mirror of
https://github.com/Kitware/CMake.git
synced 2025-10-14 02:08:27 +08:00
Merge topic 'clang-libstdcpp-support'
5750fcd7b4
ci: enable `import_std23` module compilation with clang52e2785018
experimental/CXXModules: recycle the UUID28333c4516
Clang/CXXImportStd: support `-stdlib=libstdc++` Acked-by: Kitware Robot <kwrobot@kitware.com> Merge-request: !10727
This commit is contained in:
@@ -1,3 +1,3 @@
|
||||
set(CMake_TEST_MODULE_COMPILATION "named,compile_commands,collation,partitions,internal_partitions,export_bmi,install_bmi,shared,bmionly,build_database" CACHE STRING "")
|
||||
set(CMake_TEST_MODULE_COMPILATION "named,compile_commands,collation,partitions,internal_partitions,export_bmi,install_bmi,shared,bmionly,build_database,import_std23" CACHE STRING "")
|
||||
|
||||
include("${CMAKE_CURRENT_LIST_DIR}/configure_fedora42_common_clang.cmake")
|
||||
|
@@ -81,7 +81,7 @@ In order to activate support for ``import std`` in C++23 and newer targets,
|
||||
set
|
||||
|
||||
* variable ``CMAKE_EXPERIMENTAL_CXX_IMPORT_STD`` to
|
||||
* value ``a9e1cf81-9932-4810-974b-6eccaf14e457``.
|
||||
* value ``d0edc3af-4c50-42ea-a356-e2862fe7a444``.
|
||||
|
||||
This UUID may change in future versions of CMake. Be sure to use the value
|
||||
documented here by the source tree of the version of CMake with which you are
|
||||
|
@@ -92,7 +92,7 @@ Compilers which CMake natively supports module dependency scanning include:
|
||||
Support for ``import std`` is limited to the following toolchain and standard
|
||||
library combinations:
|
||||
|
||||
* Clang 18.1.2 and newer with ``-stdlib=libc++``
|
||||
* Clang 18.1.2 and newer with ``-stdlib=libc++`` or ``-stdlib=libstdc++``
|
||||
* MSVC toolset 14.36 and newer (provided with Visual Studio 17.6 Preview 2 and
|
||||
newer)
|
||||
* GCC 15 and newer.
|
||||
|
@@ -1,7 +1,11 @@
|
||||
function (_cmake_cxx_import_std std variable)
|
||||
if (NOT CMAKE_CXX_STANDARD_LIBRARY STREQUAL "libc++")
|
||||
if (CMAKE_CXX_STANDARD_LIBRARY STREQUAL "libc++")
|
||||
set(_clang_modules_json_impl "libc++")
|
||||
elseif (CMAKE_CXX_STANDARD_LIBRARY STREQUAL "libstdc++")
|
||||
set(_clang_modules_json_impl "libstdc++")
|
||||
else ()
|
||||
set("${variable}"
|
||||
"set(CMAKE_CXX${std}_COMPILER_IMPORT_STD_NOT_FOUND_MESSAGE \"Only `libc++` is supported\")\n"
|
||||
"set(CMAKE_CXX${std}_COMPILER_IMPORT_STD_NOT_FOUND_MESSAGE \"Only `libc++` and `libstdc++` are supported\")\n"
|
||||
PARENT_SCOPE)
|
||||
return ()
|
||||
endif ()
|
||||
@@ -10,7 +14,7 @@ function (_cmake_cxx_import_std std variable)
|
||||
COMMAND
|
||||
"${CMAKE_CXX_COMPILER}"
|
||||
${CMAKE_CXX_COMPILER_ID_ARG1}
|
||||
-print-file-name=libc++.modules.json
|
||||
"-print-file-name=${_clang_modules_json_impl}.modules.json"
|
||||
OUTPUT_VARIABLE _clang_libcxx_modules_json_file
|
||||
ERROR_VARIABLE _clang_libcxx_modules_json_file_err
|
||||
RESULT_VARIABLE _clang_libcxx_modules_json_file_res
|
||||
@@ -18,7 +22,7 @@ function (_cmake_cxx_import_std std variable)
|
||||
ERROR_STRIP_TRAILING_WHITESPACE)
|
||||
if (_clang_libcxx_modules_json_file_res)
|
||||
set("${variable}"
|
||||
"set(CMAKE_CXX${std}_COMPILER_IMPORT_STD_NOT_FOUND_MESSAGE \"Could not find `libc++.modules.json` resource\")\n"
|
||||
"set(CMAKE_CXX${std}_COMPILER_IMPORT_STD_NOT_FOUND_MESSAGE \"Could not find `${_clang_modules_json_impl}.modules.json` resource\")\n"
|
||||
PARENT_SCOPE)
|
||||
return ()
|
||||
endif ()
|
||||
@@ -26,17 +30,18 @@ function (_cmake_cxx_import_std std variable)
|
||||
# Without this file, we do not have modules installed.
|
||||
if (NOT EXISTS "${_clang_libcxx_modules_json_file}")
|
||||
set("${variable}"
|
||||
"set(CMAKE_CXX${std}_COMPILER_IMPORT_STD_NOT_FOUND_MESSAGE \"`libc++.modules.json` resource does not exist\")\n"
|
||||
"set(CMAKE_CXX${std}_COMPILER_IMPORT_STD_NOT_FOUND_MESSAGE \"`${_clang_modules_json_impl}.modules.json` resource does not exist\")\n"
|
||||
PARENT_SCOPE)
|
||||
return ()
|
||||
endif ()
|
||||
|
||||
if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS "18.1.2")
|
||||
if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS "18.1.2" AND
|
||||
CMAKE_CXX_STANDARD_LIBRARY STREQUAL "libc++")
|
||||
# The original PR had a key spelling mismatch internally. Do not support it
|
||||
# and instead require a release known to have the fix.
|
||||
# https://github.com/llvm/llvm-project/pull/83036
|
||||
set("${variable}"
|
||||
"set(CMAKE_CXX${std}_COMPILER_IMPORT_STD_NOT_FOUND_MESSAGE \"LLVM 18.1.2 is required for `libc++.modules.json` format fix\")\n"
|
||||
"set(CMAKE_CXX${std}_COMPILER_IMPORT_STD_NOT_FOUND_MESSAGE \"LLVM 18.1.2 is required for `${_clang_modules_json_impl}.modules.json` format fix\")\n"
|
||||
PARENT_SCOPE)
|
||||
return ()
|
||||
endif ()
|
||||
@@ -91,9 +96,15 @@ function (_cmake_cxx_import_std std variable)
|
||||
|
||||
string(JSON _clang_modules_json_module_source GET "${_clang_modules_json_module}" "source-path")
|
||||
string(JSON _clang_modules_json_module_is_stdlib GET "${_clang_modules_json_module}" "is-std-library")
|
||||
string(JSON _clang_modules_json_module_local_arguments GET "${_clang_modules_json_module}" "local-arguments")
|
||||
string(JSON _clang_modules_json_module_nsystem_include_directories LENGTH "${_clang_modules_json_module_local_arguments}" "system-include-directories")
|
||||
string(JSON _clang_modules_json_module_local_arguments ERROR_VARIABLE _clang_modules_json_module_local_arguments_error GET "${_clang_modules_json_module}" "local-arguments")
|
||||
string(JSON _clang_modules_json_module_nsystem_include_directories ERROR_VARIABLE _clang_modules_json_module_nsystem_include_directories_error LENGTH "${_clang_modules_json_module_local_arguments}" "system-include-directories")
|
||||
|
||||
if (_clang_modules_json_module_local_arguments_error)
|
||||
set(_clang_modules_json_module_local_arguments "")
|
||||
endif ()
|
||||
if (_clang_modules_json_module_nsystem_include_directories_error)
|
||||
set(_clang_modules_json_module_nsystem_include_directories 0)
|
||||
endif ()
|
||||
if (NOT IS_ABSOLUTE "${_clang_modules_json_module_source}")
|
||||
string(PREPEND _clang_modules_json_module_source "${_clang_modules_dir}/")
|
||||
endif ()
|
||||
@@ -104,16 +115,18 @@ function (_cmake_cxx_import_std std variable)
|
||||
set(_clang_modules_is_stdlib 1)
|
||||
endif ()
|
||||
|
||||
math(EXPR _clang_modules_json_module_nsystem_include_directories_range "${_clang_modules_json_module_nsystem_include_directories} - 1")
|
||||
foreach (_clang_modules_json_modules_system_include_directories_idx RANGE 0 "${_clang_modules_json_module_nsystem_include_directories_range}")
|
||||
string(JSON _clang_modules_json_module_system_include_directory GET "${_clang_modules_json_module_local_arguments}" "system-include-directories" "${_clang_modules_json_modules_system_include_directories_idx}")
|
||||
if (_clang_modules_json_module_nsystem_include_directories)
|
||||
math(EXPR _clang_modules_json_module_nsystem_include_directories_range "${_clang_modules_json_module_nsystem_include_directories} - 1")
|
||||
foreach (_clang_modules_json_modules_system_include_directories_idx RANGE 0 "${_clang_modules_json_module_nsystem_include_directories_range}")
|
||||
string(JSON _clang_modules_json_module_system_include_directory GET "${_clang_modules_json_module_local_arguments}" "system-include-directories" "${_clang_modules_json_modules_system_include_directories_idx}")
|
||||
|
||||
if (NOT IS_ABSOLUTE "${_clang_modules_json_module_system_include_directory}")
|
||||
string(PREPEND _clang_modules_json_module_system_include_directory "${_clang_modules_dir}/")
|
||||
endif ()
|
||||
list(APPEND _clang_modules_include_dirs_list
|
||||
"${_clang_modules_json_module_system_include_directory}")
|
||||
endforeach ()
|
||||
if (NOT IS_ABSOLUTE "${_clang_modules_json_module_system_include_directory}")
|
||||
string(PREPEND _clang_modules_json_module_system_include_directory "${_clang_modules_dir}/")
|
||||
endif ()
|
||||
list(APPEND _clang_modules_include_dirs_list
|
||||
"${_clang_modules_json_module_system_include_directory}")
|
||||
endforeach ()
|
||||
endif ()
|
||||
endforeach ()
|
||||
|
||||
# Split the paths into basedirs and module paths.
|
||||
|
@@ -39,7 +39,7 @@ cmExperimental::FeatureData LookupTable[] = {
|
||||
false },
|
||||
// CxxImportStd
|
||||
{ "CxxImportStd",
|
||||
"a9e1cf81-9932-4810-974b-6eccaf14e457",
|
||||
"d0edc3af-4c50-42ea-a356-e2862fe7a444",
|
||||
"CMAKE_EXPERIMENTAL_CXX_IMPORT_STD",
|
||||
"CMake's support for `import std;` in C++23 and newer is experimental. It "
|
||||
"is meant only for experimentation and feedback to CMake developers.",
|
||||
|
@@ -1,5 +1,5 @@
|
||||
set(CMAKE_EXPERIMENTAL_CXX_IMPORT_STD
|
||||
"a9e1cf81-9932-4810-974b-6eccaf14e457")
|
||||
"d0edc3af-4c50-42ea-a356-e2862fe7a444")
|
||||
|
||||
cmake_minimum_required(VERSION 3.29)
|
||||
project(cxx_modules_import_std_export_no_std CXX)
|
||||
|
@@ -1,5 +1,5 @@
|
||||
set(CMAKE_EXPERIMENTAL_CXX_IMPORT_STD
|
||||
"a9e1cf81-9932-4810-974b-6eccaf14e457")
|
||||
"d0edc3af-4c50-42ea-a356-e2862fe7a444")
|
||||
|
||||
cmake_minimum_required(VERSION 3.29)
|
||||
project(cxx_modules_import_std_export_no_std CXX)
|
||||
|
@@ -1,5 +1,5 @@
|
||||
set(CMAKE_EXPERIMENTAL_CXX_IMPORT_STD
|
||||
"a9e1cf81-9932-4810-974b-6eccaf14e457")
|
||||
"d0edc3af-4c50-42ea-a356-e2862fe7a444")
|
||||
|
||||
cmake_minimum_required(VERSION 3.29)
|
||||
project(cxx_modules_import_std_no_std_property CXX)
|
||||
|
@@ -1,5 +1,5 @@
|
||||
set(CMAKE_EXPERIMENTAL_CXX_IMPORT_STD
|
||||
"a9e1cf81-9932-4810-974b-6eccaf14e457")
|
||||
"d0edc3af-4c50-42ea-a356-e2862fe7a444")
|
||||
|
||||
cmake_minimum_required(VERSION 3.29)
|
||||
project(cxx_modules_import_std_not_in_export CXX)
|
||||
|
@@ -1,5 +1,5 @@
|
||||
set(CMAKE_EXPERIMENTAL_CXX_IMPORT_STD
|
||||
"a9e1cf81-9932-4810-974b-6eccaf14e457")
|
||||
"d0edc3af-4c50-42ea-a356-e2862fe7a444")
|
||||
|
||||
cmake_minimum_required(VERSION 3.29)
|
||||
project(cxx_modules_import_std_not_in_export CXX)
|
||||
|
@@ -1,5 +1,5 @@
|
||||
set(CMAKE_EXPERIMENTAL_CXX_IMPORT_STD
|
||||
"a9e1cf81-9932-4810-974b-6eccaf14e457")
|
||||
"d0edc3af-4c50-42ea-a356-e2862fe7a444")
|
||||
|
||||
cmake_minimum_required(VERSION 3.29)
|
||||
|
||||
|
@@ -1,5 +1,5 @@
|
||||
set(CMAKE_EXPERIMENTAL_CXX_IMPORT_STD
|
||||
"a9e1cf81-9932-4810-974b-6eccaf14e457")
|
||||
"d0edc3af-4c50-42ea-a356-e2862fe7a444")
|
||||
|
||||
cmake_minimum_required(VERSION 3.29)
|
||||
project(cxx_modules_import_std CXX)
|
||||
|
@@ -1,5 +1,5 @@
|
||||
set(CMAKE_EXPERIMENTAL_CXX_IMPORT_STD
|
||||
"a9e1cf81-9932-4810-974b-6eccaf14e457")
|
||||
"d0edc3af-4c50-42ea-a356-e2862fe7a444")
|
||||
|
||||
cmake_language(GET_EXPERIMENTAL_FEATURE_ENABLED
|
||||
"CxxImportStd"
|
||||
|
Reference in New Issue
Block a user