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