[CMake] add_custom_target always runs?

Alexander Neundorf a.neundorf-work at gmx.net
Tue Dec 16 16:09:41 EST 2008


On Tuesday 16 December 2008, Tyler Roscoe wrote:
> 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.

It should work.
Did you try to use full pathes, i.e. use CMAKE_CURRENT_SOURCE_DIR and 
CMAKE_CURRENT_BINARY_DIR respectively ?

Alex


More information about the CMake mailing list