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