Le Tue, 16 Dec 2008 12:26:26 -0800,
Tyler Roscoe <ty...@cryptio.net> a écrit :

> 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?

Why do you add "ALL" in your case?
Won't generateheader be called when needed when you remove the ALL
argument to add_custom_target?

Note that another way to go is completely remove the add_custom_target
and add the generated header to the concerned add_executable /
add_library command.

then you have to:

set_source_files_properties(results/header.h PROPERTIES GENERATED true)
 in order to avoid to make add_library/add_executable shout at you
about missing files.

Then when the concerned libraries and/or executable are built
CMake should automatically run your add_custom_command since it
advertise it has the missing "results/header.h" as output.




-- 
Erk
_______________________________________________
CMake mailing list
CMake@cmake.org
http://www.cmake.org/mailman/listinfo/cmake

Reply via email to