CMakeDependentOption.cmake 2.0 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()
  33. set(${option}_AVAILABLE 0)
  34. endif()
  35. endforeach()
  36. if(${option}_AVAILABLE)
  37. option(${option} "${doc}" "${default}")
  38. set(${option} "${${option}}" CACHE BOOL "${doc}" FORCE)
  39. else()
  40. if(${option} MATCHES "^${option}$")
  41. else()
  42. set(${option} "${${option}}" CACHE INTERNAL "${doc}")
  43. endif()
  44. set(${option} ${force})
  45. endif()
  46. else()
  47. set(${option} "${${option}_ISSET}")
  48. endif()
  49. endmacro()