<div>Hi,</div><div><br></div><div>I'm trying to do the following in my CMake file:</div><div><br></div><div>1. Generate a "xyz.txt" file </div><div>2. Compile a "generate.c" file to give out a "generate" binary in my bin directory.</div>
<div>3. Execute the "generate" binary (The binary just reads contents of "xyz.txt" and creates a copy of "xyz.txt"using read() and write() functions in C)</div><div><br></div><div>The problem:</div>
<div>When I do a fresh build, 1 and 2 succeed. 3 fails with the following error</div><div><b>"bin/generate: Command not found"</b></div><div><br></div><div>However, if I <b>re-run the build immediately</b> after, since the "generate" binary is already created, all 3 successfully execute. Here's a snippet of what I have written.</div>
<div><br></div><div>------------</div><div>------------</div><div>/*---- Code to generate xyz.txt -- Successfully generated each time------*/</div><div>----------</div><div>---------</div><div><span class="Apple-style-span" style="font-family: Arial; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; ">ADD_EXECUTABLE(generate ${CMAKE_CURRENT_SOURCE_DIR}/server/generate.c)</span></div>
<div><span class="Apple-style-span" style="-webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px;"><br></span></div><div><span class="Apple-style-span" style="font-family: Arial; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; "></span><span class="Apple-style-span" style="font-family: Arial; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; ">set(GEN ${CMAKE_BINARY_DIR}/bin/generate)</span></div>
<span class="Apple-style-span" style="font-family: Arial; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; "><div><br></div>ADD_CUSTOM_COMMAND(<br> TARGET generate POST_BUILD<br> COMMAND ${GEN}<br>
DEPENDS ${CMAKE_BINARY_DIR}/server/xyz.txt}<br> )</span><div><span class="Apple-style-span" style="-webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px;"><br></span></div><div><span class="Apple-style-span" style="-webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px;">In my ADD_CUSTOM_COMMAND, I have specified POST_BUILD, which I understood to be that the command will be executed only after creation of the "generate" binary. </span></div>
<div><span class="Apple-style-span" style="-webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px;"><br></span></div><div><span class="Apple-style-span" style="-webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px;">Any help is greatly appreciated. Thank you in advance for your time.</span></div>
<div><span class="Apple-style-span" style="-webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px;"><br></span></div><div><span class="Apple-style-span" style="-webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px;">Regards,</span></div>
<div><span class="Apple-style-span" style="-webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px;">Swaroop</span></div>