Skip to content

Instantly share code, notes, and snippets.

@mikedld
Created October 5, 2021 20:46
Show Gist options
  • Save mikedld/a687baabc952a7f061b6a2fd3069f91c to your computer and use it in GitHub Desktop.
Save mikedld/a687baabc952a7f061b6a2fd3069f91c to your computer and use it in GitHub Desktop.
Find all CMake targets declared in a directory (recursively)
function(print_all_targets DIR)
get_property(TGTS DIRECTORY "${DIR}" PROPERTY BUILDSYSTEM_TARGETS)
foreach(TGT IN LISTS TGTS)
message(STATUS "Target: ${TGT}")
# TODO: Do something about it
endforeach()
get_property(SUBDIRS DIRECTORY "${DIR}" PROPERTY SUBDIRECTORIES)
foreach(SUBDIR IN LISTS SUBDIRS)
print_all_targets("${SUBDIR}")
endforeach()
endfunction()
print_all_targets(.)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment