mirror of
https://github.com/Kitware/CMake.git
synced 2026-05-04 13:19:51 -05:00
fa10dc6c22
Adds a parser and serializer for the EcoStd Module Metadata format RFC: https://github.com/ecostd/rfcs/pull/3 This adapts the existing experimental support for import std; to use the new parser. The CMAKE_CXX_STDLIB_MODULES_JSON is now the canonical variable for controlling how CMake discovers the stdlib module metadata, and is used directly by compiler detection. Toolchains can still override the __CMAKE::CXX## targets if they wish, either in conjunction with CMAKE_CXX_STDLIB_MODULE_JSON or not. It is possible to disable automatic detection of CMAKE_CXX_STDLIB_MODULE_JSON by setting it to the empty string. When available, the CMAKE_CXX_STDLIB_MODULE_JSON will be used to create all requested C++ stdlibs which do not already have targets.
51 lines
1.8 KiB
CMake
51 lines
1.8 KiB
CMake
enable_language(CXX)
|
|
|
|
set(info "")
|
|
|
|
# See `Modules/Compiler/MSVC-CXX.cmake` for this. If there is explicitly no
|
|
# default, the feature list is populated to be everything.
|
|
if (DEFINED CMAKE_CXX_STANDARD_DEFAULT AND
|
|
CMAKE_CXX_STANDARD_DEFAULT STREQUAL "")
|
|
set(CMAKE_CXX_COMPILE_FEATURES "")
|
|
endif ()
|
|
|
|
# Detect if the environment forces a C++ standard, let the test selection know.
|
|
set(forced_cxx_standard 0)
|
|
if (CMAKE_CXX_FLAGS MATCHES "-std=")
|
|
set(forced_cxx_standard 1)
|
|
endif ()
|
|
|
|
macro (cxx_check_import_std version)
|
|
set(have_cxx${version}_import_std 0)
|
|
if ("${version}" IN_LIST CMAKE_CXX_COMPILER_IMPORT_STD)
|
|
set(have_cxx${version}_import_std 1)
|
|
endif ()
|
|
|
|
if (TARGET "__CMAKE:CXX${version}" AND NOT have_cxx${version}_import_std)
|
|
message(FATAL_ERROR
|
|
"The toolchain's C++${version} target exists, but the user variable does "
|
|
"not indicate it.")
|
|
endif ()
|
|
endmacro ()
|
|
|
|
cxx_check_import_std(23)
|
|
cxx_check_import_std(26)
|
|
|
|
# Forward information about the C++ compile features.
|
|
string(APPEND info "\
|
|
set(CMAKE_CXX_COMPILE_FEATURES \"${CMAKE_CXX_COMPILE_FEATURES}\")
|
|
set(CMAKE_MAKE_PROGRAM \"${CMAKE_MAKE_PROGRAM}\")
|
|
set(forced_cxx_standard \"${forced_cxx_standard}\")
|
|
set(have_cxx23_import_std \"${have_cxx23_import_std}\")
|
|
set(have_cxx26_import_std \"${have_cxx26_import_std}\")
|
|
set(CMAKE_CXX_COMPILER_VERSION \"${CMAKE_CXX_COMPILER_VERSION}\")
|
|
set(CMAKE_CXX_OUTPUT_EXTENSION \"${CMAKE_CXX_OUTPUT_EXTENSION}\")
|
|
set(CXXModules_default_build_type \"${CMAKE_BUILD_TYPE}\")
|
|
set(CMAKE_CXX_STANDARD_DEFAULT \"${CMAKE_CXX_STANDARD_DEFAULT}\")
|
|
set(CMAKE_CXX20_STANDARD_COMPILE_OPTION \"${CMAKE_CXX20_STANDARD_COMPILE_OPTION}\")
|
|
set(CMAKE_CXX_COMPILER_FRONTEND_VARIANT \"${CMAKE_CXX_COMPILER_FRONTEND_VARIANT}\")
|
|
set(CMAKE_CXX_MODULE_MAP_FORMAT \"${CMAKE_CXX_MODULE_MAP_FORMAT}\")
|
|
")
|
|
|
|
file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/info.cmake" "${info}")
|