[CMake] ADD_CUSTOM_COMMAND and Dependencies

Micha Renner Micha.Renner at t-online.de
Mon Aug 1 03:32:39 EDT 2011


Am Montag, den 25.07.2011, 15:49 +0200 schrieb Michael Wild:
> On 07/25/2011 03:24 PM, Micha Renner wrote:
> > There is following sequence:
> > 
> > ADD_EXECUTEABLE(generator gen.c)
> > 
> > ADD_CUSTOM_COMMAND(OUTPUT tlib.h
> > 	COMMAND generator > tlib.h)
> > 
> > ADD_LIBRARY(tlib tlib.c tlib.h)
> > 
> > The question: Is it sure that ADD_EXECUTEABLE is invoked before the
> > library is build or is here an ADD_DEPENDENCIES(tlib generator)
> > necessary?
> > 
> > Greetings
> > 
> > Micha
> > 
> 
> Yes, CMake should recognize that "generator" is a target and create the
> dependency of tlib.h on "generator" automagically. And since it knows
> that tlib.h is GENERATED, it will also add a dependency of tlib on
> tlib.h. If you want to make really sure that CMake understands that
> "generator" is a target, use generator expressions, like
> "$<TARGET_FILE:generator>", but that works only since 2.8.4.

So really clear is this not.
After studying the documentation, to get more information for
target_file, I found this line in the add_custom_command documentation:
"Additionally, if the target is an executable or library a file-level
dependency is created to cause the custom command to re-run whenever the
target is recompiled."

ADD_CUSTOM_COMMAND(OUTPUT tlib.h COMMAND generator > tlib.h DEPENDS
generator) should solve my problem.

But what is the difference to 
ADD_CUSTOM_COMMAND(OUTPUT tlib.h COMMAND $<TARGET_FILE:generator>
generator > tlib.h)?

Greetings

Micha






More information about the CMake mailing list