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

Glenn Coombs glenn.coombs at gmail.com
Thu Jun 16 09:18:41 EDT 2011


On 13 June 2011 02:53, Michael Hertling <mhertling at online.de> wrote:

>
> AFAIK, there's no other approach to take account of single- and multi-
> config generators at the same time for this purpose, but perhaps, you
> could design the loop a bit smarter:
>
> FOREACH(i IN LISTS CMAKE_CONFIGURATION_TYPES ITEMS ${CMAKE_BUILD_TYPE})
>    STRING(TOUPPER ${i} j)
>    IF(NOT j MATCHES "RELEASENOOUTFILES")
>        SET_PROPERTY(...)
>    ENDIF()
> ENDFOREACH()
>

I wasn't aware of that syntax of the foreach command - that does tidy it up
a bit.


> and rely on the assumption that
>
> (1) the FLAGS are mentioned after the COMPILE_DEFINITIONS, and
> (2) the last -D/-U argument in the command line will take effect.
>
> At least, GCC guarantees that (2) holds, but I have not found any
> explicit assertion in the documentation that CMake guarantees (1),
> though it seems to work in this way.
>

I'm not overly keen on that solution.

BTW, is an "inverted" logic an option, i.e. a preprocessor definition
> NO_GEN_OUTFILES enabled for the RELEASENOOUTFILES configuration only?
> This would be much easier and fit that configuration's intent better.
>

The default is to generate outfiles and the code is littered with blocks
like this:

#ifdef GEN_OUTFILES
...
#endif

Changing them to #ifndef NO_GEN_OUTFILES would work but the double negative
makes the code less readable.  I'll stick with what I already have for the
moment, but add your modification to the foreach loop.

Thanks,

--
Glenn
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.cmake.org/pipermail/cmake/attachments/20110616/7f9c0bea/attachment.htm>


More information about the CMake mailing list