<div>Hi,</div><div><br></div><div>I&#39;m trying to do the following in my CMake file:</div><div><br></div><div>1. Generate a &quot;xyz.txt&quot; file </div><div>2. Compile a &quot;generate.c&quot; file to give out a  &quot;generate&quot; binary in my bin directory.</div>

<div>3. Execute the &quot;generate&quot; binary (The binary just reads contents of &quot;xyz.txt&quot; and creates a copy of &quot;xyz.txt&quot;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>&quot;bin/generate: Command not found&quot;</b></div><div><br></div><div>However, if I <b>re-run the build immediately</b> after, since the &quot;generate&quot; binary is already created, all 3 successfully execute. Here&#39;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 &quot;generate&quot; 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>