[CMake] How to set a preprocessor define for all build configurations except one ?

Glenn Coombs glenn.coombs at gmail.com
Tue Jun 7 13:05:31 EDT 2011


I want to have a preprocessor symbol (GEN_OUTFILES) defined for all build
configurations except one (ReleaseNoOutfiles).  Before I added the
ReleaseNoOutfiles configuration I just had this line in my top level
CMakeLists.txt:

add_definitions(-DGEN_OUTFILES)

but now I have to have this complicated mess instead:

# Add preprocessor definition for GEN_OUTFILES to all project configurations
except ReleaseNoOutfiles
if (CMAKE_CONFIGURATION_TYPES)
        string(TOUPPER "${CMAKE_CONFIGURATION_TYPES}"
CMAKE_CONFIGURATION_TYPES_UPPER)
else()
        string(TOUPPER "${CMAKE_BUILD_TYPE}"
CMAKE_CONFIGURATION_TYPES_UPPER)
endif()

foreach(config ${CMAKE_CONFIGURATION_TYPES_UPPER})
        if (NOT (${config} MATCHES "RELEASENOOUTFILES"))
                set_property(DIRECTORY APPEND PROPERTY
COMPILE_DEFINITIONS_${config} GEN_OUTFILES)
        endif()
endforeach()

Is there a more elegant solution that I am missing ?  Ideally something
like:

add_definitions(CONFIG=Debug;Release;RelWithDebInfo;MinSizeRel
-DGEN_OUTFILES)

which I know doesn't exist but I really wish it did :-)

Initially I didn't have the if (CMAKE_CONFIGURATION_TYPES) check and it
didn't work on linux.  Why is CMAKE_CONFIGURATION_TYPES empty for linux
targets ?  I know that multiple build configs are not supported in the same
tree like they are under Visual Studio but you can configure multiple build
directories with CMAKE_BUILD_TYPE set to each value in
CMAKE_CONFIGURATION_TYPES.  The code in CMakeLists.txt files would be more
platform agnostic and easier to read if one could iterate over
CMAKE_CONFIGURATION_TYPES on linux to set configuration specific variables
like COMPILE_DEFINITIONS_XXX.

--
Glenn
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.cmake.org/pipermail/cmake/attachments/20110607/6a16604f/attachment.htm>


More information about the CMake mailing list