The message() and file(REMOVE) commands will be executed when you run CMake. The command to generate the .cpp file won&#39;t be executed until you run make. That&#39;s why it&#39;s still around after you&#39;re done.<br><br>
You can&#39;t really do exactly what you want here very easily; you&#39;d need to have a separate custom command to delete the file after the build is complete, and I&#39;m not sure how to set up the dependencies to automate that for you.<br>
<br>Why do you want this? Wouldn&#39;t it make more sense to generate the source file into the binary directory and just leave it there? Your add_custom_command() and list(APPEND SRCS) steps below will do this if you just change the OUTPUT to &quot;${CMAKE_CURRENT_BINARY_DIR}/SourceFileInfo.cpp&quot;. This would have the added benefit of not forcing a rebuild of SourceFileInfo.o every time you run &quot;make&quot;.<br>
<br>Ceej<br>aka Chris Hillery<br><br><div class="gmail_quote">On Fri, Sep 17, 2010 at 2:53 AM, David Aldrich <span dir="ltr">&lt;<a href="mailto:David.Aldrich@eu.nec.com">David.Aldrich@eu.nec.com</a>&gt;</span> wrote:<br>
<blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">






<div>
<font face="Arial, sans-serif" size="2">
<div>Hi</div>
<div> </div>
<div>I want to generate a source file ‘SourceFileInfo.cpp’, then build a library and then delete the generated file. </div>
<div><font face="Times New Roman, serif" size="2"> </font></div>
<div>So I wrote:</div>
<div><font face="Times New Roman, serif" size="2"> </font></div>
<div>&lt;snip&gt;</div>
<div><font face="Times New Roman, serif" size="2"> </font></div>
<div>add_custom_command (</div>
<div>  OUTPUT SourceFileInfo.cpp</div>
<div>  COMMAND ../VersionInfo/_gnuRelease/versionInfo . KERNEL</div>
<div>  DEPENDS ${SRCS}</div>
<div>  COMMENT &quot;Generating SourceFileInfo.cpp&quot;</div>
<div>  VERBATIM)</div>
<div> </div>
<div>list(APPEND SRCS SourceFileInfo.cpp)</div>
<div> </div>
<div>add_library( Kernel STATIC ${SRCS} )</div>
<div> </div>
<div>message(&quot;Removing file&quot;)</div>
<div>file( REMOVE SourceFileInfo.cpp )</div>
<div><font face="Times New Roman, serif" size="2"> </font></div>
<div>But the message ‘Removing file’ appears as the first action when executing make and the file remains after make has finished.  </div>
<div><font face="Times New Roman, serif" size="2"> </font></div>
<div>I guess that one can’t interpret a CMakeLists.txt file sequentially, just like you can’t interpret a makefile sequentially.</div>
<div> </div>
<div>What am I doing wrong?</div>
<div> </div>
<div>Where can I find an explanation of CMake command ordering?</div>
<div style="margin-top: 5pt; margin-bottom: 5pt;">Best regards </div>
<div style="margin-top: 5pt; margin-bottom: 5pt;">David </div>
<div style="margin-top: 5pt; margin-bottom: 5pt;"><font face="Times New Roman, serif" size="2"> </font></div>
</font>
</div>

<br>_______________________________________________<br>
Powered by <a href="http://www.kitware.com" target="_blank">www.kitware.com</a><br>
<br>
Visit other Kitware open-source projects at <a href="http://www.kitware.com/opensource/opensource.html" target="_blank">http://www.kitware.com/opensource/opensource.html</a><br>
<br>
Please keep messages on-topic and check the CMake FAQ at: <a href="http://www.cmake.org/Wiki/CMake_FAQ" target="_blank">http://www.cmake.org/Wiki/CMake_FAQ</a><br>
<br>
Follow this link to subscribe/unsubscribe:<br>
<a href="http://www.cmake.org/mailman/listinfo/cmake" target="_blank">http://www.cmake.org/mailman/listinfo/cmake</a><br></blockquote></div><br>