[CMake] How to set a preprocessor define for all build configurations except one ?
Glenn Coombs
glenn.coombs at gmail.com
Thu Jun 16 17:44:20 EDT 2011
On 16 June 2011 15:45, Michael Hertling <mhertling at online.de> wrote:
> IMO, the default should not need to be explicitly enabled but the
> exception, and readability - though important - is subordinate to
> functionality, but probably, this is a matter of personal taste.
>
> However, if you stick with the GEN_OUTFILES definition, be aware of
> the single-config generator with an empty build type. In that case,
> only the COMPILE_DEFINITIONS property is in effect, so you must add
> the GEN_OUTFILES definition to it, but with a non-empty build type,
> this config-less property is in effect, too, so you must *not* add
> GEN_OUTFILE to it. Thus, you need to differentiate these cases:
>
> IF(CMAKE_CONFIGURATION_TYPES OR CMAKE_BUILD_TYPE)
> FOREACH(... IN LISTS ... ITEMS ...)
> # Set COMPILE_DEFINITIONS_<CONFIG>.
> ENDFOREACH()
> ELSE()
> # Set COMPILE_DEFINITIONS.
> ENDIF()
>
> Clearly, this cuts down the elegance of the FOREACH loop, while the
> inverted approach with NO_GEN_OUTFILES would be unalteredly smooth.
>
Luckily I already have this in my CMakeLists.txt:
if (NOT CMAKE_CONFIGURATION_TYPES AND NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release)
endif()
to force the default build to use the Release configuration. Otherwise I
would have fallen foul of the case you are suggesting.
Is COMPILE_DEFINITIONS only used in single-config generators if
CMAKE_BUILD_TYPE is not set ? That might explain why my initial attempts to
do this failed. I had added GEN_OUTFILES to COMPILE_DEFINITIONS thinking
this would apply to all configs. And then when I tried to remove that
option from COMPILE_DEFINITIONS_RELEASENOOUTFILES it failed to have the
desired effect.
Would that approach have worked for the multi-config generators ? Do they
use the concatenation of COMPILE_DEFINITIONS and COMPILE_DEFINITIONS_<active
config> ?
--
Glenn
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.cmake.org/pipermail/cmake/attachments/20110616/42ae6eda/attachment.htm>
More information about the CMake
mailing list