[CMake] Help with custom targets

Bill Hoffman bill.hoffman at kitware.com
Sat Mar 3 11:41:42 EST 2007


Alan W. Irwin wrote:
> On 2007-03-03 16:10+0100 Ulrik Mikaelsson wrote:
>
>> My problem right now is that I would like to define my edje-resources
>> as special targets, and have them depend on their respective
>> source-files, but I haven't managed to make them behave as I want.
>>
>> I've come pretty close using the ADD_CUSTOM_COMMAND() in OUTPUT mode,
>> but for some reason I have not been able to make the dependencies work
>> such that when I update the source-files, and run make, the compiled
>> resources are updated.
>
> My experience is custom command dependencies generally work if you 
> specify
> full pathnames and you always have a custom target file-depending on the
> OUTPUT of a custom command.
>
> Here is one CMake fragment illustrating a working example:
>
> add_executable(plhershey-unicode-gen ${plhershey-unicode-gen_SRCS})
>
> add_custom_command(
> OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/plhershey-unicode.h
> COMMAND ${CMAKE_CURRENT_BINARY_DIR}/plhershey-unicode-gen${EXEEXT}
> ${CMAKE_SOURCE_DIR}/fonts/plhershey-unicode.csv
> plhershey-unicode.h
> DEPENDS
> ${CMAKE_CURRENT_BINARY_DIR}/plhershey-unicode-gen${EXEEXT}
> ${CMAKE_SOURCE_DIR}/fonts/plhershey-unicode.csv
> )
>
> add_custom_target(
> plhershey-unicode.h_built
> DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/plhershey-unicode.h
>
> This dependency chain was complicated by the fact that my custom command
> file-depended on the results of add_executable, and my custom target was
> target-depended by an add_library in another directory.  But this 
> dependency
> chain works as expected with plhershey-unicode.h being generated only 
> when
> needed (which is important because an earlier incorrect version of this
> generated the header every time which lead to an expensive library 
> rebuild
> every time).
>
> If this pattern of working dependencies does not give you any helpful 
> ideas,
> could you give a simple example of the dependency problem you are
> encountering?
>

Basically, you have to make sure that the output of the custom command 
is in the input of some target that will get built.   It does not have 
to be a custom_target.  If you create a .h file, just make sure you add 
the .h file to the sources of an executable or library.   There are 
several entries about this in the wiki.

-Bill



More information about the CMake mailing list