[CMake] add_custom_target always runs?
Tyler Roscoe
tyler at cryptio.net
Tue Dec 16 15:26:26 EST 2008
I am using what I think is a common pattern to create some headers.
Following the example at
http://www.cmake.org/Wiki/CMake_FAQ#How_do_I_generate_an_executable.2C_then_use_the_executable_to_generate_a_file.3F,
I have an add_custom_command which calls a script (generateheader.py):
add_custom_command (
DEPENDS generateheader.py
OUTPUT results/header.h
COMMAND ${PYTHON_EXECUTABLE}
ARGS generateheader.py --infile=src/header.in.h --outfile=results/header.h
)
And then I have an add_custom_target to wrap the command in a target:
add_custom_target (
generateheader ALL
DEPENDS results/header.h
)
This seems to mostly do what it's supposed to do. When I run "make all",
the generateheader target runs and results/header.h is created. When I
run "make generateheader", same thing.
So now the problem.
When I do "make all", the generateheader target *always* runs, even if
results/header.h and generateheader.py are up-to-date.
This is a problem because other targets depend on generateheader, so
when generateheader runs, all the dependent targets also run. This makes
it impossible for me to do a delta build.
Some closer reading of the manual suggests that this is by design. From
http://www.cmake.org/cmake/help/cmake2.6docs.html#command:add_custom_target:
"Adds a target with the given name that executes the given commands. The
target has no output file and is ALWAYS CONSIDERED OUT OF DATE even if
the commands try to create a file with the name of the target."
Ok, so is it simply impossible to do delta builds if my build process
needs add_custom_command/add_custom_target invocations? Is there some
better way to have CMake create the headers for me? Does this behavior
of add_custom_target only occur when I add a new target dependent on
ALL?
Thanks,
tyler
More information about the CMake
mailing list