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