[CMake] configuration based add_custom_command

Michael Wild themiwi at gmail.com
Tue Aug 23 05:29:16 EDT 2011


On Tue 23 Aug 2011 11:21:07 AM CEST, Robert Bielik wrote:
> I'm trying to setup a custom command to be executed during Release build
> only (Xcode) using CMake 2.8.4, but I cannot find
> any configuration based options to ADD_CUSTOM_COMMAND ? Workarounds ?
> 
> TIA
> /Rob

The easiest way around this I can see is to wrap the command in a 
CMake-script like this:

add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/someFile.txt
  COMMAND ${CMAKE_COMMAND}
    -DCONFIG=$<CONFIGURATION>
    -DOUTPUT=${CMAKE_CURRENT_BINARY_DIR}/someFile.txt
    -P ${CMAKE_SOURCE_DIR}/generateSomeFile.cmake
  DEPENDS ${CMAKE_SOURCE_DIR}/generateSomeFile.cmake
  WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
  COMMENT "Generating someFile.txt"
  VERBATIM)


And then, inside the generateSomeFile.cmake wrapper file you do:

if(CONFIG STREQUAL Release)
  execute_process(COMMAND ...)
endif()


HTH

Michael


More information about the CMake mailing list