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