add_custom_command: unclear depfile semantics
I am working on a project that uses cmake
and add_custom_command
with depfiles.
These custom commands output their own depfiles.
In some cases the custom commands detect during runtime that they have no dependencies and create a depfile that looks like
output_file:
(filename, colon, whitespace, newline)
So far this worked as expected with cmake 3.21.3
, the custom commands were executed only the first time ninja
was invoked.
With cmake 3.27.1
those commands are now executed every time ninja
is executed.
This is the commit that caused the different behaviour: !6861 (0b65a2b2).
Minimal example:
project(Dep)
cmake_minimum_required(VERSION 3.20)
file(WRITE /tmp/create_depfile "echo \"/tmp/outfile: \n\" > /tmp/depfile.d")
add_custom_command(
OUTPUT
/tmp/outfile
COMMAND
touch /tmp/outfile
COMMAND
bash /tmp/create_depfile
DEPFILE
/tmp/depfile.d
COMMENT
"Executing custom command"
)
add_custom_target(test_target ALL
DEPENDS
/tmp/outfile
)
Using ninja
, before cmake 0b65a2b2
this example executed the custom command only once, when ninja
was executed for the first time.
Since cmake 0b65a2b2
the custom command is invoked every time ninja
is executed. Is this change in behaviour intended?
I couldn't find any documentation of how to express "no dependencies" in a depfile. Is there a way to do this?