Hello,
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:

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

SET(MY_EXE ${PROJECT_SOURCE_DIR}/PreBuild/aExecutable.exe)

IF(EXISTS ${MY_EXE})
...EXECUTE_PROCESS(COMMAND MY_EXE <ARGS>)  #this one works as expected
ELSE()
...#need to build the executable and then run it as a post-build operation
ENDIF()

Now, I have tried both modes to build the executable and I have failed... Here 
is what I have done:

###using ADD_CUSTOM_COMMAND

  ADD_EXECUTABLE(aExecutable ${MY_SRCS})
  TARGET_LINK_LIBRARIES(aExecutable ${MY_LIBS})
  GET_TARGET_PROPERTY(EXE_NAME aExecutableLOCATION)
  #copy the just built executable to the correct location - Works!!!
  #run the executable as  post-build operation -- Fails!!!

  ADD_CUSTOM_COMMAND(
            POST_BUILD

           OUTPUT ${PROJECT_SOURCE_DIR}/PreBuild
            COMMAND ${EXE_NAME} ${PROJECT_SOURCE_DIR}/InputFile.txt 
${PROJECT_SOURCE_DIR}/PreBuild
            DEPENDS aExecutable
 )

 
###using ADD_CUSTOM_COMMAND
#This also Fails!!!!
ADD_CUSTOM_TARGET( 
            dummy ALL

            COMMAND ${EXE_NAME} ${PROJECT_SOURCE_DIR}/InputFile.txt 
${PROJECT_SOURCE_DIR}/PreBuild
)
###using ADD_CUSTOM_COMMAND, but with dependencies
#This partially works!!!!
ADD_CUSTOM_TARGET( 
            dummy ALL

            COMMAND ${EXE_NAME} ${PROJECT_SOURCE_DIR}/InputFile.txt 
${PROJECT_SOURCE_DIR}/PreBuild
)
ADD_DEPENDENCIES(dummy aExecutable)


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". 

What am I doing work here? Conceptually, I think ADD_CUSTOM_COMMAND would be 
the correct approach for doing this.

Thanks in advance for any help.

Sumit
--

Powered by www.kitware.com

Visit other Kitware open-source projects at 
http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the CMake FAQ at: 
http://www.cmake.org/Wiki/CMake_FAQ

Follow this link to subscribe/unsubscribe:
http://www.cmake.org/mailman/listinfo/cmake

Reply via email to