Ninja doesn't rebuild if dependency changed for custom_target
Hi,
consider the following cmake file
project(Test LANGUAGES CXX)
cmake_minimum_required(VERSION 3.20)
# Add a custom command
add_custom_command(OUTPUT dummy_output.txt
COMMAND ${CMAKE_COMMAND} -E touch "dummy_output.txt"
COMMENT "Creating dummy_output.txt")
# Add a custom target
add_custom_target(CustomTarget ALL
DEPENDS dummy_output.txt
COMMENT "Call CustomTarget"
)
and using Ninja generator.
- Call ninja to build the project => File
dummy_output.txt
is correctly created - Touch
dummy_output.txt
- Call ninja, nothing happens
Isn't CustomTarget
supposed to be rebuilt due to a dependency to dummy_output.txt
which is a relative file. Except if the relative path is based on CMAKE_CURRENT_SOURCE_DIR
and not CMAKE_CURRENT_BINARY_DIR
(which I would find weird).
Note: I tried to force an absolute path using CMAKE_CURRENT_BINARY_DIR
and the result is identical.
Can you confirm this is a bug when using Ninja, or is my sample incorrect (in which case the documentation might be a little misleading)? Thanks
Edited by Christophe