<font size=2 face="sans-serif">Interesting. I had a little typo in the
first example, here's another one. You only need a file called "generated.txt.in"
next to the CMakeLists.txt file.</font>
<br>
<br>
<br><font size=2>CMAKE_MINIMUM_REQUIRED(VERSION 2.8)</font>
<br>
<br><font size=2>PROJECT(quick_test)</font>
<br>
<br><font size=2>ADD_CUSTOM_COMMAND(</font>
<br><font size=2> OUTPUT "${PROJECT_BINARY_DIR}/generated.txt"</font>
<br><font size=2> COMMAND ${CMAKE_COMMAND} -E copy </font>
<br><font size=2> "${PROJECT_SOURCE_DIR}/generated.txt.in"
</font>
<br><font size=2> "${PROJECT_BINARY_DIR}/generated.txt"</font>
<br><font size=2> DEPENDS "${PROJECT_SOURCE_DIR}/generated.txt.in")</font>
<br><font size=2> </font>
<br><font size=2> ADD_CUSTOM_COMMAND(</font>
<br><font size=2> OUTPUT "${PROJECT_BINARY_DIR}/generated_used.stamp"</font>
<br><font size=2> COMMAND ${CMAKE_COMMAND} -E touch "${PROJECT_BINARY_DIR}/generated_used.stamp"</font>
<br><font size=2> DEPENDS "${PROJECT_BINARY_DIR}/generated.txt"</font>
<br><font size=2> COMMENT "Using generated.txt")</font>
<br><font size=2> </font>
<br><font size=2> ADD_CUSTOM_TARGET(</font>
<br><font size=2> ${PROJECT_NAME}</font>
<br><font size=2> DEPENDS "${PROJECT_BINARY_DIR}/generated_used.stamp")</font>
<br>
<br>
<br><font size=2 face="sans-serif">This builds ok the first time, but then
change the "generated.txt.in" and run the build twice and the
second time you'll see "Using generated.txt" again, which I don't
want to see. I've tried VS 2008 and NMake, using CMake 2.8 and 2.8.1.</font>
<br><font size=2 face="sans-serif">-------------------------------------------------------------<br>
Aaron Wright</font>
<br>
<br>
<br>
<br>
<table width=100%>
<tr valign=top>
<td><font size=1 color=#5f5f5f face="sans-serif">From:</font>
<td><font size=1 face="sans-serif">Michael Wild <themiwi@gmail.com></font>
<tr valign=top>
<td><font size=1 color=#5f5f5f face="sans-serif">To:</font>
<td><font size=1 face="sans-serif">Aaron_Wright@selinc.com</font>
<tr>
<td valign=top><font size=1 color=#5f5f5f face="sans-serif">Cc:</font>
<td><font size=1 face="sans-serif">cmake@cmake.org</font>
<tr valign=top>
<td><font size=1 color=#5f5f5f face="sans-serif">Date:</font>
<td><font size=1 face="sans-serif">04/21/2010 11:41 PM</font>
<tr valign=top>
<td><font size=1 color=#5f5f5f face="sans-serif">Subject:</font>
<td><font size=1 face="sans-serif">Re: [CMake] Why is this custom command
run twice?</font>
<tr valign=top>
<td><font size=1 color=#5f5f5f face="sans-serif">Sent by:</font>
<td><font size=1 face="sans-serif">cmake-bounces@cmake.org</font></table>
<br>
<hr noshade>
<br>
<br>
<br><tt><font size=2><br>
On 22. Apr, 2010, at 5:12 , Aaron_Wright@selinc.com wrote:<br>
<br>
> I'm trying to do something a little weird, and I'm almost there but
not <br>
> quite. I'm trying to generate a file and then run a command based
on that <br>
> file. I only want the command to run when the file changes and thus
the <br>
> generated file changes. Instead the first build I get both custom
commands <br>
> run, and then on a second build, the second custom command runs again,
<br>
> which is not what I want. <br>
> <br>
> This is what I got (just an example):<br>
> <br>
> <br>
> ADD_CUSTOM_COMMAND(<br>
> OUTPUT "${PROJECT_BINARY_DIR}/generated.txt"<br>
> COMMAND ${CMAKE_COMMAND} -E touch "${PROJECT_BINARY_DIR}/generated.txt"<br>
> DEPENDS "${PROJECT_SOURCE_DIR}/generated.txt")<br>
> <br>
> ADD_CUSTOM_COMMAND(<br>
> OUTPUT "${PROJECT_BINARY_DIR}/generated_used.stamp"<br>
> COMMAND ${CMAKE_COMMAND} -E touch <br>
> "${PROJECT_BINARY_DIR}/generated_used.stamp"<br>
> DEPENDS "${PROJECT_BINARY_DIR}/generated.txt"<br>
> COMMENT "Using generated.txt")<br>
> <br>
> ADD_CUSTOM_TARGET(<br>
> ${PROJECT_NAME}<br>
> DEPENDS "${PROJECT_BINARY_DIR}/generated_used.stamp")<br>
> <br>
> <br>
> What I'm I missing? Thanks<br>
<br>
Your example works fine for me (using CMake 2.8.1 and Unix Makefiles generator
on Mac OS X 10.6.2).<br>
<br>
Michael<br>
<br>
_______________________________________________<br>
Powered by </font></tt><a href=www.kitware.com><tt><font size=2>www.kitware.com</font></tt></a><tt><font size=2><br>
<br>
Visit other Kitware open-source projects at </font></tt><a href=http://www.kitware.com/opensource/opensource.html><tt><font size=2>http://www.kitware.com/opensource/opensource.html</font></tt></a><tt><font size=2><br>
<br>
Please keep messages on-topic and check the CMake FAQ at: </font></tt><a href=http://www.cmake.org/Wiki/CMake_FAQ><tt><font size=2>http://www.cmake.org/Wiki/CMake_FAQ</font></tt></a><tt><font size=2><br>
<br>
Follow this link to subscribe/unsubscribe:<br>
</font></tt><a href=http://www.cmake.org/mailman/listinfo/cmake><tt><font size=2>http://www.cmake.org/mailman/listinfo/cmake</font></tt></a><tt><font size=2><br>
</font></tt>
<br>