In CMake Subdirectories can be added using add_subdirectory().
How can I get the list of all subdirectories that have been added in CMake?
CMake 3.7 has a SUBDIRECTORIES property on the directories. For example, to get all the subdirectories of DIRNAME:
get_directory_property(subdir_list DIRECTORY ${DIRNAME} SUBDIRECTORIES)
foreach(subdir ${subdir_list})
message(STATUS "${subdir}")
endforeach()
Using this approach there is no need to define a custom function for addig subdirectories.
Replace every call with a call to your own function, e. g. add_and_store_subdirectory() which adds the directory to a global variable.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With