CMake should support custom commands that can vary by configuration.
This issue was created automatically from an original Mantis Issue. Further discussion may take place here.
The current CMake 2.8.0 system does not allow custom commands created with add_custom_command() to do different things based on the build configuration.
I propose adding a new keyword to the add_custom_command CMake directive called CONFIG:
add_custom_command(OUTPUT output1 [output2 ...]
COMMAND command1 [ARGS] [args1...]
[COMMAND command2 [ARGS] [args2...] ...]
[MAIN_DEPENDENCY depend]
[DEPENDS [depends...]]
[IMPLICIT_DEPENDS <lang1> depend1 ...]
[WORKING_DIRECTORY dir]
[COMMENT comment] [VERBATIM] [APPEND]
[CONFIG Debug | MinSizeRel | Release | RelWithDebInfo | ...])
add_custom_command(TARGET target
PRE_BUILD | PRE_LINK | POST_BUILD
COMMAND command1 [ARGS] [args1...]
[COMMAND command2 [ARGS] [args2...] ...]
[WORKING_DIRECTORY dir]
[COMMENT comment] [VERBATIM]
[CONFIG Debug | MinSizeRel | Release | RelWithDebInfo | ...])
The CONFIG option specifies that the custom command(s) should run only when the given build configuration is active. This option allows custom commands to have configuration specific behavior.
When the CONFIG option is not present, add_custom_command command behaves as before.
I have uploaded patches that implement this feature. These patches were created on 11-27-09 against the current CMake CVS head branch sources.
A similar addition could be made for add_custom_target although I have not taken the time to add an implementation.