[CMake] Use of CMake OPTION in code
Eric Noulard
eric.noulard at gmail.com
Tue Oct 21 05:55:43 EDT 2008
2008/10/21 Pelt, R.F.P. van <R.F.P.v.Pelt at tue.nl>:
>
> Dear all,
>
> Recently I have added an option to a CMake project that I'm using.
>
> For example:
> OPTION(BUILD_EXTRA_STUFF "Build extra stuff." ON)
>
> Whenever this is enables, this also changes a couple of things in
> the code, which is currently implemented with a hard define.
>
> For example:
> #define EXTRA_STUFF
> #ifdef EXTRA_STUFF
>
> Is there a way that I can 'propagate' the BUILD_EXTRA_STUFF option
> to my code, so that I can implements as follows:
>
> #ifdef BUILD_EXTRA_STUFF
May be you can try
IF(BUILD_EXTRA_STUFF)
ADD_DEFINITIONS(-DBUILD_EXTRA_STUFF)
ENDIF(BUILD_EXTRA_STUFF)
note that since CMake variables and cpp MACRO are disjoint you may well
IF(BUILD_EXTRA_STUFF)
ADD_DEFINITIONS(-DEXTRA_STUFF)
ENDIF(BUILD_EXTRA_STUFF)
such that you keep your current #ifdef EXTRA_STUFF
(but you may throw the hard code #define)
Another way to do it is to use a "config.h" file:
see
http://www.cmake.org/Wiki/CMake_HowToDoPlatformChecks
--
Erk
More information about the CMake
mailing list