1 # - Macro to provide an option dependent on other options.
2 # This macro presents an option to the user only if a set of other
3 # conditions are true. When the option is not presented a default
4 # value is used, but any value set by the user is preserved for when
5 # the option is presented again.
7 # CMAKE_DEPENDENT_OPTION(USE_FOO "Use Foo" ON
8 # "USE_BAR;NOT USE_ZOT" OFF)
9 # If USE_BAR is true and USE_ZOT is false, this provides an option called
10 # USE_FOO that defaults to ON. Otherwise, it sets USE_FOO to OFF. If
11 # the status of USE_BAR or USE_ZOT ever changes, any value for the
12 # USE_FOO option is saved so that when the option is re-enabled it
13 # retains its old value.
15 #=============================================================================
16 # Copyright 2006-2009 Kitware, Inc.
18 # Distributed under the OSI-approved BSD License (the "License");
19 # see accompanying file Copyright.txt for details.
21 # This software is distributed WITHOUT ANY WARRANTY; without even the
22 # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
23 # See the License for more information.
24 #=============================================================================
25 # (To distribute this file outside of CMake, substitute the full
26 # License text for the above reference.)
28 macro(CMAKE_DEPENDENT_OPTION option doc default depends force)
29 if(${option}_ISSET MATCHES "^${option}_ISSET$")
30 set(${option}_AVAILABLE 1)
32 string(REGEX REPLACE " +" ";" CMAKE_DEPENDENT_OPTION_DEP "${d}")
33 if(${CMAKE_DEPENDENT_OPTION_DEP})
35 set(${option}_AVAILABLE 0)
38 if(${option}_AVAILABLE)
39 option(${option} "${doc}" "${default}")
40 set(${option} "${${option}}" CACHE BOOL "${doc}" FORCE)
42 if(${option} MATCHES "^${option}$")
44 set(${option} "${${option}}" CACHE INTERNAL "${doc}")
46 set(${option} ${force})
49 set(${option} "${${option}_ISSET}")