I have a subdirectory foo/ which I want to build
CMakeLists.txt:
add_subdirectory(foo)
Inside foo/ I have a number of targets I want to build, and I want to "group" them under a single phony target, also called foo.
foo/CMakeLists.txt:
add_custom_target(foo ALL)
add_library (foo_lib ...)
add_executable(foo_bin ...)
add_executable(foo_tests ...)
add_dependencies(foo foo_lib)
add_dependencies(foo foo_bin)
add_dependencies(foo foo_test)
This will allow me to build all these related targets by typing make foo
This works fine, except when I am in the directory above foo/
make foo in the directory in which foo subdirectory exists does nothing.
I believe this is because make considers foo a target that is not out of date, since the directory exists. The fix is to mark it as a PHONY target.
According to the CMake documentation on add_custom_target, the target will always be considered out-of-date (ie: in make parlance, it will be a PHONY target).
Question:
Why is my foo custom target not being built inside the directory containing the foo subdirectory?