Imported Upstream version 2.8.10.2
[platform/upstream/cmake.git] / Modules / CMakeDependentOption.cmake
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.
6 # Example invocation:
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
15 #=============================================================================
16 # Copyright 2006-2009 Kitware, Inc.
17 #
18 # Distributed under the OSI-approved BSD License (the "License");
19 # see accompanying file Copyright.txt for details.
20 #
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.)
27
28 macro(CMAKE_DEPENDENT_OPTION option doc default depends force)
29   if(${option}_ISSET MATCHES "^${option}_ISSET$")
30     set(${option}_AVAILABLE 1)
31     foreach(d ${depends})
32       string(REGEX REPLACE " +" ";" CMAKE_DEPENDENT_OPTION_DEP "${d}")
33       if(${CMAKE_DEPENDENT_OPTION_DEP})
34       else()
35         set(${option}_AVAILABLE 0)
36       endif()
37     endforeach()
38     if(${option}_AVAILABLE)
39       option(${option} "${doc}" "${default}")
40       set(${option} "${${option}}" CACHE BOOL "${doc}" FORCE)
41     else()
42       if(${option} MATCHES "^${option}$")
43       else()
44         set(${option} "${${option}}" CACHE INTERNAL "${doc}")
45       endif()
46       set(${option} ${force})
47     endif()
48   else()
49     set(${option} "${${option}_ISSET}")
50   endif()
51 endmacro()