Hi,
When in a subdirectory’s CMakeLists.txt
, I have:
add_custom_command(
OUTPUT ${TEST_OUTPUT}
COMMAND ${CMAKE_COMMAND} -E copy ${TEST_INPUT} ${TEST_OUTPUT}
DEPENDS ${TEST_INPUT}
)
add_custom_target(gen_test_file DEPENDS ${TEST_OUTPUT})
And in parent CMakeLists.txt
:
add_custom_command(
OUTPUT test_file2.txt
COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_PROPERTY:gen_test_file,GENERATED_FILE> test_file2.txt
DEPENDS gen_test_file
)
add_custom_target(gen_test_file2 ALL DEPENDS test_file2.txt)
The gen_test_file dependency is not honored by make and NMake when ${TEST_OUTPUT}
is changed.
If I touch the ${TEST_INPUT}
file, gen_test_file
is rebuilt but not test_file2.txt
:
[ 50%] Generating test_file.txt
[ 50%] Built target gen_test_file
[100%] Built target gen_test_file2
I’m expecting that output instead:
[ 50%] Generating test_file.txt
[ 50%] Built target gen_test_file
[100%] Generating test_file2.txt
[100%] Built target gen_test_file2
I’m attaching add_custom_target_dependencies.zip which contains an example.
I’m executing these commands in the unzip directory containing the parent CMakeLists.txt:
mkdir build
cd build
cmake ..
# For the first build, all files are generated, that's OK everything works as expeced
cmake --build .
# Here I will touch the ${TEST_INPUT} file
cmake --build . --target touch_test_input
# Here, only test_file.txt is regenerated, I expect that test_file2.txt to be regenerated too
cmake --build .
How to add a dependency between 2 custom commands in separate CMakeLists.txt so when first is rebuilt, the second is also rebuilt ?
I’m tempted to put ${TEST_OUTPUT}
as a dependency of test_file2.txt
command, but as said in the documentation for add_custom_command :
If any dependency is an OUTPUT of another custom command in the same directory (
CMakeLists.txt
file), CMake automatically brings the other custom command
As I have different CMakeLists.txt here, I shouldn’t do that.