<html><body><div style="color:#000; background-color:#fff; font-family:times new roman, new york, times, serif;font-size:12pt"><div><span>Hello,</span></div><div><span>I am facing a weird scenario when using the ADD_CUSTOM_TARGET / ADD_CUSTOM_COMMAND in building an executable for my project. I have scoured the internet for a solution but to no avail. Let me illustrate my case:</span></div><div><br><span></span></div><div><span>I need to do a pre-build operation by checking the presence of an already built executable. If it does, then the process would be something like this</span></div><div><br><span></span></div><div><span>SET(MY_EXE ${PROJECT_SOURCE_DIR}/PreBuild/aExecutable.exe)</span></div><div><br><span></span></div><div><span>IF(EXISTS ${MY_EXE})</span></div><div><span>...EXECUTE_PROCESS(COMMAND MY_EXE <ARGS>) #this one works as expected</span></div><div><span>ELSE()</span></div><div><span>...#need to build the executable and then run
it as a post-build operation</span></div><div><span>ENDIF()</span></div><div><br><span></span></div><div><span>Now, I have tried both modes to build the executable and I have failed... Here is what I have done:</span></div><div><br><span></span></div><div><span>###using ADD_CUSTOM_COMMAND<br></span></div><div><span> ADD_EXECUTABLE(</span><span>aExecutable ${MY_SRCS})</span></div><div><span> TARGET_LINK_LIBRARIES(aExecutable ${MY_LIBS})</span></div><div><span> GET_TARGET_PROPERTY(EXE_NAME </span><span>aExecutable</span><span> LOCATION)</span></div><div> #copy the just built executable to the correct location - Works!!!</div><div> #run the executable as post-build operation -- Fails!!!<br></div><div><span class="tab"> </span><span>ADD_CUSTOM_COMMAND(</span></div><div><span> </span><span class="tab">
</span><span>POST_BUILD<br></span></div><div><span> </span><span class="tab"> </span><span class="tab"> </span><span class="tab"> </span><span class="tab"> </span><span>OUTPUT </span><span> ${PROJECT_SOURCE_DIR}/PreBuild</span><br><span> </span><span class="tab"> </span><span class="tab"> </span><span>COMMAND ${EXE_NAME} ${PROJECT_SOURCE_DIR}/InputFile.txt </span><span></span><span> ${PROJECT_SOURCE_DIR}/PreBuild</span></div><div><span></span><span> DEPENDS aExecutable<br> )<br></span></div><div> <br><span>###using ADD_CUSTOM_COMMAND<br>#This also Fails!!!!<br></span><span>ADD_CUSTOM_TARGET(</span>
<div><span> </span><span class="tab"> </span><span>dummy ALL<br>
</span></div>
<div><span> </span><span class="tab"> </span><span class="tab"> </span><span class="tab"> </span><span class="tab"> </span><span></span><span class="tab"></span><span>COMMAND ${EXE_NAME} ${PROJECT_SOURCE_DIR}/InputFile.txt </span><span></span><span> ${PROJECT_SOURCE_DIR}/PreBuild</span></div>
<div><span></span><span> )</span></div><br><span>###using ADD_CUSTOM_COMMAND, but with dependencies<br>
#This partially works!!!!<br>
</span><span>ADD_CUSTOM_TARGET(</span>
<div><span> </span><span class="tab"> </span><span>dummy ALL<br>
</span></div>
<div><span> </span><span class="tab"> </span><span class="tab"> </span><span class="tab"> </span><span class="tab"> </span><span></span><span class="tab"></span><span>COMMAND ${EXE_NAME} ${PROJECT_SOURCE_DIR}/InputFile.txt </span><span></span><span> ${PROJECT_SOURCE_DIR}/PreBuild</span></div>
<div><span></span><span> )</span></div>
<br>ADD_DEPENDENCIES(dummy aExecutable)<br><br><br>So amongst all the three combinations, the last combination seems to work in that I can see the required behavior of the executable. However, in VS2010 I get an error message as "....exists with cmd.exe"; Apparently it is trying to build the dummy project "dummy". <br><br>What am I doing work here? Conceptually, I think ADD_CUSTOM_COMMAND would be the correct approach for doing this.<br><br>Thanks in advance for any help.<br></div><div>Sumit</div></div></body></html>