I did. The same problem persists. Is there a work-around - maybe some other command that I can use?<br><br><div class="gmail_quote">2009/8/27 Michael Wild <span dir="ltr">&lt;<a href="mailto:themiwi@gmail.com">themiwi@gmail.com</a>&gt;</span><br>

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">David is probably right, that you need to add the dependency on &quot;generate&quot;. However, only add it&#39;s target name to both the COMMAND and DEPENDS arguments, CMake should figure this out.<br>


<br>
Michael<div><div></div><div class="h5"><br>
<br>
On 27. Aug, 2009, at 21:31, Swaroop Ramachandra wrote:<br>
<br>
</div></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div></div><div class="h5">
Still no luck :( . I really wonder why it is trying to execute my &quot;generate&quot;<br>
binary even before it is built. Here are my updated lines of code.<br>
#Trying to compile and run generate.c. generate.c creates a new file<br>
someoutput.txt and copies all data from someinput.txt to someoutput.txt<br>
add_executable(generate server/generate.c)<br>
add_custom_command(<br>
# I want to generate someoutput.txt<br>
OUTPUT ${CMAKE_BINARY_DIR}/server/someoutput.txt<br>
# using the generate program. cmake knows that &quot;generate&quot; refers to the<br>
above target<br>
COMMAND generate ${CMAKE_CURRENT_SOURCE_DIR}/server/someinput.txt<br>
# only run if sominput.txt changed<br>
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/server/someinput.txt<br>
${CMAKE_BINARY_DIR}/bin/generate${CMAKE_EXECUTABLE_SUFFIX}<br>
# tell to run in current binary dir<br>
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/bin<br>
# some nice comment in the output<br>
COMMENT &quot;Generating ${CMAKE_BINARY_DIR}/someoutput.txt&quot;<br>
VERBATIM<br>
)<br>
<br>
<br>
2009/8/27 David Cole &lt;<a href="mailto:david.cole@kitware.com" target="_blank">david.cole@kitware.com</a>&gt;<br>
<br>
</div></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div></div><div class="h5">
Use full path file names as DEPENDS arguments.<br>
Also: depend on the executable file too so that cmake knows not to try to<br>
run the custom command before the executable is built...<br>
<br>
i.e. :<br>
<br>
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/server/someinput.txt ${CMAKE_BINARY_DIR}/bin/generate${CMAKE_EXECUTABLE_SUFFIX}<br>
<br>
<br>
HTH,<br>
David<br>
<br>
<br>
On Thu, Aug 27, 2009 at 2:41 PM, Swaroop Ramachandra &lt;<a href="mailto:swaroopgr@gmail.com" target="_blank">swaroopgr@gmail.com</a><br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
wrote:<br>
</blockquote>
<br>
</div></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div></div><div class="h5">
Hi Michael,<br>
<br>
Thanks for your reply.  I still have the same problem.<br>
*<br>
*<br>
gmake-3.81[2]: bin/generate: Command not found<br>
lin: gmake-3.81[2]: *** [bin/generate] Error 127<br>
lin: gmake-3.81[1]: *** [CMakeFiles/generate.dir/all] Error 2<br>
<br>
<br>
<br>
Here&#39;s my code as is:<br>
#Trying to compile and run generate.c. generate.c creates a new file<br>
someoutput.txt and copies all data from someinput.txt to someoutput.txt<br>
add_executable(generate server/generate.c)<br>
add_custom_command(<br>
# I want to generate someoutput.txt<br>
OUTPUT ${CMAKE_BINARY_DIR}/server/someoutput.txt<br>
# using the generate program. cmake knows that &quot;generate&quot; refers to the<br>
above target<br>
COMMAND generate ${CMAKE_CURRENT_SOURCE_DIR}/server/someinput.txt<br>
# only run if sominput.txt changed<br>
DEPENDS server/someinput.txt<br>
# tell to run in current binary dir<br>
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/bin<br>
# some nice comment in the output<br>
COMMENT &quot;Generating ${CMAKE_BINARY_DIR}/someoutput.txt&quot;<br>
VERBATIM<br>
)<br>
<br>
<br>
Still the same issue. I guess it is trying to execute my &quot;generate&quot; even<br>
before it is compiled. Does CMake see that in the line &quot;COMMAND&quot; generate<br>
refers to the compiled one? Again, since generate is created in round one of<br>
make, the second run sees the &quot;generate&quot; and runs fine.<br>
<br>
Any help is greatly appreciated! Thanks for your time!<br>
<br>
Regards,<br>
Swaroop<br>
<br>
2009/8/27 Michael Wild &lt;<a href="mailto:themiwi@gmail.com" target="_blank">themiwi@gmail.com</a>&gt;<br>
<br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
On 27. Aug, 2009, at 0:58, Swaroop Ramachandra wrote:<br>
<br>
Hi,<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
I&#39;m trying to do the following in my CMake file:<br>
<br>
1. Generate a &quot;xyz.txt&quot; file<br>
2. Compile a &quot;generate.c&quot; file to give out a  &quot;generate&quot; binary in my<br>
bin<br>
directory.<br>
3. Execute the &quot;generate&quot; binary (The binary just reads contents of<br>
&quot;xyz.txt&quot; and creates a copy of &quot;xyz.txt&quot;using read() and write()<br>
functions<br>
in C)<br>
<br>
The problem:<br>
When I do a fresh build, 1 and 2 succeed. 3 fails with the following<br>
error<br>
*&quot;bin/generate: Command not found&quot;*<br>
<br>
However, if I *re-run the build immediately* after, since the &quot;generate&quot;<br>
binary is already created, all 3 successfully execute. Here&#39;s a snippet<br>
of<br>
what I have written.<br>
<br>
------------<br>
------------<br>
/*---- Code to generate xyz.txt -- Successfully generated each<br>
time------*/<br>
----------<br>
---------<br>
ADD_EXECUTABLE(generate ${CMAKE_CURRENT_SOURCE_DIR}/server/generate.c)<br>
<br>
set(GEN ${CMAKE_BINARY_DIR}/bin/generate)<br>
<br>
ADD_CUSTOM_COMMAND(<br>
TARGET generate POST_BUILD<br>
COMMAND ${GEN}<br>
DEPENDS ${CMAKE_BINARY_DIR}/server/xyz.txt}<br>
)<br>
In my ADD_CUSTOM_COMMAND, I have specified POST_BUILD, which I<br>
understood to<br>
be that the command will be executed only after creation of the<br>
&quot;generate&quot;<br>
binary.<br>
<br>
</blockquote>
<br>
That&#39;s the wrong way to go about it. the TARGET form of the<br>
add_custom_command is intended to &quot;finish&quot; the actual target. What you want<br>
is something like this:<br>
<br>
# no need for absolute paths...<br>
add_executable(generate server/generate.c)<br>
<br>
add_custom_command(<br>
# tell cmake you want to generate xyz.c<br>
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/xyz.c<br>
# using the generate program. cmake knows that &quot;generate&quot; refers to the<br>
above target<br>
COMMAND generate ${CMAKE_CURRENT_SOURCE_DIR}/xyz.txt<br>
# only run if xyz.txt changed<br>
DEPENDS xyz.txt<br>
# tell to run in current binary dir<br>
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}<br>
# some nice comment in the output<br>
COMMENT &quot;Generating ${CMAKE_CURRENT_BINARY_DIR}/xyz.c&quot;<br>
VERBATIM<br>
)<br>
<br>
<br>
And then you simply use ${CMAKE_CURRENT_BINARY_DIR}/xyz.c in one of your<br>
other targets. CMake will then know that it first needs to create target<br>
&quot;generate&quot;, then run the program on xyz.txt to create<br>
${CMAKE_CURRENT_BINARY_DIR}/xyz.c, and finally use that to build the actual<br>
target.<br>
<br>
<br>
HTH<br>
<br>
Michael<br>
<br>
<br>
</blockquote>
<br>
<br>
--<br>
<br></div></div>
Samuel Goldwyn&lt;<a href="http://www.brainyquote.com/quotes/authors/s/samuel_goldwyn.html" target="_blank">http://www.brainyquote.com/quotes/authors/s/samuel_goldwyn.html</a>&gt; - &quot;I&#39;m willing to admit that I may not always be right, but I am never<div class="im">

<br>
wrong.&quot;<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<br>
<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:<br>
<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>
<br>
</div></blockquote>
<br>
<br>
</blockquote>
<br>
<br>
-- <br>
<br>
Ted Turner &lt;<a href="http://www.brainyquote.com/quotes/authors/t/ted_turner.html" target="_blank">http://www.brainyquote.com/quotes/authors/t/ted_turner.html</a>&gt;  -<div class="im"><br>
&quot;Sports is like a war without the killing.&quot;<br>
</div></blockquote>
<br>
</blockquote></div><br><br clear="all"><br>-- <br><br><a href="http://www.brainyquote.com/quotes/authors/s/samuel_goldwyn.html" target="_blank">Samuel Goldwyn</a>  - &quot;I&#39;m willing to admit that I may not always be right, but I am never wrong.&quot;