Browse Source

Merge topic 'clang-libstdcpp-support'

5750fcd7b4 ci: enable `import_std23` module compilation with clang
52e2785018 experimental/CXXModules: recycle the UUID
28333c4516 Clang/CXXImportStd: support `-stdlib=libstdc++`

Acked-by: Kitware Robot <[email protected]>
Merge-request: !10727
Brad King 8 months ago
parent
commit
74e677f62b

+ 1 - 1
.gitlab/ci/configure_fedora42_ninja_clang.cmake

@@ -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")
 include("${CMAKE_CURRENT_LIST_DIR}/configure_fedora42_common_clang.cmake")

+ 1 - 1
Help/dev/experimental.rst

@@ -81,7 +81,7 @@ In order to activate support for ``import std`` in C++23 and newer targets,
 set
 set
 
 
 * variable ``CMAKE_EXPERIMENTAL_CXX_IMPORT_STD`` to
 * 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
 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
 documented here by the source tree of the version of CMake with which you are

+ 1 - 1
Help/manual/cmake-cxxmodules.7.rst

@@ -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
 Support for ``import std`` is limited to the following toolchain and standard
 library combinations:
 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
 * MSVC toolset 14.36 and newer (provided with Visual Studio 17.6 Preview 2 and
   newer)
   newer)
 * GCC 15 and newer.
 * GCC 15 and newer.

+ 32 - 19
Modules/Compiler/Clang-CXX-CXXImportStd.cmake

@@ -1,7 +1,11 @@
 function (_cmake_cxx_import_std std variable)
 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("${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)
       PARENT_SCOPE)
     return ()
     return ()
   endif ()
   endif ()
@@ -10,7 +14,7 @@ function (_cmake_cxx_import_std std variable)
     COMMAND
     COMMAND
       "${CMAKE_CXX_COMPILER}"
       "${CMAKE_CXX_COMPILER}"
       ${CMAKE_CXX_COMPILER_ID_ARG1}
       ${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
     OUTPUT_VARIABLE _clang_libcxx_modules_json_file
     ERROR_VARIABLE _clang_libcxx_modules_json_file_err
     ERROR_VARIABLE _clang_libcxx_modules_json_file_err
     RESULT_VARIABLE _clang_libcxx_modules_json_file_res
     RESULT_VARIABLE _clang_libcxx_modules_json_file_res
@@ -18,7 +22,7 @@ function (_cmake_cxx_import_std std variable)
     ERROR_STRIP_TRAILING_WHITESPACE)
     ERROR_STRIP_TRAILING_WHITESPACE)
   if (_clang_libcxx_modules_json_file_res)
   if (_clang_libcxx_modules_json_file_res)
     set("${variable}"
     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)
       PARENT_SCOPE)
     return ()
     return ()
   endif ()
   endif ()
@@ -26,17 +30,18 @@ function (_cmake_cxx_import_std std variable)
   # Without this file, we do not have modules installed.
   # Without this file, we do not have modules installed.
   if (NOT EXISTS "${_clang_libcxx_modules_json_file}")
   if (NOT EXISTS "${_clang_libcxx_modules_json_file}")
     set("${variable}"
     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)
       PARENT_SCOPE)
     return ()
     return ()
   endif ()
   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
     # The original PR had a key spelling mismatch internally. Do not support it
     # and instead require a release known to have the fix.
     # and instead require a release known to have the fix.
     # https://github.com/llvm/llvm-project/pull/83036
     # https://github.com/llvm/llvm-project/pull/83036
     set("${variable}"
     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)
       PARENT_SCOPE)
     return ()
     return ()
   endif ()
   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_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_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}")
     if (NOT IS_ABSOLUTE "${_clang_modules_json_module_source}")
       string(PREPEND _clang_modules_json_module_source "${_clang_modules_dir}/")
       string(PREPEND _clang_modules_json_module_source "${_clang_modules_dir}/")
     endif ()
     endif ()
