[Cmake] Options depend on other options.
Brad King
brad . king at kitware . com
Tue, 15 Jul 2003 10:47:32 -0400 (EDT)
Klaas,
> I made several options in my top CmakeList file like:
>
> OPTION( WXART2D_USE_SVGIO
> "Enable SVG format module" ON)
>
> Know i want to set the other options to be On or OFF based on
> a certain option, but what i have tried sofar, CmakeSetup does not
> show the updated values for the option.
We've done this in some projects. You'll want to define a macro like
this:
# Macro to provide an option only if a set of other variables are ON.
# Example invocation:
#
# VTK_DEPENDENT_OPTION(USE_FOO "Use Foo" ON "USE_BAR;USE_ZOT" OFF)
#
# If both USE_BAR and USE_ZOT are true, this provides an option called
# USE_FOO that defaults to ON. Otherwise, it sets USE_FOO to OFF. If
# the status of USE_BAR or USE_ZOT ever changes, any value for the
# USE_FOO option is saved so that when the option is re-enabled it
# retains its old value.
#
MACRO(VTK_DEPENDENT_OPTION option doc default depends force)
SET(${option}_AVAILABLE 1)
# Test for each required variable.
FOREACH(d ${depends})
IF(NOT ${d})
SET(${option}_AVAILABLE 0)
ENDIF(NOT ${d})
ENDFOREACH(d)
IF(${option}_AVAILABLE)
# The option is available.
OPTION(${option} "${doc}" "${default}")
# Show the cache value to the user.
SET(${option} "${${option}}" CACHE BOOL "${doc}" FORCE)
ELSE(${option}_AVAILABLE)
# Option should not be available. Hide the cache value.
SET(${option} "${${option}}" CACHE INTERNAL "${doc}")
# Force the option value to be that specified.
SET(${option} ${force})
ENDIF(${option}_AVAILABLE)
ENDMACRO(VTK_DEPENDENT_OPTION)
Just rename the "VTK" parts to use your project's name. You can then use
it like this:
IF(WXART2D_USE_EDITOR)
SET(WXART2D_NO_EDITOR 0)
ELSE(WXART2D_USE_EDITOR)
SET(WXART2D_NO_EDITOR 1)
ENDIF(WXART2D_USE_EDITOR)
VTK_DEPENDENT_OPTION(WXART2D_USE_SVGIO "Enable SVG format module" OFF
WXART2D_NO_EDITOR ON)
This will force WXART2D_USE_SVGIO to be ON if WXART2D_USE_EDITOR is ON,
but will provide the option for WXART2D_USE_SVGIO with a default of OFF if
WXART2D_USE_EDITOR is OFF.
-Brad