[CMake] Way to use precompilation directive on cmake and conditionnal linking
Philip Lowman
philip at yhbt.com
Tue Mar 24 23:27:34 EDT 2009
On Tue, Mar 24, 2009 at 12:11 PM, Nadir SOUALEM <nadir.soualem at irisa.fr>wrote:
> Tyler wrote:
> Not so bad, but it would be very nice to do some things such adding
> preprocessing on command line calls:
> cmake -DPREPROCCESSING_VAR
>
You could certainly file a feature request that did something like this but
I think it would probably prove too confusing for people.
You could implement it with a macro provided you are comfortable with some
standard way of converting CMake variables into preprocessor definitions.
Any variables that start with DEF_foo would result in
add_definitions(-Dfoo). The list of variables that exist in the system is
available.
Ultimately though build systems usually deal with a fixed number of
preprocessor definitions and usually they just add build options for them
OPTION(USE_FOO "Use foo" ON)
if(USE_FOO)
add_definitions(-DHAVE_FOO)
find_package(FOO)
if(NOT FOO_FOUND)
MESSAGE(FATAL_ERROR "You enabled USE_FOO but FOO was not found")
endif()
endif()
Obviously if you just want to add a preprocessor definition the code is far
simpler
OPTION(ENABLE_BAR "Enable special bar feature" OFF)
if(ENABLE_BAR)
ADD_DEFINITIONS(-DBAR_ENABLED)
endif()
This has the benefit of documenting your build options as you go along
somewhere.
--
Philip Lowman
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.cmake.org/pipermail/cmake/attachments/20090324/1da2dfb1/attachment.htm>
More information about the CMake
mailing list