@@ -104,16 +115,18 @@ function (_cmake_cxx_import_std std variable)
       set(_clang_modules_is_stdlib 1)
       set(_clang_modules_is_stdlib 1)
     endif ()
     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 (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 (_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 ()
+    endif ()
   endforeach ()
   endforeach ()
 
 
   # Split the paths into basedirs and module paths.
   # Split the paths into basedirs and module paths.

+ 1 - 1
Source/cmExperimental.cxx

@@ -39,7 +39,7 @@ cmExperimental::FeatureData LookupTable[] = {
     false },
     false },
   // CxxImportStd
   // CxxImportStd
   { "CxxImportStd",
   { "CxxImportStd",
-    "a9e1cf81-9932-4810-974b-6eccaf14e457",
+    "d0edc3af-4c50-42ea-a356-e2862fe7a444",
     "CMAKE_EXPERIMENTAL_CXX_IMPORT_STD",
     "CMAKE_EXPERIMENTAL_CXX_IMPORT_STD",
     "CMake's support for `import std;` in C++23 and newer is experimental. It "
     "CMake's support for `import std;` in C++23 and newer is experimental. It "
     "is meant only for experimentation and feedback to CMake developers.",
     "is meant only for experimentation and feedback to CMake developers.",

+ 1 - 1
Tests/RunCMake/CXXModules/examples/import-std-export-no-std-build/CMakeLists.txt

@@ -1,5 +1,5 @@
 set(CMAKE_EXPERIMENTAL_CXX_IMPORT_STD
 set(CMAKE_EXPERIMENTAL_CXX_IMPORT_STD
-  "a9e1cf81-9932-4810-974b-6eccaf14e457")
+  "d0edc3af-4c50-42ea-a356-e2862fe7a444")
 
 
 cmake_minimum_required(VERSION 3.29)
 cmake_minimum_required(VERSION 3.29)
 project(cxx_modules_import_std_export_no_std CXX)
 project(cxx_modules_import_std_export_no_std CXX)

+ 1 - 1
Tests/RunCMake/CXXModules/examples/import-std-export-no-std-install/CMakeLists.txt

@@ -1,5 +1,5 @@
 set(CMAKE_EXPERIMENTAL_CXX_IMPORT_STD
 set(CMAKE_EXPERIMENTAL_CXX_IMPORT_STD
-  "a9e1cf81-9932-4810-974b-6eccaf14e457")
+  "d0edc3af-4c50-42ea-a356-e2862fe7a444")
 
 
 cmake_minimum_required(VERSION 3.29)
 cmake_minimum_required(VERSION 3.29)
 project(cxx_modules_import_std_export_no_std CXX)
 project(cxx_modules_import_std_export_no_std CXX)

+ 1 - 1
Tests/RunCMake/CXXModules/examples/import-std-no-std-property/CMakeLists.txt

@@ -1,5 +1,5 @@
 set(CMAKE_EXPERIMENTAL_CXX_IMPORT_STD
 set(CMAKE_EXPERIMENTAL_CXX_IMPORT_STD
-  "a9e1cf81-9932-4810-974b-6eccaf14e457")
+  "d0edc3af-4c50-42ea-a356-e2862fe7a444")
 
 
 cmake_minimum_required(VERSION 3.29)
 cmake_minimum_required(VERSION 3.29)
 project(cxx_modules_import_std_no_std_property CXX)
 project(cxx_modules_import_std_no_std_property CXX)

+ 1 - 1
Tests/RunCMake/CXXModules/examples/import-std-not-in-export-build/CMakeLists.txt

@@ -1,5 +1,5 @@
 set(CMAKE_EXPERIMENTAL_CXX_IMPORT_STD
 set(CMAKE_EXPERIMENTAL_CXX_IMPORT_STD
-  "a9e1cf81-9932-4810-974b-6eccaf14e457")
+  "d0edc3af-4c50-42ea-a356-e2862fe7a444")
 
 
 cmake_minimum_required(VERSION 3.29)
 cmake_minimum_required(VERSION 3.29)
 project(cxx_modules_import_std_not_in_export CXX)
 project(cxx_modules_import_std_not_in_export CXX)

+ 1 - 1
Tests/RunCMake/CXXModules/examples/import-std-not-in-export-install/CMakeLists.txt

@@ -1,5 +1,5 @@
 set(CMAKE_EXPERIMENTAL_CXX_IMPORT_STD
 set(CMAKE_EXPERIMENTAL_CXX_IMPORT_STD
-  "a9e1cf81-9932-4810-974b-6eccaf14e457")
+  "d0edc3af-4c50-42ea-a356-e2862fe7a444")
 
 
 cmake_minimum_required(VERSION 3.29)
 cmake_minimum_required(VERSION 3.29)
 project(cxx_modules_import_std_not_in_export CXX)
 project(cxx_modules_import_std_not_in_export CXX)

+ 1 - 1
Tests/RunCMake/CXXModules/examples/import-std-transitive/CMakeLists.txt

@@ -1,5 +1,5 @@
 set(CMAKE_EXPERIMENTAL_CXX_IMPORT_STD
 set(CMAKE_EXPERIMENTAL_CXX_IMPORT_STD
-  "a9e1cf81-9932-4810-974b-6eccaf14e457")
+  "d0edc3af-4c50-42ea-a356-e2862fe7a444")
 
 
 cmake_minimum_required(VERSION 3.29)
 cmake_minimum_required(VERSION 3.29)
 
 

+ 1 - 1
Tests/RunCMake/CXXModules/examples/import-std/CMakeLists.txt

@@ -1,5 +1,5 @@
 set(CMAKE_EXPERIMENTAL_CXX_IMPORT_STD
 set(CMAKE_EXPERIMENTAL_CXX_IMPORT_STD
-  "a9e1cf81-9932-4810-974b-6eccaf14e457")
+  "d0edc3af-4c50-42ea-a356-e2862fe7a444")
 
 
 cmake_minimum_required(VERSION 3.29)
 cmake_minimum_required(VERSION 3.29)
 project(cxx_modules_import_std CXX)
 project(cxx_modules_import_std CXX)

+ 1 - 1
Tests/RunCMake/cmake_language/Experimental/CxxImportStd-set.cmake

@@ -1,5 +1,5 @@
 set(CMAKE_EXPERIMENTAL_CXX_IMPORT_STD
 set(CMAKE_EXPERIMENTAL_CXX_IMPORT_STD
-  "a9e1cf81-9932-4810-974b-6eccaf14e457")
+  "d0edc3af-4c50-42ea-a356-e2862fe7a444")
 
 
 cmake_language(GET_EXPERIMENTAL_FEATURE_ENABLED
 cmake_language(GET_EXPERIMENTAL_FEATURE_ENABLED
   "CxxImportStd"
   "CxxImportStd"