CMakeInitializeConfigs.cmake 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. # Distributed under the OSI-approved BSD 3-Clause License. See accompanying
  2. # file Copyright.txt or https://cmake.org/licensing for details.
  3. include_guard(GLOBAL)
  4. # Initializes `<_PREFIX>_<CONFIG>` variables from the corresponding
  5. # `<_PREFIX>_<CONFIG>_INIT`, for the configurations currently used.
  6. function(cmake_initialize_per_config_variable _PREFIX _DOCSTRING)
  7. string(STRIP "${${_PREFIX}_INIT}" _INIT)
  8. set("${_PREFIX}" "${_INIT}"
  9. CACHE STRING "${_DOCSTRING} during all build types.")
  10. mark_as_advanced("${_PREFIX}")
  11. if (NOT CMAKE_NOT_USING_CONFIG_FLAGS)
  12. set(_CONFIGS Debug Release MinSizeRel RelWithDebInfo)
  13. get_property(_GENERATOR_IS_MULTI_CONFIG GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
  14. if (_GENERATOR_IS_MULTI_CONFIG)
  15. list(APPEND _CONFIGS ${CMAKE_CONFIGURATION_TYPES})
  16. else()
  17. if (NOT CMAKE_NO_BUILD_TYPE)
  18. set(CMAKE_BUILD_TYPE "${CMAKE_BUILD_TYPE_INIT}" CACHE STRING
  19. "Choose the type of build, options are: None Debug Release RelWithDebInfo MinSizeRel ...")
  20. endif()
  21. list(APPEND _CONFIGS ${CMAKE_BUILD_TYPE})
  22. endif()
  23. list(REMOVE_DUPLICATES _CONFIGS)
  24. foreach(_BUILD_TYPE IN LISTS _CONFIGS)
  25. if (NOT "${_BUILD_TYPE}" STREQUAL "")
  26. string(TOUPPER "${_BUILD_TYPE}" _BUILD_TYPE)
  27. string(STRIP "${${_PREFIX}_${_BUILD_TYPE}_INIT}" _INIT)
  28. set("${_PREFIX}_${_BUILD_TYPE}" "${_INIT}"
  29. CACHE STRING "${_DOCSTRING} during ${_BUILD_TYPE} builds.")
  30. mark_as_advanced("${_PREFIX}_${_BUILD_TYPE}")
  31. endif()
  32. endforeach()
  33. endif()
  34. endfunction()