[CMake] Dependent options (was Re: Questions on features)
E. Wing
ewmailing at gmail.com
Fri Sep 5 22:06:37 EDT 2008
On 8/21/08, Jens.Storz at elektrobit.com <Jens.Storz at elektrobit.com> wrote:
> Hello,
>
> we are currently developing with MPC (Makefile project creator) and I'm
> trying to find out what advantages we would have with a switch to CMake.
> First of all I would like to say, that CMake is very useful for me.
> Still there are some things, I'd like to know how to do or if this
> features are planned to be implemented.
>
> 1) In our MPC generated Visual Studio solution files we can easily
> switch the active solution platform. I actually don't know how to
> realize this with CMake.
> Example: you are compiling for x86 and want to switch to ARMV4I
Don't know this. Somebody else will have to answer.
> 2) Is it possible to realize dropdown lists with multiple options in
> CMake GUI setup? I'm only aware of boolean ( ON | OFF ) and strings.
> Example: you want to select processor from a list (x86, ARMV4I, SH4,
> ...) to avoid misspelling when using strings.
I don't know of any feature like this. I could really use such a thing
too. In the case where it can be approximated by lots of ON/OFF
options, it's a real pain to validate that only (or exactly) 1 of the
options is set and not multiple options.
> 3) Assume you have a lot of features to select including dependencies.
> How can I realize to set a dependent feature in the CMake GUI setup, if
> another is changed?
> Example 1: your car can have a "radio" (bool) and "mp3" (bool). If
> you select "mp3"=ON, "radio" is also set to ON.
>
This can be done, but my way is really ugly (especially if you then
want to remove the option again when you turn the parent OFF).
Basically, for my solution, it comes down to using SET(... CACHE BOOL
... FORCE). But you have to be a little careful about the variable
being forced back when the user changes it. And I also want to
preserve the user selected option if the option gets removed. So all
this makes me save the value in a private internal/hidden variable.
And then to set initial default values, I need a special check if the
script is being run for the first time.
All in all, it works, but I really don't like it. I would like to know
a better way to deal with this.
Below is an example from my own code. For OS X, I want to provide an
option to build a Framework style library instead of a dylib. It
should only appear on APPLE and if the user selects they want a
dynamic library. If they unselect dynamic library, the framework
option gets removed (but I preserve the last state in case it comes
back).
If somebody wants to generalize it so it can be used, that would be
great. Or if there is already a better implementation, I would love to
know about that.
OPTION(WANTS_BUILD_SHARED_LIBRARY "Set to ON to build dynamic library." ON)
IF(APPLE)
# Lots of ugliness to force CMake to make the GUI option disappear when
# when the option is not available.
IF(NOT LUA_CONFIG_HAS_BEEN_RUN_BEFORE)
SET(INTERNAL_WANTS_FRAMEWORK_STATE ON)
SET(WANTS_BUILD_FRAMEWORK ON)
ENDIF(NOT LUA_CONFIG_HAS_BEEN_RUN_BEFORE)
IF(WANTS_BUILD_SHARED_LIBRARY)
SET(INTERNAL_WANTS_FRAMEWORK_STATE ${WANTS_BUILD_FRAMEWORK})
SET(WANTS_BUILD_FRAMEWORK ${INTERNAL_WANTS_FRAMEWORK_STATE} CACHE
BOOL "Set to ON to build framework instead of dylib. Only valid if
BUILD_SHARED_LIBRARY is ON an is OS X." FORCE)
OPTION(WANTS_BUILD_FRAMEWORK "Set to ON to build framework instead
of dylib. Only valid if BUILD_SHARED_LIBRARY is ON an is OS X."
${INTERNAL_WANTS_FRAMEWORK_STATE})
ELSE(WANTS_BUILD_SHARED_LIBRARY)
SET(INTERNAL_WANTS_FRAMEWORK_STATE ${WANTS_BUILD_FRAMEWORK})
SET(WANTS_BUILD_FRAMEWORK ${INTERNAL_WANTS_FRAMEWORK_STATE} CACHE
INTERNAL "Set to ON to build framework instead of dylib. Only valid if
BUILD_SHARED_LIBRARY is ON an is OS X." FORCE)
ENDIF(WANTS_BUILD_SHARED_LIBRARY)
OPTION(LUA_FRAMEWORK_INSTALL_SYMLINKS_FOR_EXECUTABLES_TO_CMAKE_INSTALL_PREFIX_BIN_DIR
"Set to ON to create symlinks to lua & luac to CMAKE_PREFIX_PATH/bin.
For framework install only." ON)
ENDIF(APPLE)
# This needs to be run very last so other parts of the scripts can take
# advantage of this.
IF(NOT LUA_CONFIG_HAS_BEEN_RUN_BEFORE)
SET(LUA_CONFIG_HAS_BEEN_RUN_BEFORE 1 CACHE INTERNAL "Flag to track
whether this is the first time running CMake or if CMake has been
configured before")
ENDIF(NOT LUA_CONFIG_HAS_BEEN_RUN_BEFORE)
-Eric
More information about the CMake
mailing list