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.
14 MACRO(CMAKE_DEPENDENT_OPTION option doc default depends force)
15 IF(${option}_ISSET MATCHES "^${option}_ISSET$")
16 SET(${option}_AVAILABLE 1)
18 STRING(REGEX REPLACE " +" ";" CMAKE_DEPENDENT_OPTION_DEP "${d}")
19 IF(${CMAKE_DEPENDENT_OPTION_DEP})
20 ELSE(${CMAKE_DEPENDENT_OPTION_DEP})
21 SET(${option}_AVAILABLE 0)
22 ENDIF(${CMAKE_DEPENDENT_OPTION_DEP})
24 IF(${option}_AVAILABLE)
25 OPTION(${option} "${doc}" "${default}")
26 SET(${option} "${${option}}" CACHE BOOL "${doc}" FORCE)
27 ELSE(${option}_AVAILABLE)
28 IF(${option} MATCHES "^${option}$")
29 ELSE(${option} MATCHES "^${option}$")
30 SET(${option} "${${option}}" CACHE INTERNAL "${doc}")
31 ENDIF(${option} MATCHES "^${option}$")
32 SET(${option} ${force})
33 ENDIF(${option}_AVAILABLE)
34 ELSE(${option}_ISSET MATCHES "^${option}_ISSET$")
35 SET(${option} "${${option}_ISSET}")
36 ENDIF(${option}_ISSET MATCHES "^${option}_ISSET$")
37 ENDMACRO(CMAKE_DEPENDENT_OPTION)