Thanks. It works.<br><br><div class="gmail_quote">2009/6/1 Alexander Neundorf <span dir="ltr"><<a href="mailto:a.neundorf-work@gmx.net">a.neundorf-work@gmx.net</a>></span><br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<div class="im">On Monday 01 June 2009, Dong Tiger wrote:<br>
> 2009/5/29 Alexander Neundorf <<a href="mailto:a.neundorf-work@gmx.net">a.neundorf-work@gmx.net</a>><br>
><br>
> > On Thursday 28 May 2009, <a href="mailto:idlecat511@gmail.com">idlecat511@gmail.com</a> wrote:<br>
> > > Hi,<br>
> > ><br>
> > > This situation is:<br>
> > ><br>
> > > foo.h is generated from foo.x. And foo.h is included by bar.h. And then<br>
> > > bar.h is included by a lot of c files. So actually every c files<br>
> ><br>
> > including<br>
> ><br>
> > > bar.h depends on foo.h.<br>
> > > But the file number is so big that I don't want to add dependency for<br>
> ><br>
> > each<br>
> ><br>
> > > one.<br>
> > ><br>
> > > How can I specify foo.x is generated before all the c files being<br>
> ><br>
> > compiled?<br>
> ><br>
> > > It seems add_custom_target works but it will regenerate foo.h every<br>
> > > time even the foo.x is not modified.<br>
> ><br>
> > You should use<br>
> > add_custom_command(OUTPUT <fullpath>/foo.h<br>
> > ... )<br>
> ><br>
> > and then list that generated file as a source file for your target:<br>
> ><br>
> > add_library(blub <fullpath>/foo.h foo.c bar.c ...)<br>
><br>
> I know by this way, if foo.h is changed, blub will be rebuilt. But what I<br>
> need is foo.h is guaranteed to be up to date before foo.o is built. I am<br>
> not sure if this command is relevant to this. Will cmake try to make sure<br>
> all the src files are up to date before compiling any .c files?<br>
<br>
</div>Yes.<br>
<div class="im"><br>
> > This should make sure that everything is up to date.<br>
> ><br>
> > The header-file dependency scanning does in general not work for<br>
> > generated files, you need to list the generated file as source file for<br>
> > the targets which need it.<br>
><br>
> Another problem is that I am trying to avoid adding dependencies for these<br>
> generated files manually because in my project, there are many generated<br>
> head files and quite a few .c files including them. I just want to make<br>
> sure the head files are generated before any .c compilation.<br>
> ADD_CUSTOM_TARGET can do this but it will regenerate the head files even<br>
> they are up-to-date.<br>
<br>
</div>There should be no need to do this if you use add_custom_command()<br>
<br>
Alex<br>
</blockquote></div><br>