[CMake] configuration based add_custom_command

Michael Hertling mhertling at online.de
Wed Aug 24 07:13:17 EDT 2011


On 08/24/2011 11:04 AM, Robert Bielik wrote:
> Michael Wild skrev 2011-08-23 11:29:
>> 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
> 
> Ooh... I'll try it, but I don't understand it, yet :)
> 
> Feature request: A CONFIGURATION option to add_custom_command:
> 
> ADD_CUSTOM_COMMAND(
> ...
>     CONFIGURATION Release
> ...
> )
> 
> would make life so much easier.

Suppose

ADD_CUSTOM_COMMAND(OUTPUT source.c CONFIGURATION Release COMMAND ...)
ADD_EXECUTABLE(main ... source.c)

and then:

cmake -DCMAKE_BUILD_TYPE=Debug <path/to/source>

How would you like this case to be handled by CMake? Note that with
multi-config generators, the build type aka configuration is chosen
at build time, and the user is free to define custom build types.

Regards,

Michael


More information about the CMake mailing list