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