PerConfigOption.cmake 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. # Filename: PerConfigOption.cmake
  2. #
  3. # This contains a convenience function for defining per-config options.
  4. # In single-config generators, it will set the option based on the defined
  5. # CMAKE_BUILD_TYPE. In multi-config generators, it will create separate
  6. # options, one per config.
  7. #
  8. # Function: per_config_option
  9. # Usage:
  10. # option(name "help string" [Config1] [Config2] [...ConfigN])
  11. #
  12. # Example:
  13. # per_config_option(DO_DEBUGGING "Enables debugging." Debug Standard)
  14. set(_PER_CONFIG_OPTIONS CACHE INTERNAL "Internal variable")
  15. function(per_config_option name help)
  16. set(_configs ${ARGN})
  17. # In single-config generatotrs, we simply create one config.
  18. if(NOT IS_MULTICONFIG)
  19. list(FIND _configs "${CMAKE_BUILD_TYPE}" _index)
  20. if(${_index} GREATER -1)
  21. option("${name}" "${help}" ON)
  22. else()
  23. option("${name}" "${help}" OFF)
  24. endif()
  25. elseif(DEFINED "${name}")
  26. # It's been explicitly defined, so that makes it not a multi-configuration
  27. # variable anymore.
  28. option("${name}" "${help}")
  29. return()
  30. else()
  31. foreach(_config ${CMAKE_CONFIGURATION_TYPES})
  32. string(TOUPPER "${_config}" _config_upper)
  33. list(FIND _configs "${_config}" _index)
  34. if(${_index} GREATER -1)
  35. option("${name}_${_config_upper}" "${help}" ON)
  36. else()
  37. option("${name}_${_config_upper}" "${help}" OFF)
  38. endif()
  39. endforeach()
  40. endif()
  41. list(APPEND _PER_CONFIG_OPTIONS "${name}")
  42. set(_PER_CONFIG_OPTIONS "${_PER_CONFIG_OPTIONS}" CACHE INTERNAL "Internal variable")
  43. endfunction(per_config_option)