CMakeDependentOption.cmake 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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. # Copyright 2006-2009 Kitware, Inc.
  16. #
  17. # Distributed under the OSI-approved BSD License (the "License");
  18. # see accompanying file Copyright.txt for details.
  19. #
  20. # This software is distributed WITHOUT ANY WARRANTY; without even the
  21. # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  22. # See the License for more information.
  23. #=============================================================================
  24. # (To distribute this file outside of CMake, substitute the full
  25. # License text for the above reference.)
  26. MACRO(CMAKE_DEPENDENT_OPTION option doc default depends force)
  27. IF(${option}_ISSET MATCHES "^${option}_ISSET$")
  28. SET(${option}_AVAILABLE 1)
  29. FOREACH(d ${depends})
  30. STRING(REGEX REPLACE " +" ";" CMAKE_DEPENDENT_OPTION_DEP "${d}")
  31. IF(${CMAKE_DEPENDENT_OPTION_DEP})
  32. ELSE(${CMAKE_DEPENDENT_OPTION_DEP})
  33. SET(${option}_AVAILABLE 0)
  34. ENDIF(${CMAKE_DEPENDENT_OPTION_DEP})
  35. ENDFOREACH(d)
  36. IF(${option}_AVAILABLE)
  37. OPTION(${option} "${doc}" "${default}")
  38. SET(${option} "${${option}}" CACHE BOOL "${doc}" FORCE)
  39. ELSE(${option}_AVAILABLE)
  40. IF(${option} MATCHES "^${option}$")
  41. ELSE(${option} MATCHES "^${option}$")
  42. SET(${option} "${${option}}" CACHE INTERNAL "${doc}")
  43. ENDIF(${option} MATCHES "^${option}$")
  44. SET(${option} ${force})
  45. ENDIF(${option}_AVAILABLE)
  46. ELSE(${option}_ISSET MATCHES "^${option}_ISSET$")
  47. SET(${option} "${${option}_ISSET}")
  48. ENDIF(${option}_ISSET MATCHES "^${option}_ISSET$")
  49. ENDMACRO(CMAKE_DEPENDENT_OPTION)