[CMake] How to guarntee the sequence of build if no target can be used
Alexander Neundorf
a.neundorf-work at gmx.net
Fri May 29 16:02:43 EDT 2009
On Thursday 28 May 2009, idlecat511 at gmail.com wrote:
> Hi,
>
> This situation is:
>
> foo.h is generated from foo.x. And foo.h is included by bar.h. And then
> bar.h is included by a lot of c files. So actually every c files including
> bar.h depends on foo.h.
> But the file number is so big that I don't want to add dependency for each
> one.
>
> How can I specify foo.x is generated before all the c files being compiled?
> It seems add_custom_target works but it will regenerate foo.h every time
> even the foo.x is not modified.
You should use
add_custom_command(OUTPUT <fullpath>/foo.h
... )
and then list that generated file as a source file for your target:
add_library(blub <fullpath>/foo.h foo.c bar.c ...)
This should make sure that everything is up to date.
The header-file dependency scanning does in general not work for generated
files, you need to list the generated file as source file for the targets
which need it.
Alex
More information about the CMake
mailing list