From acbada3df6908a56d7bfd9b94c8553823dc62636 Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Tue, 31 Dec 2024 01:36:52 +0100 Subject: Tests/RunCMake: handle C++26 support where needed (cherry picked from commit 2791b7564b (Tests/RunCMake: handle C++26 support where needed, 2024-12-31, v4.0.0-rc1~238^2~3)) --- Tests/RunCMake/CXXModules/examples/import-std-transitive/CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/Tests/RunCMake/CXXModules/examples/import-std-transitive/CMakeLists.txt b/Tests/RunCMake/CXXModules/examples/import-std-transitive/CMakeLists.txt index 2894d67..4d1d5df 100644 --- a/Tests/RunCMake/CXXModules/examples/import-std-transitive/CMakeLists.txt +++ b/Tests/RunCMake/CXXModules/examples/import-std-transitive/CMakeLists.txt @@ -6,6 +6,7 @@ cmake_minimum_required(VERSION 3.29) if (EXPORT_NO_STD) # Block making C++ `import std` targets. add_library(__CMAKE::CXX23 IMPORTED INTERFACE) + add_library(__CMAKE::CXX26 IMPORTED INTERFACE) endif () project(cxx_modules_import_std_transitive CXX) -- cgit v0.12 From 9cad48c6cbdc0c64f0695c474223acdccbf3211d Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Thu, 21 Nov 2024 04:56:41 -0500 Subject: gcc: support `import std` (cherry picked from commit a980dab9b1 (gcc: support `import std`, 2024-11-21)) --- Modules/CMakeDetermineCompilerId.cmake | 5 +- Modules/Compiler/GNU-CXX-CXXImportStd.cmake | 134 +++++++++++++++++++++ .../import-std-no-std-property-build-stdout.txt | 2 +- 3 files changed, 138 insertions(+), 3 deletions(-) create mode 100644 Modules/Compiler/GNU-CXX-CXXImportStd.cmake diff --git a/Modules/CMakeDetermineCompilerId.cmake b/Modules/CMakeDetermineCompilerId.cmake index 5e88076..e5dc8ea 100644 --- a/Modules/CMakeDetermineCompilerId.cmake +++ b/Modules/CMakeDetermineCompilerId.cmake @@ -315,8 +315,9 @@ function(CMAKE_DETERMINE_COMPILER_ID lang flagvar src) set(CMAKE_${lang}_STANDARD_LIBRARY "") if ("x${lang}" STREQUAL "xCXX" AND EXISTS "${CMAKE_CURRENT_FUNCTION_LIST_DIR}/${lang}-DetectStdlib.h" AND - "x${CMAKE_${lang}_COMPILER_ID}" STREQUAL "xClang" AND - "x${CMAKE_${lang}_COMPILER_FRONTEND_VARIANT}" STREQUAL "xGNU") + ("x${CMAKE_${lang}_COMPILER_ID}" STREQUAL "xClang" AND + "x${CMAKE_${lang}_COMPILER_FRONTEND_VARIANT}" STREQUAL "xGNU") OR + ("x${CMAKE_${lang}_COMPILER_ID}" STREQUAL "xGNU")) # See #20851 for a proper abstraction for this. execute_process( COMMAND "${CMAKE_${lang}_COMPILER}" diff --git a/Modules/Compiler/GNU-CXX-CXXImportStd.cmake b/Modules/Compiler/GNU-CXX-CXXImportStd.cmake new file mode 100644 index 0000000..965e25a --- /dev/null +++ b/Modules/Compiler/GNU-CXX-CXXImportStd.cmake @@ -0,0 +1,134 @@ +function (_cmake_cxx_import_std std variable) + if (NOT CMAKE_CXX_STANDARD_LIBRARY STREQUAL "libstdc++") + set("${variable}" + "set(CMAKE_CXX${std}_COMPILER_IMPORT_STD_NOT_FOUND_MESSAGE \"Only `libstdc++` is supported\")\n" + PARENT_SCOPE) + return () + endif () + + execute_process( + COMMAND + "${CMAKE_CXX_COMPILER}" + ${CMAKE_CXX_COMPILER_ID_ARG1} + -print-file-name=libstdc++.modules.json + OUTPUT_VARIABLE _gnu_libstdcxx_modules_json_file + ERROR_VARIABLE _gnu_libstdcxx_modules_json_file_err + RESULT_VARIABLE _gnu_libstdcxx_modules_json_file_res + OUTPUT_STRIP_TRAILING_WHITESPACE + ERROR_STRIP_TRAILING_WHITESPACE) + if (_gnu_libstdcxx_modules_json_file_res) + set("${variable}" + "set(CMAKE_CXX${std}_COMPILER_IMPORT_STD_NOT_FOUND_MESSAGE \"Could not find `libstdc++.modules.json` resource\")\n" + PARENT_SCOPE) + return () + endif () + + # Without this file, we do not have modules installed. + if (NOT EXISTS "${_gnu_libstdcxx_modules_json_file}") + set("${variable}" + "set(CMAKE_CXX${std}_COMPILER_IMPORT_STD_NOT_FOUND_MESSAGE \"`libstdc++.modules.json` resource does not exist\")\n" + PARENT_SCOPE) + return () + endif () + + file(READ "${_gnu_libstdcxx_modules_json_file}" _gnu_libstdcxx_modules_json) + string(JSON _gnu_modules_json_version GET "${_gnu_libstdcxx_modules_json}" "version") + string(JSON _gnu_modules_json_revision GET "${_gnu_libstdcxx_modules_json}" "revision") + # Require version 1. + if (NOT _gnu_modules_json_version EQUAL "1") + set("${variable}" + "set(CMAKE_CXX${std}_COMPILER_IMPORT_STD_NOT_FOUND_MESSAGE \"`libstdc++.modules.json` version ${_gnu_modules_json_version}.${_gnu_modules_json_revision} is not recognized\")\n" + PARENT_SCOPE) + return () + endif () + + string(JSON _gnu_modules_json_nmodules LENGTH "${_gnu_libstdcxx_modules_json}" "modules") + # Don't declare the target without any modules. + if (NOT _gnu_modules_json_nmodules) + set("${variable}" + "set(CMAKE_CXX${std}_COMPILER_IMPORT_STD_NOT_FOUND_MESSAGE \"`libstdc++.modules.json` does not list any available modules\")\n" + PARENT_SCOPE) + return () + endif () + + # Declare the target. + set(_gnu_libstdcxx_target "") + string(APPEND _gnu_libstdcxx_target + "add_library(__CMAKE::CXX${std} IMPORTED INTERFACE)\n") + string(APPEND _gnu_libstdcxx_target + "target_compile_features(__CMAKE::CXX${std} INTERFACE cxx_std_${std})\n") + + set(_gnu_modules_is_stdlib 0) + set(_gnu_modules_include_dirs_list "") + set(_gnu_modules_module_paths "") + get_filename_component(_gnu_modules_dir "${_gnu_libstdcxx_modules_json_file}" DIRECTORY) + + # Add module sources. + math(EXPR _gnu_modules_json_nmodules_range "${_gnu_modules_json_nmodules} - 1") + foreach (_gnu_modules_json_modules_idx RANGE 0 "${_gnu_modules_json_nmodules_range}") + string(JSON _gnu_modules_json_module GET "${_gnu_libstdcxx_modules_json}" "modules" "${_gnu_modules_json_modules_idx}") + + string(JSON _gnu_modules_json_module_source GET "${_gnu_modules_json_module}" "source-path") + string(JSON _gnu_modules_json_module_is_stdlib GET "${_gnu_modules_json_module}" "is-std-library") + string(JSON _gnu_modules_json_module_local_arguments ERROR_VARIABLE _gnu_modules_json_module_local_arguments_error GET "${_gnu_modules_json_module}" "local-arguments") + string(JSON _gnu_modules_json_module_nsystem_include_directories ERROR_VARIABLE _gnu_modules_json_module_nsystem_include_directories_error LENGTH "${_gnu_modules_json_module_local_arguments}" "system-include-directories") + + if (_gnu_modules_json_module_local_arguments_error STREQUAL "NOTFOUND") + set(_gnu_modules_json_module_local_arguments "") + endif () + if (_gnu_modules_json_module_nsystem_include_directories_error STREQUAL "NOTFOUND") + set(_gnu_modules_json_module_nsystem_include_directories 0) + endif () + + if (NOT IS_ABSOLUTE "${_gnu_modules_json_module_source}") + string(PREPEND _gnu_modules_json_module_source "${_gnu_modules_dir}/") + endif () + list(APPEND _gnu_modules_module_paths + "${_gnu_modules_json_module_source}") + + if (_gnu_modules_json_module_is_stdlib) + set(_gnu_modules_is_stdlib 1) + endif () + + if (_gnu_modules_json_module_nsystem_include_directories) + math(EXPR _gnu_modules_json_module_nsystem_include_directories_range "${_gnu_modules_json_module_nsystem_include_directories} - 1") + foreach (_gnu_modules_json_modules_system_include_directories_idx RANGE 0 "${_gnu_modules_json_module_nsystem_include_directories_range}") + string(JSON _gnu_modules_json_module_system_include_directory GET "${_gnu_modules_json_module_local_arguments}" "system-include-directories" "${_gnu_modules_json_modules_system_include_directories_idx}") + + if (NOT IS_ABSOLUTE "${_gnu_modules_json_module_system_include_directory}") + string(PREPEND _gnu_modules_json_module_system_include_directory "${_gnu_modules_dir}/") + endif () + list(APPEND _gnu_modules_include_dirs_list + "${_gnu_modules_json_module_system_include_directory}") + endforeach () + endif () + endforeach () + + # Split the paths into basedirs and module paths. + set(_gnu_modules_base_dirs_list "") + set(_gnu_modules_files "") + foreach (_gnu_modules_module_path IN LISTS _gnu_modules_module_paths) + get_filename_component(_gnu_module_dir "${_gnu_modules_module_path}" DIRECTORY) + + list(APPEND _gnu_modules_base_dirs_list + "${_gnu_module_dir}") + string(APPEND _gnu_modules_files + " \"${_gnu_modules_module_path}\"") + endforeach () + list(REMOVE_DUPLICATES _gnu_modules_base_dirs_list) + set(_gnu_modules_base_dirs "") + foreach (_gnu_modules_base_dir IN LISTS _gnu_modules_base_dirs_list) + string(APPEND _gnu_modules_base_dirs + " \"${_gnu_modules_base_dir}\"") + endforeach () + + # Create the file set for the modules. + string(APPEND _gnu_libstdcxx_target + "target_sources(__CMAKE::CXX${std} + INTERFACE + FILE_SET std TYPE CXX_MODULES + BASE_DIRS ${_gnu_modules_base_dirs} + FILES ${_gnu_modules_files})\n") + + set("${variable}" "${_gnu_libstdcxx_target}" PARENT_SCOPE) +endfunction () diff --git a/Tests/RunCMake/CXXModules/examples/import-std-no-std-property-build-stdout.txt b/Tests/RunCMake/CXXModules/examples/import-std-no-std-property-build-stdout.txt index d473333..a94f02a 100644 --- a/Tests/RunCMake/CXXModules/examples/import-std-no-std-property-build-stdout.txt +++ b/Tests/RunCMake/CXXModules/examples/import-std-no-std-property-build-stdout.txt @@ -1 +1 @@ -((Clang)?module 'std' not found|(MSVC)?could not find module 'std') +((GNU)?fatal error: unknown compiled module interface: no such module|(Clang)?module 'std' not found|(MSVC)?could not find module 'std') -- cgit v0.12 From ba5c9703b16e69f9b171abdb9b304d04628a9f0d Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Thu, 21 Nov 2024 04:58:11 -0500 Subject: Experimental: recycle the `import std` UUID Now that GCC is supported, update the feature UUID. (cherry picked from commit 469175c2e6 (Experimental: recycle the `import std` UUID, 2024-11-21)) --- Help/dev/experimental.rst | 2 +- Source/cmExperimental.cxx | 2 +- .../CXXModules/examples/import-std-export-no-std-build/CMakeLists.txt | 2 +- .../CXXModules/examples/import-std-export-no-std-install/CMakeLists.txt | 2 +- .../CXXModules/examples/import-std-no-std-property/CMakeLists.txt | 2 +- .../CXXModules/examples/import-std-not-in-export-build/CMakeLists.txt | 2 +- .../CXXModules/examples/import-std-not-in-export-install/CMakeLists.txt | 2 +- Tests/RunCMake/CXXModules/examples/import-std-transitive/CMakeLists.txt | 2 +- Tests/RunCMake/CXXModules/examples/import-std/CMakeLists.txt | 2 +- Tests/RunCMake/cmake_language/Experimental/CxxImportStd-set.cmake | 2 +- 10 files changed, 10 insertions(+), 10 deletions(-) diff --git a/Help/dev/experimental.rst b/Help/dev/experimental.rst index f5b9114..b401595 100644 --- a/Help/dev/experimental.rst +++ b/Help/dev/experimental.rst @@ -63,7 +63,7 @@ In order to activate support for ``import std`` in C++23 and newer targets, set * variable ``CMAKE_EXPERIMENTAL_CXX_IMPORT_STD`` to -* value ``0e5b6991-d74f-4b3d-a41c-cf096e0b2508``. +* value ``a9e1cf81-9932-4810-974b-6eccaf14e457``. 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 diff --git a/Source/cmExperimental.cxx b/Source/cmExperimental.cxx index 913db87..053579b 100644 --- a/Source/cmExperimental.cxx +++ b/Source/cmExperimental.cxx @@ -39,7 +39,7 @@ cmExperimental::FeatureData LookupTable[] = { false }, // CxxImportStd { "CxxImportStd", - "0e5b6991-d74f-4b3d-a41c-cf096e0b2508", + "a9e1cf81-9932-4810-974b-6eccaf14e457", "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.", diff --git a/Tests/RunCMake/CXXModules/examples/import-std-export-no-std-build/CMakeLists.txt b/Tests/RunCMake/CXXModules/examples/import-std-export-no-std-build/CMakeLists.txt index 89350ef..5d41b0e 100644 --- a/Tests/RunCMake/CXXModules/examples/import-std-export-no-std-build/CMakeLists.txt +++ b/Tests/RunCMake/CXXModules/examples/import-std-export-no-std-build/CMakeLists.txt @@ -1,5 +1,5 @@ set(CMAKE_EXPERIMENTAL_CXX_IMPORT_STD - "0e5b6991-d74f-4b3d-a41c-cf096e0b2508") + "a9e1cf81-9932-4810-974b-6eccaf14e457") cmake_minimum_required(VERSION 3.29) project(cxx_modules_import_std_export_no_std CXX) diff --git a/Tests/RunCMake/CXXModules/examples/import-std-export-no-std-install/CMakeLists.txt b/Tests/RunCMake/CXXModules/examples/import-std-export-no-std-install/CMakeLists.txt index 62d9d91..fccb8b4 100644 --- a/Tests/RunCMake/CXXModules/examples/import-std-export-no-std-install/CMakeLists.txt +++ b/Tests/RunCMake/CXXModules/examples/import-std-export-no-std-install/CMakeLists.txt @@ -1,5 +1,5 @@ set(CMAKE_EXPERIMENTAL_CXX_IMPORT_STD - "0e5b6991-d74f-4b3d-a41c-cf096e0b2508") + "a9e1cf81-9932-4810-974b-6eccaf14e457") cmake_minimum_required(VERSION 3.29) project(cxx_modules_import_std_export_no_std CXX) diff --git a/Tests/RunCMake/CXXModules/examples/import-std-no-std-property/CMakeLists.txt b/Tests/RunCMake/CXXModules/examples/import-std-no-std-property/CMakeLists.txt index a605e95..f21da1e 100644 --- a/Tests/RunCMake/CXXModules/examples/import-std-no-std-property/CMakeLists.txt +++ b/Tests/RunCMake/CXXModules/examples/import-std-no-std-property/CMakeLists.txt @@ -1,5 +1,5 @@ set(CMAKE_EXPERIMENTAL_CXX_IMPORT_STD - "0e5b6991-d74f-4b3d-a41c-cf096e0b2508") + "a9e1cf81-9932-4810-974b-6eccaf14e457") cmake_minimum_required(VERSION 3.29) project(cxx_modules_import_std_no_std_property CXX) diff --git a/Tests/RunCMake/CXXModules/examples/import-std-not-in-export-build/CMakeLists.txt b/Tests/RunCMake/CXXModules/examples/import-std-not-in-export-build/CMakeLists.txt index 3112002..e3e11d1 100644 --- a/Tests/RunCMake/CXXModules/examples/import-std-not-in-export-build/CMakeLists.txt +++ b/Tests/RunCMake/CXXModules/examples/import-std-not-in-export-build/CMakeLists.txt @@ -1,5 +1,5 @@ set(CMAKE_EXPERIMENTAL_CXX_IMPORT_STD - "0e5b6991-d74f-4b3d-a41c-cf096e0b2508") + "a9e1cf81-9932-4810-974b-6eccaf14e457") cmake_minimum_required(VERSION 3.29) project(cxx_modules_import_std_not_in_export CXX) diff --git a/Tests/RunCMake/CXXModules/examples/import-std-not-in-export-install/CMakeLists.txt b/Tests/RunCMake/CXXModules/examples/import-std-not-in-export-install/CMakeLists.txt index 788ea84..53ef333 100644 --- a/Tests/RunCMake/CXXModules/examples/import-std-not-in-export-install/CMakeLists.txt +++ b/Tests/RunCMake/CXXModules/examples/import-std-not-in-export-install/CMakeLists.txt @@ -1,5 +1,5 @@ set(CMAKE_EXPERIMENTAL_CXX_IMPORT_STD - "0e5b6991-d74f-4b3d-a41c-cf096e0b2508") + "a9e1cf81-9932-4810-974b-6eccaf14e457") cmake_minimum_required(VERSION 3.29) project(cxx_modules_import_std_not_in_export CXX) diff --git a/Tests/RunCMake/CXXModules/examples/import-std-transitive/CMakeLists.txt b/Tests/RunCMake/CXXModules/examples/import-std-transitive/CMakeLists.txt index 4d1d5df..2f12662 100644 --- a/Tests/RunCMake/CXXModules/examples/import-std-transitive/CMakeLists.txt +++ b/Tests/RunCMake/CXXModules/examples/import-std-transitive/CMakeLists.txt @@ -1,5 +1,5 @@ set(CMAKE_EXPERIMENTAL_CXX_IMPORT_STD - "0e5b6991-d74f-4b3d-a41c-cf096e0b2508") + "a9e1cf81-9932-4810-974b-6eccaf14e457") cmake_minimum_required(VERSION 3.29) diff --git a/Tests/RunCMake/CXXModules/examples/import-std/CMakeLists.txt b/Tests/RunCMake/CXXModules/examples/import-std/CMakeLists.txt index bffcd66..95b6636 100644 --- a/Tests/RunCMake/CXXModules/examples/import-std/CMakeLists.txt +++ b/Tests/RunCMake/CXXModules/examples/import-std/CMakeLists.txt @@ -1,5 +1,5 @@ set(CMAKE_EXPERIMENTAL_CXX_IMPORT_STD - "0e5b6991-d74f-4b3d-a41c-cf096e0b2508") + "a9e1cf81-9932-4810-974b-6eccaf14e457") cmake_minimum_required(VERSION 3.29) project(cxx_modules_import_std CXX) diff --git a/Tests/RunCMake/cmake_language/Experimental/CxxImportStd-set.cmake b/Tests/RunCMake/cmake_language/Experimental/CxxImportStd-set.cmake index a002297..4a9edf4 100644 --- a/Tests/RunCMake/cmake_language/Experimental/CxxImportStd-set.cmake +++ b/Tests/RunCMake/cmake_language/Experimental/CxxImportStd-set.cmake @@ -1,5 +1,5 @@ set(CMAKE_EXPERIMENTAL_CXX_IMPORT_STD - "0e5b6991-d74f-4b3d-a41c-cf096e0b2508") + "a9e1cf81-9932-4810-974b-6eccaf14e457") cmake_language(GET_EXPERIMENTAL_FEATURE_ENABLED "CxxImportStd" -- cgit v0.12 From c88f3ea1e4c1cc17a54e68637b0bd98febc45d76 Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Wed, 30 Apr 2025 13:47:27 +0200 Subject: Clang/CXXImportStd: support `-stdlib=libstdc++` Fedora 42 ships `clang` with `libstdc++` as the default. Detect and support `import std;` in this configuration. --- Help/manual/cmake-cxxmodules.7.rst | 2 +- Modules/Compiler/Clang-CXX-CXXImportStd.cmake | 51 +++++++++++++++++---------- 2 files changed, 33 insertions(+), 20 deletions(-) diff --git a/Help/manual/cmake-cxxmodules.7.rst b/Help/manual/cmake-cxxmodules.7.rst index 201a415..1387e24 100644 --- a/Help/manual/cmake-cxxmodules.7.rst +++ b/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 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) diff --git a/Modules/Compiler/Clang-CXX-CXXImportStd.cmake b/Modules/Compiler/Clang-CXX-CXXImportStd.cmake index f58f17e..5330eb1 100644 --- a/Modules/Compiler/Clang-CXX-CXXImportStd.cmake +++ b/Modules/Compiler/Clang-CXX-CXXImportStd.cmake @@ -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 (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 () # Split the paths into basedirs and module paths. -- cgit v0.12 From 802f261d629e5f51213385716824a0423d063624 Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Wed, 30 Apr 2025 13:48:13 +0200 Subject: experimental/CXXModules: recycle the UUID Now that `clang -stdlib=libstdc++` is supported. (cherry picked from commit 52e2785018 (experimental/CXXModules: recycle the UUID, 2025-04-30)) --- Help/dev/experimental.rst | 2 +- Source/cmExperimental.cxx | 2 +- .../CXXModules/examples/import-std-export-no-std-build/CMakeLists.txt | 2 +- .../CXXModules/examples/import-std-export-no-std-install/CMakeLists.txt | 2 +- .../CXXModules/examples/import-std-no-std-property/CMakeLists.txt | 2 +- .../CXXModules/examples/import-std-not-in-export-build/CMakeLists.txt | 2 +- .../CXXModules/examples/import-std-not-in-export-install/CMakeLists.txt | 2 +- Tests/RunCMake/CXXModules/examples/import-std-transitive/CMakeLists.txt | 2 +- Tests/RunCMake/CXXModules/examples/import-std/CMakeLists.txt | 2 +- Tests/RunCMake/cmake_language/Experimental/CxxImportStd-set.cmake | 2 +- 10 files changed, 10 insertions(+), 10 deletions(-) diff --git a/Help/dev/experimental.rst b/Help/dev/experimental.rst index b401595..5d4c107 100644 --- a/Help/dev/experimental.rst +++ b/Help/dev/experimental.rst @@ -63,7 +63,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 diff --git a/Source/cmExperimental.cxx b/Source/cmExperimental.cxx index 053579b..acc64da 100644 --- a/Source/cmExperimental.cxx +++ b/Source/cmExperimental.cxx @@ -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.", diff --git a/Tests/RunCMake/CXXModules/examples/import-std-export-no-std-build/CMakeLists.txt b/Tests/RunCMake/CXXModules/examples/import-std-export-no-std-build/CMakeLists.txt index 5d41b0e..3dfc927 100644 --- a/Tests/RunCMake/CXXModules/examples/import-std-export-no-std-build/CMakeLists.txt +++ b/Tests/RunCMake/CXXModules/examples/import-std-export-no-std-build/CMakeLists.txt @@ -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) diff --git a/Tests/RunCMake/CXXModules/examples/import-std-export-no-std-install/CMakeLists.txt b/Tests/RunCMake/CXXModules/examples/import-std-export-no-std-install/CMakeLists.txt index fccb8b4..9b25973 100644 --- a/Tests/RunCMake/CXXModules/examples/import-std-export-no-std-install/CMakeLists.txt +++ b/Tests/RunCMake/CXXModules/examples/import-std-export-no-std-install/CMakeLists.txt @@ -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) diff --git a/Tests/RunCMake/CXXModules/examples/import-std-no-std-property/CMakeLists.txt b/Tests/RunCMake/CXXModules/examples/import-std-no-std-property/CMakeLists.txt index f21da1e..52d76f0 100644 --- a/Tests/RunCMake/CXXModules/examples/import-std-no-std-property/CMakeLists.txt +++ b/Tests/RunCMake/CXXModules/examples/import-std-no-std-property/CMakeLists.txt @@ -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) diff --git a/Tests/RunCMake/CXXModules/examples/import-std-not-in-export-build/CMakeLists.txt b/Tests/RunCMake/CXXModules/examples/import-std-not-in-export-build/CMakeLists.txt index e3e11d1..204a9db 100644 --- a/Tests/RunCMake/CXXModules/examples/import-std-not-in-export-build/CMakeLists.txt +++ b/Tests/RunCMake/CXXModules/examples/import-std-not-in-export-build/CMakeLists.txt @@ -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) diff --git a/Tests/RunCMake/CXXModules/examples/import-std-not-in-export-install/CMakeLists.txt b/Tests/RunCMake/CXXModules/examples/import-std-not-in-export-install/CMakeLists.txt index 53ef333..83fc385 100644 --- a/Tests/RunCMake/CXXModules/examples/import-std-not-in-export-install/CMakeLists.txt +++ b/Tests/RunCMake/CXXModules/examples/import-std-not-in-export-install/CMakeLists.txt @@ -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) diff --git a/Tests/RunCMake/CXXModules/examples/import-std-transitive/CMakeLists.txt b/Tests/RunCMake/CXXModules/examples/import-std-transitive/CMakeLists.txt index 2f12662..943bf8f 100644 --- a/Tests/RunCMake/CXXModules/examples/import-std-transitive/CMakeLists.txt +++ b/Tests/RunCMake/CXXModules/examples/import-std-transitive/CMakeLists.txt @@ -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) diff --git a/Tests/RunCMake/CXXModules/examples/import-std/CMakeLists.txt b/Tests/RunCMake/CXXModules/examples/import-std/CMakeLists.txt index 95b6636..fd15455 100644 --- a/Tests/RunCMake/CXXModules/examples/import-std/CMakeLists.txt +++ b/Tests/RunCMake/CXXModules/examples/import-std/CMakeLists.txt @@ -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) diff --git a/Tests/RunCMake/cmake_language/Experimental/CxxImportStd-set.cmake b/Tests/RunCMake/cmake_language/Experimental/CxxImportStd-set.cmake index 4a9edf4..6cd0f89 100644 --- a/Tests/RunCMake/cmake_language/Experimental/CxxImportStd-set.cmake +++ b/Tests/RunCMake/cmake_language/Experimental/CxxImportStd-set.cmake @@ -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" -- cgit v0.12