My understanding is that custom targets which depend on another executable or library target should always be built after the dependent target is built.
Example:
project(foo)
add_executable(foo foo.cpp)
add_custom_target(print COMMAND echo "Some printed text." COMMENT "Running the print custom target.")
add_dependencies(print foo)
However, using the CMakeListst.txt
included does not result in the print
target being built.
If I add the ALL
keyword to add_custom_target
, it builds. However, I wouldn’t have expected the ALL
keyword to be required here.
I am using CMake version 3.22. I’ve tried the same CMakeLists.txt
on Windows 10 and Debian 10.
Here are the cmake
commands I am using to build:
$ cmake -S . -B build
-- The C compiler identification is GNU 8.3.0
-- The CXX compiler identification is GNU 8.3.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /usr/bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring done
-- Generating done
-- Build files have been written to: [path]/build
$ cmake --build build
[ 50%] Building CXX object CMakeFiles/foo.dir/foo.cpp.o
[100%] Linking CXX executable foo
[100%] Built target foo
Given the COMMENT
on the print
custom target, I would have expected the message "Running the print custom target."
to be printed to the standard output stream here, as well as the message "Some printed text."
.