diff --git a/Help/dev/experimental.rst b/Help/dev/experimental.rst index ad87217f73..3d528717bb 100644 --- a/Help/dev/experimental.rst +++ b/Help/dev/experimental.rst @@ -59,6 +59,28 @@ When activated, this experimental feature provides the following: .. _CPS: https://cps-org.github.io/cps/ .. |CPS| replace:: Common Package Specification +C++ ``import std`` support +========================== + +In order to activate support for ``import std`` in C++23 and newer targets, +set + +* variable ``CMAKE_EXPERIMENTAL_CXX_IMPORT_STD`` to +* value ``451f2fe2-a8a2-47c3-bc32-94786d8fc91b``. + +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 +experimenting. It must be set before the ``CXX`` toolchain is discovered by +CMake, usually as part of a ``project()`` call. + +When activated, this experimental feature provides the following: + +* The ``CXX_MODULE_STD`` target property and its initializing variable + ``CMAKE_CXX_MODULE_STD``. + +* Targets with the property set to a true value and at least ``cxx_std_23`` + may use ``import std;`` in any scanned C++ source file. + Build database support ====================== diff --git a/Help/manual/cmake-cxxmodules.7.rst b/Help/manual/cmake-cxxmodules.7.rst index 4bab66c46b..d26c6414d1 100644 --- a/Help/manual/cmake-cxxmodules.7.rst +++ b/Help/manual/cmake-cxxmodules.7.rst @@ -75,8 +75,6 @@ modules includes: ``import std`` Support ====================== -.. versionadded:: 4.3 - Support for ``import std`` is limited to the following toolchain and standard library combinations: @@ -98,6 +96,12 @@ Additionally, only the :ref:`Ninja Generators` currently support ``import std`` at this time because :ref:`Visual Studio Generators` do not support building :term:`BMIs ` for ``IMPORTED`` targets. +.. note:: + + This support is provided only when experimental support for + ``import std`` has been enabled by the + ``CMAKE_EXPERIMENTAL_CXX_IMPORT_STD`` gate. + Generator Support ================= diff --git a/Help/prop_tgt/CXX_MODULE_STD.rst b/Help/prop_tgt/CXX_MODULE_STD.rst index eb798a484f..3c9bb2311e 100644 --- a/Help/prop_tgt/CXX_MODULE_STD.rst +++ b/Help/prop_tgt/CXX_MODULE_STD.rst @@ -1,11 +1,16 @@ CXX_MODULE_STD -------------- -.. versionadded:: 4.3 +.. versionadded:: 3.30 ``CXX_MODULE_STD`` is a boolean specifying whether the target may use ``import std;`` its C++ sources or not. +.. note:: + + This setting is meaningful only when experimental support for ``import + std;`` has been enabled by the ``CMAKE_EXPERIMENTAL_CXX_IMPORT_STD`` gate. + When this property is explicitly set to ``ON``, CMake will add a dependency to a target which provides the C++ standard library's modules for the C++ standard applied to the target. This target is only applicable within the diff --git a/Help/release/4.3.rst b/Help/release/4.3.rst index 9db39e10c7..52d12fa77c 100644 --- a/Help/release/4.3.rst +++ b/Help/release/4.3.rst @@ -143,18 +143,6 @@ Variables to support per-language link flags for all target types. See policy :policy:`CMP0210`. -* The :variable:`CMAKE_CXX_MODULE_STD` variable and corresponding - :prop_tgt:`CXX_MODULE_STD` target property were added to control the - availability of ``import std`` for C++ targets. - -* The read-only :variable:`CMAKE_CXX_COMPILER_IMPORT_STD` variable was added - to list the C++ standard levels for which ``import std`` is available on - the current toolchain. - -* The :variable:`CMAKE_CXX_STDLIB_MODULES_JSON` variable was added to specify - an ``import std`` module metadata file instead of relying on automatic - detection from the C++ compiler. - * The :variable:`CMAKE_VERIFY_PRIVATE_HEADER_SETS` variable and corresponding :prop_tgt:`VERIFY_PRIVATE_HEADER_SETS` target property were added to enable build rules that verify all headers in private file sets can be used diff --git a/Help/variable/CMAKE_CXX_COMPILER_IMPORT_STD.rst b/Help/variable/CMAKE_CXX_COMPILER_IMPORT_STD.rst index 02ed5d4fcd..6605f1a094 100644 --- a/Help/variable/CMAKE_CXX_COMPILER_IMPORT_STD.rst +++ b/Help/variable/CMAKE_CXX_COMPILER_IMPORT_STD.rst @@ -1,9 +1,14 @@ CMAKE_CXX_COMPILER_IMPORT_STD ----------------------------- -.. versionadded:: 4.3 +.. versionadded:: 3.30 A list of C++ standard levels for which ``import std`` support exists for the current C++ toolchain. Support for C++\ may be detected using a `` IN_LIST CMAKE_CXX_COMPILER_IMPORT_STD`` predicate with the :command:`if` command. + +.. note:: + + This variable is meaningful only when experimental support for ``import + std;`` has been enabled by the ``CMAKE_EXPERIMENTAL_CXX_IMPORT_STD`` gate. diff --git a/Help/variable/CMAKE_CXX_MODULE_STD.rst b/Help/variable/CMAKE_CXX_MODULE_STD.rst index 608d6d6051..057272bbe5 100644 --- a/Help/variable/CMAKE_CXX_MODULE_STD.rst +++ b/Help/variable/CMAKE_CXX_MODULE_STD.rst @@ -1,10 +1,15 @@ CMAKE_CXX_MODULE_STD -------------------- -.. versionadded:: 4.3 +.. versionadded:: 3.30 Whether to add utility targets as dependencies to targets with at least ``cxx_std_23`` or not. +.. note:: + + This setting is meaningful only when experimental support for ``import + std;`` has been enabled by the ``CMAKE_EXPERIMENTAL_CXX_IMPORT_STD`` gate. + This variable is used to initialize the :prop_tgt:`CXX_MODULE_STD` property on all targets. See that target property for additional information. diff --git a/Help/variable/CMAKE_CXX_STDLIB_MODULES_JSON.rst b/Help/variable/CMAKE_CXX_STDLIB_MODULES_JSON.rst index 2cd6607730..134e8d60bc 100644 --- a/Help/variable/CMAKE_CXX_STDLIB_MODULES_JSON.rst +++ b/Help/variable/CMAKE_CXX_STDLIB_MODULES_JSON.rst @@ -1,7 +1,7 @@ CMAKE_CXX_STDLIB_MODULES_JSON ----------------------------- -.. versionadded:: 4.3 +.. versionadded:: 4.2 This variable may be used to set the path to a metadata file for CMake to understand how the ``import std`` target for the active CXX compiler should be diff --git a/Modules/Compiler/CMakeCommonCompilerMacros.cmake b/Modules/Compiler/CMakeCommonCompilerMacros.cmake index 2e0ce5d4f2..a97fe0fe54 100644 --- a/Modules/Compiler/CMakeCommonCompilerMacros.cmake +++ b/Modules/Compiler/CMakeCommonCompilerMacros.cmake @@ -220,6 +220,17 @@ function(cmake_cxx_find_modules_json) return () endif () + # Check the experimental flag. Check it here to avoid triggering warnings in + # situations that don't support the feature anyways. + set(_cmake_supported_import_std_experimental "") + cmake_language(GET_EXPERIMENTAL_FEATURE_ENABLED + "CxxImportStd" + _cmake_supported_import_std_experimental) + if (NOT _cmake_supported_import_std_experimental) + set(CMAKE_CXX_COMPILER_IMPORT_STD_ERROR_MESSAGE "Experimental `import std` support not enabled when detecting toolchain; it must be set before `CXX` is enabled (usually a `project()` call)" PARENT_SCOPE) + return () + endif () + _cmake_cxx_find_modules_json() set(CMAKE_CXX_COMPILER_IMPORT_STD_ERROR_MESSAGE "${CMAKE_CXX_COMPILER_IMPORT_STD_ERROR_MESSAGE}" PARENT_SCOPE) set(CMAKE_CXX_STDLIB_MODULES_JSON "${CMAKE_CXX_STDLIB_MODULES_JSON}" PARENT_SCOPE) diff --git a/Source/cmExperimental.cxx b/Source/cmExperimental.cxx index 3d022d70ff..acf8e5c276 100644 --- a/Source/cmExperimental.cxx +++ b/Source/cmExperimental.cxx @@ -29,6 +29,14 @@ cmExperimental::FeatureData const LookupTable[] = { "only for experimentation and feedback to CMake developers.", {}, cmExperimental::TryCompileCondition::Always }, + // CxxImportStd + { "CxxImportStd", + "451f2fe2-a8a2-47c3-bc32-94786d8fc91b", + "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.", + {}, + cmExperimental::TryCompileCondition::Always }, // MappedPackageInfo { "MappedPackageInfo", "ababa1b5-7099-495f-a9cd-e22d38f274f2", diff --git a/Source/cmExperimental.h b/Source/cmExperimental.h index 79dbd5fdf2..dcd99ebf99 100644 --- a/Source/cmExperimental.h +++ b/Source/cmExperimental.h @@ -18,6 +18,7 @@ public: enum class Feature { ExportPackageDependencies, + CxxImportStd, MappedPackageInfo, ExportBuildDatabase, GenerateSbom, diff --git a/Source/cmGeneratorTarget.cxx b/Source/cmGeneratorTarget.cxx index 4799c78556..2bc13d9534 100644 --- a/Source/cmGeneratorTarget.cxx +++ b/Source/cmGeneratorTarget.cxx @@ -5306,6 +5306,18 @@ bool cmGeneratorTarget::ApplyCXXStdTargets() ">:", cxxTargetName, ">>")); } + // Check the experimental feature here. A toolchain may have + // skipped the check in the toolchain preparation logic. + if (!cmExperimental::HasSupportEnabled( + *this->Makefile, cmExperimental::Feature::CxxImportStd)) { + this->Makefile->IssueMessage( + MessageType::FATAL_ERROR, + "Experimental `import std` support not enabled when detecting " + "toolchain; it must be set before `CXX` is enabled (usually a " + "`project()` call)."); + return false; + } + return true; } diff --git a/Tests/RunCMake/CXXModules/NoCXX23TargetRequired-stderr.txt b/Tests/RunCMake/CXXModules/NoCXX23TargetRequired-stderr.txt index b61b42f68e..48a8b9480f 100644 --- a/Tests/RunCMake/CXXModules/NoCXX23TargetRequired-stderr.txt +++ b/Tests/RunCMake/CXXModules/NoCXX23TargetRequired-stderr.txt @@ -2,7 +2,7 @@ CMake Error in CMakeLists\.txt: The "CXX_MODULE_STD" property on target "nocxx23target" requires toolchain support, but it was not provided. Reason: - (Toolchain does not support discovering module metadata|Unsupported generator: [^\n]*|Only `libc\+\+` and `libstdc\+\+` are supported) + (Toolchain does not support discovering module metadata|Experimental `import std` support not enabled when detecting toolchain; it must be set before `CXX` is enabled \(usually a `project\(\)` call\)|Unsupported generator: [^\n]*) CMake Generate step failed\. Build files cannot be regenerated correctly\. diff --git a/Tests/RunCMake/CXXModules/NoCXX26TargetRequired-stderr.txt b/Tests/RunCMake/CXXModules/NoCXX26TargetRequired-stderr.txt index 5a91de10ad..b45b04e0d2 100644 --- a/Tests/RunCMake/CXXModules/NoCXX26TargetRequired-stderr.txt +++ b/Tests/RunCMake/CXXModules/NoCXX26TargetRequired-stderr.txt @@ -2,7 +2,7 @@ CMake Error in CMakeLists\.txt: The "CXX_MODULE_STD" property on target "nocxx26target" requires toolchain support, but it was not provided. Reason: - (Toolchain does not support discovering module metadata|Unsupported generator: [^\n]*|Only `libc\+\+` and `libstdc\+\+` are supported) + (Toolchain does not support discovering module metadata|Experimental `import std` support not enabled when detecting toolchain; it must be set before `CXX` is enabled \(usually a `project\(\)` call\)|Unsupported generator: [^\n]*) CMake Generate step failed\. Build files cannot be regenerated correctly\. diff --git a/Tests/RunCMake/CXXModulesCompile/imp-std-exp-no-std-build-stderr.txt b/Tests/RunCMake/CXXModulesCompile/imp-std-exp-no-std-build-stderr.txt new file mode 100644 index 0000000000..f7d285878e --- /dev/null +++ b/Tests/RunCMake/CXXModulesCompile/imp-std-exp-no-std-build-stderr.txt @@ -0,0 +1,8 @@ +CMake Warning \(dev\) at .*/Modules/Compiler/CMakeCommonCompilerMacros\.cmake:[0-9]* \(cmake_language\): + CMake's support for `import std;` in C\+\+23 and newer is experimental\. It + is meant only for experimentation and feedback to CMake developers\. +Call Stack \(most recent call first\): + .*/Modules/CMakeDetermineCompilerSupport\.cmake:[0-9]* \(cmake_cxx_find_modules_json\) + .*/Modules/CMakeTestCXXCompiler\.cmake:[0-9]* \(CMAKE_DETERMINE_COMPILER_SUPPORT\) + CMakeLists\.txt:[0-9]* \(project\) +This warning is for project developers\. Use -Wno-dev to suppress it\. diff --git a/Tests/RunCMake/CXXModulesCompile/imp-std-exp-no-std-build/CMakeLists.txt b/Tests/RunCMake/CXXModulesCompile/imp-std-exp-no-std-build/CMakeLists.txt index 0a4c41d579..e981f3b65f 100644 --- a/Tests/RunCMake/CXXModulesCompile/imp-std-exp-no-std-build/CMakeLists.txt +++ b/Tests/RunCMake/CXXModulesCompile/imp-std-exp-no-std-build/CMakeLists.txt @@ -1,3 +1,6 @@ +set(CMAKE_EXPERIMENTAL_CXX_IMPORT_STD + "451f2fe2-a8a2-47c3-bc32-94786d8fc91b") + cmake_minimum_required(VERSION 3.29) project(cxx_modules_import_std_export_no_std CXX) diff --git a/Tests/RunCMake/CXXModulesCompile/imp-std-exp-no-std-install-stderr.txt b/Tests/RunCMake/CXXModulesCompile/imp-std-exp-no-std-install-stderr.txt new file mode 100644 index 0000000000..f7d285878e --- /dev/null +++ b/Tests/RunCMake/CXXModulesCompile/imp-std-exp-no-std-install-stderr.txt @@ -0,0 +1,8 @@ +CMake Warning \(dev\) at .*/Modules/Compiler/CMakeCommonCompilerMacros\.cmake:[0-9]* \(cmake_language\): + CMake's support for `import std;` in C\+\+23 and newer is experimental\. It + is meant only for experimentation and feedback to CMake developers\. +Call Stack \(most recent call first\): + .*/Modules/CMakeDetermineCompilerSupport\.cmake:[0-9]* \(cmake_cxx_find_modules_json\) + .*/Modules/CMakeTestCXXCompiler\.cmake:[0-9]* \(CMAKE_DETERMINE_COMPILER_SUPPORT\) + CMakeLists\.txt:[0-9]* \(project\) +This warning is for project developers\. Use -Wno-dev to suppress it\. diff --git a/Tests/RunCMake/CXXModulesCompile/imp-std-exp-no-std-install/CMakeLists.txt b/Tests/RunCMake/CXXModulesCompile/imp-std-exp-no-std-install/CMakeLists.txt index 69edbb5870..b63c814730 100644 --- a/Tests/RunCMake/CXXModulesCompile/imp-std-exp-no-std-install/CMakeLists.txt +++ b/Tests/RunCMake/CXXModulesCompile/imp-std-exp-no-std-install/CMakeLists.txt @@ -1,3 +1,6 @@ +set(CMAKE_EXPERIMENTAL_CXX_IMPORT_STD + "451f2fe2-a8a2-47c3-bc32-94786d8fc91b") + cmake_minimum_required(VERSION 3.29) project(cxx_modules_import_std_export_no_std CXX) diff --git a/Tests/RunCMake/CXXModulesCompile/imp-std-no-std-prop-stderr.txt b/Tests/RunCMake/CXXModulesCompile/imp-std-no-std-prop-stderr.txt new file mode 100644 index 0000000000..f7d285878e --- /dev/null +++ b/Tests/RunCMake/CXXModulesCompile/imp-std-no-std-prop-stderr.txt @@ -0,0 +1,8 @@ +CMake Warning \(dev\) at .*/Modules/Compiler/CMakeCommonCompilerMacros\.cmake:[0-9]* \(cmake_language\): + CMake's support for `import std;` in C\+\+23 and newer is experimental\. It + is meant only for experimentation and feedback to CMake developers\. +Call Stack \(most recent call first\): + .*/Modules/CMakeDetermineCompilerSupport\.cmake:[0-9]* \(cmake_cxx_find_modules_json\) + .*/Modules/CMakeTestCXXCompiler\.cmake:[0-9]* \(CMAKE_DETERMINE_COMPILER_SUPPORT\) + CMakeLists\.txt:[0-9]* \(project\) +This warning is for project developers\. Use -Wno-dev to suppress it\. diff --git a/Tests/RunCMake/CXXModulesCompile/imp-std-no-std-prop/CMakeLists.txt b/Tests/RunCMake/CXXModulesCompile/imp-std-no-std-prop/CMakeLists.txt index 4ec4e36497..12dc294607 100644 --- a/Tests/RunCMake/CXXModulesCompile/imp-std-no-std-prop/CMakeLists.txt +++ b/Tests/RunCMake/CXXModulesCompile/imp-std-no-std-prop/CMakeLists.txt @@ -1,3 +1,6 @@ +set(CMAKE_EXPERIMENTAL_CXX_IMPORT_STD + "451f2fe2-a8a2-47c3-bc32-94786d8fc91b") + cmake_minimum_required(VERSION 3.29) project(cxx_modules_import_std_no_std_property CXX) diff --git a/Tests/RunCMake/CXXModulesCompile/imp-std-not-in-exp-build-stderr.txt b/Tests/RunCMake/CXXModulesCompile/imp-std-not-in-exp-build-stderr.txt new file mode 100644 index 0000000000..f7d285878e --- /dev/null +++ b/Tests/RunCMake/CXXModulesCompile/imp-std-not-in-exp-build-stderr.txt @@ -0,0 +1,8 @@ +CMake Warning \(dev\) at .*/Modules/Compiler/CMakeCommonCompilerMacros\.cmake:[0-9]* \(cmake_language\): + CMake's support for `import std;` in C\+\+23 and newer is experimental\. It + is meant only for experimentation and feedback to CMake developers\. +Call Stack \(most recent call first\): + .*/Modules/CMakeDetermineCompilerSupport\.cmake:[0-9]* \(cmake_cxx_find_modules_json\) + .*/Modules/CMakeTestCXXCompiler\.cmake:[0-9]* \(CMAKE_DETERMINE_COMPILER_SUPPORT\) + CMakeLists\.txt:[0-9]* \(project\) +This warning is for project developers\. Use -Wno-dev to suppress it\. diff --git a/Tests/RunCMake/CXXModulesCompile/imp-std-not-in-exp-build/CMakeLists.txt b/Tests/RunCMake/CXXModulesCompile/imp-std-not-in-exp-build/CMakeLists.txt index b7ab2797f4..7b7ca316c1 100644 --- a/Tests/RunCMake/CXXModulesCompile/imp-std-not-in-exp-build/CMakeLists.txt +++ b/Tests/RunCMake/CXXModulesCompile/imp-std-not-in-exp-build/CMakeLists.txt @@ -1,3 +1,6 @@ +set(CMAKE_EXPERIMENTAL_CXX_IMPORT_STD + "451f2fe2-a8a2-47c3-bc32-94786d8fc91b") + cmake_minimum_required(VERSION 3.29) project(cxx_modules_import_std_not_in_export CXX) diff --git a/Tests/RunCMake/CXXModulesCompile/imp-std-not-in-exp-install-stderr.txt b/Tests/RunCMake/CXXModulesCompile/imp-std-not-in-exp-install-stderr.txt new file mode 100644 index 0000000000..f7d285878e --- /dev/null +++ b/Tests/RunCMake/CXXModulesCompile/imp-std-not-in-exp-install-stderr.txt @@ -0,0 +1,8 @@ +CMake Warning \(dev\) at .*/Modules/Compiler/CMakeCommonCompilerMacros\.cmake:[0-9]* \(cmake_language\): + CMake's support for `import std;` in C\+\+23 and newer is experimental\. It + is meant only for experimentation and feedback to CMake developers\. +Call Stack \(most recent call first\): + .*/Modules/CMakeDetermineCompilerSupport\.cmake:[0-9]* \(cmake_cxx_find_modules_json\) + .*/Modules/CMakeTestCXXCompiler\.cmake:[0-9]* \(CMAKE_DETERMINE_COMPILER_SUPPORT\) + CMakeLists\.txt:[0-9]* \(project\) +This warning is for project developers\. Use -Wno-dev to suppress it\. diff --git a/Tests/RunCMake/CXXModulesCompile/imp-std-not-in-exp-install/CMakeLists.txt b/Tests/RunCMake/CXXModulesCompile/imp-std-not-in-exp-install/CMakeLists.txt index 8b9295d21a..b0587c90ae 100644 --- a/Tests/RunCMake/CXXModulesCompile/imp-std-not-in-exp-install/CMakeLists.txt +++ b/Tests/RunCMake/CXXModulesCompile/imp-std-not-in-exp-install/CMakeLists.txt @@ -1,3 +1,6 @@ +set(CMAKE_EXPERIMENTAL_CXX_IMPORT_STD + "451f2fe2-a8a2-47c3-bc32-94786d8fc91b") + cmake_minimum_required(VERSION 3.29) project(cxx_modules_import_std_not_in_export CXX) diff --git a/Tests/RunCMake/CXXModulesCompile/imp-std-stderr.txt b/Tests/RunCMake/CXXModulesCompile/imp-std-stderr.txt new file mode 100644 index 0000000000..f7d285878e --- /dev/null +++ b/Tests/RunCMake/CXXModulesCompile/imp-std-stderr.txt @@ -0,0 +1,8 @@ +CMake Warning \(dev\) at .*/Modules/Compiler/CMakeCommonCompilerMacros\.cmake:[0-9]* \(cmake_language\): + CMake's support for `import std;` in C\+\+23 and newer is experimental\. It + is meant only for experimentation and feedback to CMake developers\. +Call Stack \(most recent call first\): + .*/Modules/CMakeDetermineCompilerSupport\.cmake:[0-9]* \(cmake_cxx_find_modules_json\) + .*/Modules/CMakeTestCXXCompiler\.cmake:[0-9]* \(CMAKE_DETERMINE_COMPILER_SUPPORT\) + CMakeLists\.txt:[0-9]* \(project\) +This warning is for project developers\. Use -Wno-dev to suppress it\. diff --git a/Tests/RunCMake/CXXModulesCompile/imp-std-trans-exp-no-std-build-stderr.txt b/Tests/RunCMake/CXXModulesCompile/imp-std-trans-exp-no-std-build-stderr.txt new file mode 100644 index 0000000000..f7d285878e --- /dev/null +++ b/Tests/RunCMake/CXXModulesCompile/imp-std-trans-exp-no-std-build-stderr.txt @@ -0,0 +1,8 @@ +CMake Warning \(dev\) at .*/Modules/Compiler/CMakeCommonCompilerMacros\.cmake:[0-9]* \(cmake_language\): + CMake's support for `import std;` in C\+\+23 and newer is experimental\. It + is meant only for experimentation and feedback to CMake developers\. +Call Stack \(most recent call first\): + .*/Modules/CMakeDetermineCompilerSupport\.cmake:[0-9]* \(cmake_cxx_find_modules_json\) + .*/Modules/CMakeTestCXXCompiler\.cmake:[0-9]* \(CMAKE_DETERMINE_COMPILER_SUPPORT\) + CMakeLists\.txt:[0-9]* \(project\) +This warning is for project developers\. Use -Wno-dev to suppress it\. diff --git a/Tests/RunCMake/CXXModulesCompile/imp-std-trans-exp-no-std-install-stderr.txt b/Tests/RunCMake/CXXModulesCompile/imp-std-trans-exp-no-std-install-stderr.txt new file mode 100644 index 0000000000..f7d285878e --- /dev/null +++ b/Tests/RunCMake/CXXModulesCompile/imp-std-trans-exp-no-std-install-stderr.txt @@ -0,0 +1,8 @@ +CMake Warning \(dev\) at .*/Modules/Compiler/CMakeCommonCompilerMacros\.cmake:[0-9]* \(cmake_language\): + CMake's support for `import std;` in C\+\+23 and newer is experimental\. It + is meant only for experimentation and feedback to CMake developers\. +Call Stack \(most recent call first\): + .*/Modules/CMakeDetermineCompilerSupport\.cmake:[0-9]* \(cmake_cxx_find_modules_json\) + .*/Modules/CMakeTestCXXCompiler\.cmake:[0-9]* \(CMAKE_DETERMINE_COMPILER_SUPPORT\) + CMakeLists\.txt:[0-9]* \(project\) +This warning is for project developers\. Use -Wno-dev to suppress it\. diff --git a/Tests/RunCMake/CXXModulesCompile/imp-std-trans-not-in-exp-build-stderr.txt b/Tests/RunCMake/CXXModulesCompile/imp-std-trans-not-in-exp-build-stderr.txt new file mode 100644 index 0000000000..f7d285878e --- /dev/null +++ b/Tests/RunCMake/CXXModulesCompile/imp-std-trans-not-in-exp-build-stderr.txt @@ -0,0 +1,8 @@ +CMake Warning \(dev\) at .*/Modules/Compiler/CMakeCommonCompilerMacros\.cmake:[0-9]* \(cmake_language\): + CMake's support for `import std;` in C\+\+23 and newer is experimental\. It + is meant only for experimentation and feedback to CMake developers\. +Call Stack \(most recent call first\): + .*/Modules/CMakeDetermineCompilerSupport\.cmake:[0-9]* \(cmake_cxx_find_modules_json\) + .*/Modules/CMakeTestCXXCompiler\.cmake:[0-9]* \(CMAKE_DETERMINE_COMPILER_SUPPORT\) + CMakeLists\.txt:[0-9]* \(project\) +This warning is for project developers\. Use -Wno-dev to suppress it\. diff --git a/Tests/RunCMake/CXXModulesCompile/imp-std-trans-not-in-exp-install-stderr.txt b/Tests/RunCMake/CXXModulesCompile/imp-std-trans-not-in-exp-install-stderr.txt new file mode 100644 index 0000000000..f7d285878e --- /dev/null +++ b/Tests/RunCMake/CXXModulesCompile/imp-std-trans-not-in-exp-install-stderr.txt @@ -0,0 +1,8 @@ +CMake Warning \(dev\) at .*/Modules/Compiler/CMakeCommonCompilerMacros\.cmake:[0-9]* \(cmake_language\): + CMake's support for `import std;` in C\+\+23 and newer is experimental\. It + is meant only for experimentation and feedback to CMake developers\. +Call Stack \(most recent call first\): + .*/Modules/CMakeDetermineCompilerSupport\.cmake:[0-9]* \(cmake_cxx_find_modules_json\) + .*/Modules/CMakeTestCXXCompiler\.cmake:[0-9]* \(CMAKE_DETERMINE_COMPILER_SUPPORT\) + CMakeLists\.txt:[0-9]* \(project\) +This warning is for project developers\. Use -Wno-dev to suppress it\. diff --git a/Tests/RunCMake/CXXModulesCompile/imp-std-trans/CMakeLists.txt b/Tests/RunCMake/CXXModulesCompile/imp-std-trans/CMakeLists.txt index 1c848c7c2b..aa37dccbdd 100644 --- a/Tests/RunCMake/CXXModulesCompile/imp-std-trans/CMakeLists.txt +++ b/Tests/RunCMake/CXXModulesCompile/imp-std-trans/CMakeLists.txt @@ -1,3 +1,6 @@ +set(CMAKE_EXPERIMENTAL_CXX_IMPORT_STD + "451f2fe2-a8a2-47c3-bc32-94786d8fc91b") + cmake_minimum_required(VERSION 3.29) if (EXPORT_NO_STD) diff --git a/Tests/RunCMake/CXXModulesCompile/imp-std/CMakeLists.txt b/Tests/RunCMake/CXXModulesCompile/imp-std/CMakeLists.txt index 4e894c7066..5488596fe2 100644 --- a/Tests/RunCMake/CXXModulesCompile/imp-std/CMakeLists.txt +++ b/Tests/RunCMake/CXXModulesCompile/imp-std/CMakeLists.txt @@ -1,3 +1,6 @@ +set(CMAKE_EXPERIMENTAL_CXX_IMPORT_STD + "451f2fe2-a8a2-47c3-bc32-94786d8fc91b") + cmake_minimum_required(VERSION 3.29) project(cxx_modules_import_std CXX) diff --git a/Tests/RunCMake/cmake_language/Experimental/CxxImportStd-set-stderr.txt b/Tests/RunCMake/cmake_language/Experimental/CxxImportStd-set-stderr.txt new file mode 100644 index 0000000000..5b2791e36d --- /dev/null +++ b/Tests/RunCMake/cmake_language/Experimental/CxxImportStd-set-stderr.txt @@ -0,0 +1,6 @@ +^CMake Warning \(dev\) at Experimental/CxxImportStd-set\.cmake:4 \(cmake_language\): + CMake's support for `import std;` in C\+\+23 and newer is experimental\. It + is meant only for experimentation and feedback to CMake developers\. +Call Stack \(most recent call first\): + CMakeLists\.txt:[0-9]+ \(include\) +This warning is for project developers\. Use -Wno-dev to suppress it\.$ diff --git a/Tests/RunCMake/cmake_language/Experimental/CxxImportStd-set.cmake b/Tests/RunCMake/cmake_language/Experimental/CxxImportStd-set.cmake new file mode 100644 index 0000000000..66720a9538 --- /dev/null +++ b/Tests/RunCMake/cmake_language/Experimental/CxxImportStd-set.cmake @@ -0,0 +1,11 @@ +set(CMAKE_EXPERIMENTAL_CXX_IMPORT_STD + "451f2fe2-a8a2-47c3-bc32-94786d8fc91b") + +cmake_language(GET_EXPERIMENTAL_FEATURE_ENABLED + "CxxImportStd" + feature_present) + +if (NOT feature_present STREQUAL "TRUE") + message(FATAL_ERROR + "Expected the `CxxImportStd` feature to be enabled.") +endif () diff --git a/Tests/RunCMake/cmake_language/Experimental/CxxImportStd-unset.cmake b/Tests/RunCMake/cmake_language/Experimental/CxxImportStd-unset.cmake new file mode 100644 index 0000000000..be758c239f --- /dev/null +++ b/Tests/RunCMake/cmake_language/Experimental/CxxImportStd-unset.cmake @@ -0,0 +1,8 @@ +cmake_language(GET_EXPERIMENTAL_FEATURE_ENABLED + "CxxImportStd" + feature_present) + +if (NOT feature_present STREQUAL "FALSE") + message(FATAL_ERROR + "Expected the `CxxImportStd` feature to be disabled.") +endif () diff --git a/Tests/RunCMake/cmake_language/Experimental/CxxImportStd-wrong-stderr.txt b/Tests/RunCMake/cmake_language/Experimental/CxxImportStd-wrong-stderr.txt new file mode 100644 index 0000000000..3a9a9dd0f0 --- /dev/null +++ b/Tests/RunCMake/cmake_language/Experimental/CxxImportStd-wrong-stderr.txt @@ -0,0 +1,25 @@ +^CMake Warning \(dev\) at Experimental/CxxImportStd-wrong\.cmake:4 \(cmake_language\): + CMAKE_EXPERIMENTAL_CXX_IMPORT_STD is set to incorrect value + + 01234567-0123-0123-0123-0123456789ab + + See 'Help/dev/experimental\.rst' in the source tree of this version of CMake + for documentation of the experimental feature and the corresponding + activation value\. This project's code may require changes to work with + this CMake's version of the feature\. +Call Stack \(most recent call first\): + CMakeLists\.txt:[0-9]+ \(include\) +This warning is for project developers\. Use -Wno-dev to suppress it\. ++ +CMake Warning \(dev\) at Experimental/CxxImportStd-wrong\.cmake:19 \(cmake_language\): + CMAKE_EXPERIMENTAL_CXX_IMPORT_STD is set to incorrect value + + 76543210-3210-3210-3210-ba9876543210 + + See 'Help/dev/experimental\.rst' in the source tree of this version of CMake + for documentation of the experimental feature and the corresponding + activation value\. This project's code may require changes to work with + this CMake's version of the feature\. +Call Stack \(most recent call first\): + CMakeLists\.txt:[0-9]+ \(include\) +This warning is for project developers\. Use -Wno-dev to suppress it\.$ diff --git a/Tests/RunCMake/cmake_language/Experimental/CxxImportStd-wrong.cmake b/Tests/RunCMake/cmake_language/Experimental/CxxImportStd-wrong.cmake new file mode 100644 index 0000000000..751d4fe302 --- /dev/null +++ b/Tests/RunCMake/cmake_language/Experimental/CxxImportStd-wrong.cmake @@ -0,0 +1,21 @@ +set(CMAKE_EXPERIMENTAL_CXX_IMPORT_STD + "01234567-0123-0123-0123-0123456789ab") + +cmake_language(GET_EXPERIMENTAL_FEATURE_ENABLED + "CxxImportStd" + feature_present) + +if (NOT feature_present STREQUAL "FALSE") + message(FATAL_ERROR + "Expected the `CxxImportStd` feature to be disabled.") +endif () + +# Test if/when warning is repeated. +cmake_language(GET_EXPERIMENTAL_FEATURE_ENABLED + "CxxImportStd" + feature_present) +set(CMAKE_EXPERIMENTAL_CXX_IMPORT_STD + "76543210-3210-3210-3210-ba9876543210") +cmake_language(GET_EXPERIMENTAL_FEATURE_ENABLED + "CxxImportStd" + feature_present) diff --git a/Tests/RunCMake/cmake_language/RunCMakeTest.cmake b/Tests/RunCMake/cmake_language/RunCMakeTest.cmake index dad7f0ed37..e032366ddd 100644 --- a/Tests/RunCMake/cmake_language/RunCMakeTest.cmake +++ b/Tests/RunCMake/cmake_language/RunCMakeTest.cmake @@ -157,6 +157,9 @@ run_cmake_command( -P ${RunCMake_SOURCE_DIR}/get_message_log_level.cmake ) +run_cmake(Experimental/CxxImportStd-set) +run_cmake(Experimental/CxxImportStd-unset) +run_cmake(Experimental/CxxImportStd-wrong) run_cmake(Experimental/ExportPackageDependencies-set) run_cmake(Experimental/ExportPackageDependencies-unset) run_cmake(Experimental/ExportPackageDependencies-wrong) diff --git a/Tests/RunCMake/property_init/CompileSources.cmake b/Tests/RunCMake/property_init/CompileSources.cmake index 7ca13a5612..2d0106c25b 100644 --- a/Tests/RunCMake/property_init/CompileSources.cmake +++ b/Tests/RunCMake/property_init/CompileSources.cmake @@ -156,7 +156,6 @@ set(properties "AUTOMOC_DEPEND_FILTERS" "FIRSTSECOND" "" ## C++ "CXX_SCAN_FOR_MODULES" "ON" "" - "CXX_MODULE_STD" "ON" "" ## Ninja "JOB_POOL_COMPILE" "compile_pool" "" "JOB_POOL_LINK" "link_pool" "" @@ -231,6 +230,15 @@ macro (add_language_properties lang std) ) endmacro () +set(_cmake_supported_import_std_experimental "") +cmake_language(GET_EXPERIMENTAL_FEATURE_ENABLED "CxxImportStd" _cmake_supported_import_std_experimental) +if(_cmake_supported_import_std_experimental) + list(APPEND properties + # property expected alias + "CXX_MODULE_STD" "ON" "" + ) +endif() + # Mock up knowing the standard flag. This doesn't actually build, so nothing # should care at this point. set(CMAKE_Cc_std_11_STANDARD_COMPILE_OPTION "-std=c11")