summaryrefslogtreecommitdiffstats
path: root/Tests/RunCMake/CXXModules
diff options
context:
space:
mode:
Diffstat (limited to 'Tests/RunCMake/CXXModules')
-rw-r--r--Tests/RunCMake/CXXModules/CMP0155-NEW.cmake3
-rw-r--r--Tests/RunCMake/CXXModules/CMP0155-OLD.cmake3
-rw-r--r--Tests/RunCMake/CXXModules/CXXImportStdConfig-result.txt1
-rw-r--r--Tests/RunCMake/CXXModules/CXXImportStdConfig-stderr.txt3
-rw-r--r--Tests/RunCMake/CXXModules/CXXImportStdConfig.cmake10
-rw-r--r--Tests/RunCMake/CXXModules/CXXImportStdHeadTarget-result.txt1
-rw-r--r--Tests/RunCMake/CXXModules/CXXImportStdHeadTarget-stderr.txt9
-rw-r--r--Tests/RunCMake/CXXModules/CXXImportStdHeadTarget.cmake10
-rw-r--r--Tests/RunCMake/CXXModules/CXXImportStdInvalidGenex.cmake11
-rw-r--r--Tests/RunCMake/CXXModules/CXXImportStdLinkLanguage-result.txt1
-rw-r--r--Tests/RunCMake/CXXModules/CXXImportStdLinkLanguage-stderr.txt7
-rw-r--r--Tests/RunCMake/CXXModules/CXXImportStdLinkLanguage.cmake10
-rw-r--r--Tests/RunCMake/CXXModules/ImplicitCXX20.cmake3
-rw-r--r--Tests/RunCMake/CXXModules/Inspect.cmake17
-rw-r--r--Tests/RunCMake/CXXModules/NoCXX20.cmake3
-rw-r--r--Tests/RunCMake/CXXModules/NoCXX23TargetNotRequired.cmake11
-rw-r--r--Tests/RunCMake/CXXModules/NoCXX23TargetRequired-result.txt1
-rw-r--r--Tests/RunCMake/CXXModules/NoCXX23TargetRequired-stderr.txt9
-rw-r--r--Tests/RunCMake/CXXModules/NoCXX23TargetRequired.cmake11
-rw-r--r--Tests/RunCMake/CXXModules/NoCXX23TargetUnset.cmake13
-rw-r--r--Tests/RunCMake/CXXModules/NoCXX26TargetNotRequired.cmake11
-rw-r--r--Tests/RunCMake/CXXModules/NoCXX26TargetRequired-result.txt1
-rw-r--r--Tests/RunCMake/CXXModules/NoCXX26TargetRequired-stderr.txt9
-rw-r--r--Tests/RunCMake/CXXModules/NoCXX26TargetRequired.cmake11
-rw-r--r--Tests/RunCMake/CXXModules/NoCXX26TargetUnset.cmake13
-rw-r--r--Tests/RunCMake/CXXModules/NoScanningVariable.cmake3
-rw-r--r--Tests/RunCMake/CXXModules/RunCMakeTest.cmake47
-rw-r--r--Tests/RunCMake/CXXModules/examples/import-std-export-no-std-build-stderr.txt8
-rw-r--r--Tests/RunCMake/CXXModules/examples/import-std-export-no-std-build/CMakeLists.txt59
-rw-r--r--Tests/RunCMake/CXXModules/examples/import-std-export-no-std-build/impl-uses-std.cxx3
-rw-r--r--Tests/RunCMake/CXXModules/examples/import-std-export-no-std-build/main.cxx6
-rw-r--r--Tests/RunCMake/CXXModules/examples/import-std-export-no-std-build/test/CMakeLists.txt45
-rw-r--r--Tests/RunCMake/CXXModules/examples/import-std-export-no-std-build/uses-std.cxx8
-rw-r--r--Tests/RunCMake/CXXModules/examples/import-std-export-no-std-install-stderr.txt8
-rw-r--r--Tests/RunCMake/CXXModules/examples/import-std-export-no-std-install/CMakeLists.txt61
-rw-r--r--Tests/RunCMake/CXXModules/examples/import-std-export-no-std-install/impl-uses-std.cxx3
-rw-r--r--Tests/RunCMake/CXXModules/examples/import-std-export-no-std-install/main.cxx6
-rw-r--r--Tests/RunCMake/CXXModules/examples/import-std-export-no-std-install/test/CMakeLists.txt45
-rw-r--r--Tests/RunCMake/CXXModules/examples/import-std-export-no-std-install/uses-std.cxx9
-rw-r--r--Tests/RunCMake/CXXModules/examples/import-std-no-std-property-build-result.txt1
-rw-r--r--Tests/RunCMake/CXXModules/examples/import-std-no-std-property-build-stdout.txt1
-rw-r--r--Tests/RunCMake/CXXModules/examples/import-std-no-std-property-stderr.txt8
-rw-r--r--Tests/RunCMake/CXXModules/examples/import-std-no-std-property/CMakeLists.txt13
-rw-r--r--Tests/RunCMake/CXXModules/examples/import-std-no-std-property/main.cxx6
-rw-r--r--Tests/RunCMake/CXXModules/examples/import-std-not-in-export-build-stderr.txt8
-rw-r--r--Tests/RunCMake/CXXModules/examples/import-std-not-in-export-build/CMakeLists.txt54
-rw-r--r--Tests/RunCMake/CXXModules/examples/import-std-not-in-export-build/main.cxx6
-rw-r--r--Tests/RunCMake/CXXModules/examples/import-std-not-in-export-build/test/CMakeLists.txt45
-rw-r--r--Tests/RunCMake/CXXModules/examples/import-std-not-in-export-build/uses-std.cxx7
-rw-r--r--Tests/RunCMake/CXXModules/examples/import-std-not-in-export-install-stderr.txt8
-rw-r--r--Tests/RunCMake/CXXModules/examples/import-std-not-in-export-install/CMakeLists.txt58
-rw-r--r--Tests/RunCMake/CXXModules/examples/import-std-not-in-export-install/main.cxx6
-rw-r--r--Tests/RunCMake/CXXModules/examples/import-std-not-in-export-install/test/CMakeLists.txt45
-rw-r--r--Tests/RunCMake/CXXModules/examples/import-std-not-in-export-install/uses-std.cxx7
-rw-r--r--Tests/RunCMake/CXXModules/examples/import-std-stderr.txt8
-rw-r--r--Tests/RunCMake/CXXModules/examples/import-std-transitive-not-in-export-build-stderr.txt8
-rw-r--r--Tests/RunCMake/CXXModules/examples/import-std-transitive-not-in-export-install-stderr.txt8
-rw-r--r--Tests/RunCMake/CXXModules/examples/import-std-transitive/CMakeLists.txt28
-rw-r--r--Tests/RunCMake/CXXModules/examples/import-std-transitive/main.cxx6
-rw-r--r--Tests/RunCMake/CXXModules/examples/import-std/CMakeLists.txt15
-rw-r--r--Tests/RunCMake/CXXModules/examples/import-std/main.cxx10
-rw-r--r--Tests/RunCMake/CXXModules/examples/vs-without-flags/CMakeLists.txt2
62 files changed, 850 insertions, 1 deletions
diff --git a/Tests/RunCMake/CXXModules/CMP0155-NEW.cmake b/Tests/RunCMake/CXXModules/CMP0155-NEW.cmake
index d68775a..c754930 100644
--- a/Tests/RunCMake/CXXModules/CMP0155-NEW.cmake
+++ b/Tests/RunCMake/CXXModules/CMP0155-NEW.cmake
@@ -1,3 +1,6 @@
+# Block making C++ `import std` targets.
+add_library(__CMAKE::CXX23 IMPORTED INTERFACE)
+
enable_language(CXX)
unset(CMAKE_CXX_SCANDEP_SOURCE)
diff --git a/Tests/RunCMake/CXXModules/CMP0155-OLD.cmake b/Tests/RunCMake/CXXModules/CMP0155-OLD.cmake
index 201598e..a994266 100644
--- a/Tests/RunCMake/CXXModules/CMP0155-OLD.cmake
+++ b/Tests/RunCMake/CXXModules/CMP0155-OLD.cmake
@@ -1,3 +1,6 @@
+# Block making C++ `import std` targets.
+add_library(__CMAKE::CXX23 IMPORTED INTERFACE)
+
enable_language(CXX)
unset(CMAKE_CXX_SCANDEP_SOURCE)
diff --git a/Tests/RunCMake/CXXModules/CXXImportStdConfig-result.txt b/Tests/RunCMake/CXXModules/CXXImportStdConfig-result.txt
new file mode 100644
index 0000000..d00491f
--- /dev/null
+++ b/Tests/RunCMake/CXXModules/CXXImportStdConfig-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/CXXModules/CXXImportStdConfig-stderr.txt b/Tests/RunCMake/CXXModules/CXXImportStdConfig-stderr.txt
new file mode 100644
index 0000000..268099f
--- /dev/null
+++ b/Tests/RunCMake/CXXModules/CXXImportStdConfig-stderr.txt
@@ -0,0 +1,3 @@
+CMake Error in CMakeLists.txt:
+ The "CXX_MODULE_STD" property on the target "nocxx23target" contains a
+ context-sensitive condition that is not supported.
diff --git a/Tests/RunCMake/CXXModules/CXXImportStdConfig.cmake b/Tests/RunCMake/CXXModules/CXXImportStdConfig.cmake
new file mode 100644
index 0000000..0867082
--- /dev/null
+++ b/Tests/RunCMake/CXXModules/CXXImportStdConfig.cmake
@@ -0,0 +1,10 @@
+enable_language(CXX)
+
+set(CMAKE_CXX_MODULE_STD "$<CONFIG:Release>")
+
+add_library(nocxx23target)
+target_sources(nocxx23target
+ PRIVATE
+ FILE_SET fs TYPE CXX_MODULES FILES
+ sources/module.cxx)
+target_compile_features(nocxx23target PRIVATE cxx_std_23)
diff --git a/Tests/RunCMake/CXXModules/CXXImportStdHeadTarget-result.txt b/Tests/RunCMake/CXXModules/CXXImportStdHeadTarget-result.txt
new file mode 100644
index 0000000..d00491f
--- /dev/null
+++ b/Tests/RunCMake/CXXModules/CXXImportStdHeadTarget-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/CXXModules/CXXImportStdHeadTarget-stderr.txt b/Tests/RunCMake/CXXModules/CXXImportStdHeadTarget-stderr.txt
new file mode 100644
index 0000000..a2cdb63
--- /dev/null
+++ b/Tests/RunCMake/CXXModules/CXXImportStdHeadTarget-stderr.txt
@@ -0,0 +1,9 @@
+CMake Error:
+ Error evaluating generator expression:
+
+ \$<TARGET_PROPERTY:use_std_in_consumed>
+
+ \$<TARGET_PROPERTY:prop> may only be used with binary targets. It may not
+ be used with add_custom_command or add_custom_target. Specify the target
+ to read a property from using the \$<TARGET_PROPERTY:tgt,prop> signature
+ instead.
diff --git a/Tests/RunCMake/CXXModules/CXXImportStdHeadTarget.cmake b/Tests/RunCMake/CXXModules/CXXImportStdHeadTarget.cmake
new file mode 100644
index 0000000..3eb2c68
--- /dev/null
+++ b/Tests/RunCMake/CXXModules/CXXImportStdHeadTarget.cmake
@@ -0,0 +1,10 @@
+enable_language(CXX)
+
+set(CMAKE_CXX_MODULE_STD "$<TARGET_PROPERTY:use_std_in_consumed>")
+
+add_library(nocxx23target)
+target_sources(nocxx23target
+ PRIVATE
+ FILE_SET fs TYPE CXX_MODULES FILES
+ sources/module.cxx)
+target_compile_features(nocxx23target PRIVATE cxx_std_23)
diff --git a/Tests/RunCMake/CXXModules/CXXImportStdInvalidGenex.cmake b/Tests/RunCMake/CXXModules/CXXImportStdInvalidGenex.cmake
new file mode 100644
index 0000000..86230a4
--- /dev/null
+++ b/Tests/RunCMake/CXXModules/CXXImportStdInvalidGenex.cmake
@@ -0,0 +1,11 @@
+enable_language(CXX)
+set(CMAKE_CXX_SCANDEP_SOURCE "echo")
+
+set(CMAKE_CXX_MODULE_STD "$<STREQUAL:")
+
+add_library(nocxx23target)
+target_sources(nocxx23target
+ PRIVATE
+ FILE_SET fs TYPE CXX_MODULES FILES
+ sources/module.cxx)
+target_compile_features(nocxx23target PRIVATE cxx_std_23)
diff --git a/Tests/RunCMake/CXXModules/CXXImportStdLinkLanguage-result.txt b/Tests/RunCMake/CXXModules/CXXImportStdLinkLanguage-result.txt
new file mode 100644
index 0000000..d00491f
--- /dev/null
+++ b/Tests/RunCMake/CXXModules/CXXImportStdLinkLanguage-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/CXXModules/CXXImportStdLinkLanguage-stderr.txt b/Tests/RunCMake/CXXModules/CXXImportStdLinkLanguage-stderr.txt
new file mode 100644
index 0000000..21148a2
--- /dev/null
+++ b/Tests/RunCMake/CXXModules/CXXImportStdLinkLanguage-stderr.txt
@@ -0,0 +1,7 @@
+CMake Error:
+ Error evaluating generator expression:
+
+ \$<LINK_LANGUAGE:CXX>
+
+ \$<LINK_LANGUAGE:...> may only be used with binary targets to specify link
+ libraries, link directories, link options and link depends.
diff --git a/Tests/RunCMake/CXXModules/CXXImportStdLinkLanguage.cmake b/Tests/RunCMake/CXXModules/CXXImportStdLinkLanguage.cmake
new file mode 100644
index 0000000..e9b20c7
--- /dev/null
+++ b/Tests/RunCMake/CXXModules/CXXImportStdLinkLanguage.cmake
@@ -0,0 +1,10 @@
+enable_language(CXX)
+
+set(CMAKE_CXX_MODULE_STD "$<LINK_LANGUAGE:CXX>")
+
+add_library(nocxx23target)
+target_sources(nocxx23target
+ PRIVATE
+ FILE_SET fs TYPE CXX_MODULES FILES
+ sources/module.cxx)
+target_compile_features(nocxx23target PRIVATE cxx_std_23)
diff --git a/Tests/RunCMake/CXXModules/ImplicitCXX20.cmake b/Tests/RunCMake/CXXModules/ImplicitCXX20.cmake
index cac1777..64d69f3 100644
--- a/Tests/RunCMake/CXXModules/ImplicitCXX20.cmake
+++ b/Tests/RunCMake/CXXModules/ImplicitCXX20.cmake
@@ -1,6 +1,9 @@
# Enable scanning by default for targets that explicitly use C++ 20.
cmake_policy(SET CMP0155 NEW)
+# Block making C++ `import std` targets.
+add_library(__CMAKE::CXX23 IMPORTED INTERFACE)
+
# Force CMAKE_CXX_STANDARD_DEFAULT to be C++ 20.
set(ENV{CXXFLAGS} "$ENV{CXXFLAGS} ${CMAKE_CXX20_STANDARD_COMPILE_OPTION}")
enable_language(CXX)
diff --git a/Tests/RunCMake/CXXModules/Inspect.cmake b/Tests/RunCMake/CXXModules/Inspect.cmake
index 612b01b..e648e8c 100644
--- a/Tests/RunCMake/CXXModules/Inspect.cmake
+++ b/Tests/RunCMake/CXXModules/Inspect.cmake
@@ -15,11 +15,28 @@ 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(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}\")
diff --git a/Tests/RunCMake/CXXModules/NoCXX20.cmake b/Tests/RunCMake/CXXModules/NoCXX20.cmake
index b7372e8..9710728 100644
--- a/Tests/RunCMake/CXXModules/NoCXX20.cmake
+++ b/Tests/RunCMake/CXXModules/NoCXX20.cmake
@@ -1,3 +1,6 @@
+# Block making C++ `import std` targets.
+add_library(__CMAKE::CXX23 IMPORTED INTERFACE)
+
enable_language(CXX)
add_library(nocxx20)
diff --git a/Tests/RunCMake/CXXModules/NoCXX23TargetNotRequired.cmake b/Tests/RunCMake/CXXModules/NoCXX23TargetNotRequired.cmake
new file mode 100644
index 0000000..2d9bffa
--- /dev/null
+++ b/Tests/RunCMake/CXXModules/NoCXX23TargetNotRequired.cmake
@@ -0,0 +1,11 @@
+enable_language(CXX)
+set(CMAKE_CXX_SCANDEP_SOURCE "echo")
+
+set(CMAKE_CXX_MODULE_STD 0)
+
+add_library(nocxx23target)
+target_sources(nocxx23target
+ PRIVATE
+ FILE_SET fs TYPE CXX_MODULES FILES
+ sources/module.cxx)
+target_compile_features(nocxx23target PRIVATE cxx_std_23)
diff --git a/Tests/RunCMake/CXXModules/NoCXX23TargetRequired-result.txt b/Tests/RunCMake/CXXModules/NoCXX23TargetRequired-result.txt
new file mode 100644
index 0000000..d00491f
--- /dev/null
+++ b/Tests/RunCMake/CXXModules/NoCXX23TargetRequired-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/CXXModules/NoCXX23TargetRequired-stderr.txt b/Tests/RunCMake/CXXModules/NoCXX23TargetRequired-stderr.txt
new file mode 100644
index 0000000..866fa55
--- /dev/null
+++ b/Tests/RunCMake/CXXModules/NoCXX23TargetRequired-stderr.txt
@@ -0,0 +1,9 @@
+CMake Error in CMakeLists.txt:
+ The "CXX_MODULE_STD" property on the target "nocxx23target" requires that
+ the "__CMAKE::CXX23" target exist, but it was not provided by the
+ toolchain. Reason:
+
+ (Toolchain does not support discovering `import std` support|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/NoCXX23TargetRequired.cmake b/Tests/RunCMake/CXXModules/NoCXX23TargetRequired.cmake
new file mode 100644
index 0000000..fac05e2
--- /dev/null
+++ b/Tests/RunCMake/CXXModules/NoCXX23TargetRequired.cmake
@@ -0,0 +1,11 @@
+enable_language(CXX)
+set(CMAKE_CXX_SCANDEP_SOURCE "echo")
+
+set(CMAKE_CXX_MODULE_STD 1)
+
+add_library(nocxx23target)
+target_sources(nocxx23target
+ PRIVATE
+ FILE_SET fs TYPE CXX_MODULES FILES
+ sources/module.cxx)
+target_compile_features(nocxx23target PRIVATE cxx_std_23)
diff --git a/Tests/RunCMake/CXXModules/NoCXX23TargetUnset.cmake b/Tests/RunCMake/CXXModules/NoCXX23TargetUnset.cmake
new file mode 100644
index 0000000..8f6a656
--- /dev/null
+++ b/Tests/RunCMake/CXXModules/NoCXX23TargetUnset.cmake
@@ -0,0 +1,13 @@
+enable_language(CXX)
+set(CMAKE_CXX_SCANDEP_SOURCE "echo")
+
+# TODO(cxxmodules): Add instances of this test which test the policy
+# of the property's unset behavior.
+# set(CMAKE_CXX_MODULE_STD …)
+
+add_library(nocxx23target)
+target_sources(nocxx23target
+ PRIVATE
+ FILE_SET fs TYPE CXX_MODULES FILES
+ sources/module.cxx)
+target_compile_features(nocxx23target PRIVATE cxx_std_23)
diff --git a/Tests/RunCMake/CXXModules/NoCXX26TargetNotRequired.cmake b/Tests/RunCMake/CXXModules/NoCXX26TargetNotRequired.cmake
new file mode 100644
index 0000000..b91fa9b
--- /dev/null
+++ b/Tests/RunCMake/CXXModules/NoCXX26TargetNotRequired.cmake
@@ -0,0 +1,11 @@
+enable_language(CXX)
+set(CMAKE_CXX_SCANDEP_SOURCE "echo")
+
+set(CMAKE_CXX_MODULE_STD 0)
+
+add_library(nocxx26target)
+target_sources(nocxx26target
+ PRIVATE
+ FILE_SET fs TYPE CXX_MODULES FILES
+ sources/module.cxx)
+target_compile_features(nocxx26target PRIVATE cxx_std_26)
diff --git a/Tests/RunCMake/CXXModules/NoCXX26TargetRequired-result.txt b/Tests/RunCMake/CXXModules/NoCXX26TargetRequired-result.txt
new file mode 100644
index 0000000..d00491f
--- /dev/null
+++ b/Tests/RunCMake/CXXModules/NoCXX26TargetRequired-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/CXXModules/NoCXX26TargetRequired-stderr.txt b/Tests/RunCMake/CXXModules/NoCXX26TargetRequired-stderr.txt
new file mode 100644
index 0000000..6e14f1e
--- /dev/null
+++ b/Tests/RunCMake/CXXModules/NoCXX26TargetRequired-stderr.txt
@@ -0,0 +1,9 @@
+CMake Error in CMakeLists.txt:
+ The "CXX_MODULE_STD" property on the target "nocxx26target" requires that
+ the "__CMAKE::CXX26" target exist, but it was not provided by the
+ toolchain. Reason:
+
+ (Toolchain does not support discovering `import std` support|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.cmake b/Tests/RunCMake/CXXModules/NoCXX26TargetRequired.cmake
new file mode 100644
index 0000000..79dcb79
--- /dev/null
+++ b/Tests/RunCMake/CXXModules/NoCXX26TargetRequired.cmake
@@ -0,0 +1,11 @@
+enable_language(CXX)
+set(CMAKE_CXX_SCANDEP_SOURCE "echo")
+
+set(CMAKE_CXX_MODULE_STD 1)
+
+add_library(nocxx26target)
+target_sources(nocxx26target
+ PRIVATE
+ FILE_SET fs TYPE CXX_MODULES FILES
+ sources/module.cxx)
+target_compile_features(nocxx26target PRIVATE cxx_std_26)
diff --git a/Tests/RunCMake/CXXModules/NoCXX26TargetUnset.cmake b/Tests/RunCMake/CXXModules/NoCXX26TargetUnset.cmake
new file mode 100644
index 0000000..85108ff
--- /dev/null
+++ b/Tests/RunCMake/CXXModules/NoCXX26TargetUnset.cmake
@@ -0,0 +1,13 @@
+enable_language(CXX)
+set(CMAKE_CXX_SCANDEP_SOURCE "echo")
+
+# TODO(cxxmodules): Add instances of this test which test the policy
+# of the property's unset behavior.
+# set(CMAKE_CXX_MODULE_STD …)
+
+add_library(nocxx26target)
+target_sources(nocxx26target
+ PRIVATE
+ FILE_SET fs TYPE CXX_MODULES FILES
+ sources/module.cxx)
+target_compile_features(nocxx26target PRIVATE cxx_std_26)
diff --git a/Tests/RunCMake/CXXModules/NoScanningVariable.cmake b/Tests/RunCMake/CXXModules/NoScanningVariable.cmake
index 4bb6a70..950f1f3 100644
--- a/Tests/RunCMake/CXXModules/NoScanningVariable.cmake
+++ b/Tests/RunCMake/CXXModules/NoScanningVariable.cmake
@@ -1,6 +1,9 @@
# Enable scanning by default for targets that explicitly use C++ 20.
cmake_policy(SET CMP0155 NEW)
+# Block making C++ `import std` targets.
+add_library(__CMAKE::CXX23 IMPORTED INTERFACE)
+
enable_language(CXX)
# Hide any real scanning rule that may be available.
diff --git a/Tests/RunCMake/CXXModules/RunCMakeTest.cmake b/Tests/RunCMake/CXXModules/RunCMakeTest.cmake
index 23c32c0..8b7bc86 100644
--- a/Tests/RunCMake/CXXModules/RunCMakeTest.cmake
+++ b/Tests/RunCMake/CXXModules/RunCMakeTest.cmake
@@ -83,6 +83,27 @@ foreach (fileset_type IN LISTS fileset_types)
run_cmake("NotCXXSource${fileset_type}")
endforeach ()
+if ("cxx_std_23" IN_LIST CMAKE_CXX_COMPILE_FEATURES)
+ run_cmake(CXXImportStdConfig)
+ run_cmake(CXXImportStdHeadTarget)
+ run_cmake(CXXImportStdLinkLanguage)
+ run_cmake(CXXImportStdInvalidGenex)
+endif ()
+
+if ("cxx_std_23" IN_LIST CMAKE_CXX_COMPILE_FEATURES AND
+ NOT have_cxx23_import_std)
+ run_cmake(NoCXX23TargetUnset)
+ run_cmake(NoCXX23TargetNotRequired)
+ run_cmake(NoCXX23TargetRequired)
+endif ()
+
+if ("cxx_std_26" IN_LIST CMAKE_CXX_COMPILE_FEATURES AND
+ NOT have_cxx26_import_std)
+ run_cmake(NoCXX26TargetUnset)
+ run_cmake(NoCXX26TargetNotRequired)
+ run_cmake(NoCXX26TargetRequired)
+endif ()
+
run_cmake(InstallBMI)
run_cmake(InstallBMIGenericArgs)
run_cmake(InstallBMIIgnore)
@@ -176,6 +197,7 @@ endfunction ()
# - `partitions`: module partitions are supported
# - `internal_partitions`: internal module partitions are supported
# - `bmionly`: the compiler supports BMI-only builds
+# - `import_std23`: the compiler supports `import std` for C++23
#
# Generator-based:
# - `compile_commands`: the generator supports `compile_commands.json`
@@ -222,6 +244,31 @@ if ("named" IN_LIST CMake_TEST_MODULE_COMPILATION)
run_cxx_module_test(same-src-name)
run_cxx_module_test(scan_properties)
run_cxx_module_test(target-objects)
+
+ if ("cxx_std_23" IN_LIST CMAKE_CXX_COMPILE_FEATURES AND
+ "import_std23" IN_LIST CMake_TEST_MODULE_COMPILATION)
+ run_cxx_module_test(import-std)
+ set(RunCMake_CXXModules_NO_TEST 1)
+ run_cxx_module_test(import-std-no-std-property)
+ unset(RunCMake_CXXModules_NO_TEST)
+ run_cxx_module_test(import-std-export-no-std-build)
+ set(RunCMake_CXXModules_INSTALL 1)
+ run_cxx_module_test(import-std-export-no-std-install)
+ unset(RunCMake_CXXModules_INSTALL)
+
+ if ("collation" IN_LIST CMake_TEST_MODULE_COMPILATION)
+ run_cxx_module_test(import-std-not-in-export-build)
+ run_cxx_module_test(import-std-transitive import-std-transitive-not-in-export-build "-DCMAKE_PREFIX_PATH=${RunCMake_BINARY_DIR}/examples/import-std-not-in-export-build-build")
+
+ set(RunCMake_CXXModules_INSTALL 1)
+ run_cxx_module_test(import-std-not-in-export-install)
+ unset(RunCMake_CXXModules_INSTALL)
+ run_cxx_module_test(import-std-transitive import-std-transitive-not-in-export-install "-DCMAKE_PREFIX_PATH=${RunCMake_BINARY_DIR}/examples/import-std-not-in-export-install-install")
+
+ run_cxx_module_test(import-std-transitive import-std-transitive-export-no-std-build "-DCMAKE_PREFIX_PATH=${RunCMake_BINARY_DIR}/examples/import-std-export-no-std-build-build" -DEXPORT_NO_STD=1)
+ run_cxx_module_test(import-std-transitive import-std-transitive-export-no-std-install "-DCMAKE_PREFIX_PATH=${RunCMake_BINARY_DIR}/examples/import-std-export-no-std-install-install" -DEXPORT_NO_STD=1)
+ endif ()
+ endif ()
endif ()
# Tests which require compile commands support.
diff --git a/Tests/RunCMake/CXXModules/examples/import-std-export-no-std-build-stderr.txt b/Tests/RunCMake/CXXModules/examples/import-std-export-no-std-build-stderr.txt
new file mode 100644
index 0000000..3589448
--- /dev/null
+++ b/Tests/RunCMake/CXXModules/examples/import-std-export-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_create_cxx_import_std\)
+ .*/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/CXXModules/examples/import-std-export-no-std-build/CMakeLists.txt b/Tests/RunCMake/CXXModules/examples/import-std-export-no-std-build/CMakeLists.txt
new file mode 100644
index 0000000..89350ef
--- /dev/null
+++ b/Tests/RunCMake/CXXModules/examples/import-std-export-no-std-build/CMakeLists.txt
@@ -0,0 +1,59 @@
+set(CMAKE_EXPERIMENTAL_CXX_IMPORT_STD
+ "0e5b6991-d74f-4b3d-a41c-cf096e0b2508")
+
+cmake_minimum_required(VERSION 3.29)
+project(cxx_modules_import_std_export_no_std CXX)
+
+include("${CMAKE_SOURCE_DIR}/../cxx-modules-rules.cmake")
+
+set(CMAKE_NO_STD 1)
+
+add_library(import_std_export_no_std)
+target_sources(import_std_export_no_std
+ PRIVATE
+ uses-std.cxx
+ PUBLIC
+ FILE_SET use_std TYPE CXX_MODULES FILES
+ impl-uses-std.cxx)
+target_compile_features(import_std_export_no_std PUBLIC cxx_std_23)
+set_property(TARGET import_std_export_no_std
+ PROPERTY
+ CXX_MODULE_STD "$<BOOL:$<BUILD_LOCAL_INTERFACE:1>>")
+
+add_executable(main
+ main.cxx)
+target_link_libraries(main PRIVATE import_std_export_no_std)
+
+install(TARGETS import_std_export_no_std
+ EXPORT export
+ ARCHIVE DESTINATION "lib"
+ FILE_SET use_std DESTINATION "lib/cxx/miu")
+export(EXPORT export
+ NAMESPACE CXXModules::
+ FILE "${CMAKE_CURRENT_BINARY_DIR}/import_std_export_no_std-targets.cmake")
+file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/import_std_export_no_std-config.cmake"
+ "include(\"\${CMAKE_CURRENT_LIST_DIR}/import_std_export_no_std-targets.cmake\")
+set(\${CMAKE_FIND_PACKAGE_NAME}_FOUND 1)
+")
+
+add_test(NAME main COMMAND main)
+
+set(generator
+ -G "${CMAKE_GENERATOR}")
+if (CMAKE_GENERATOR_TOOLSET)
+ list(APPEND generator
+ -T "${CMAKE_GENERATOR_TOOLSET}")
+endif ()
+if (CMAKE_GENERATOR_PLATFORM)
+ list(APPEND generator
+ -A "${CMAKE_GENERATOR_PLATFORM}")
+endif ()
+
+add_test(NAME import_std_export_no_std_build
+ COMMAND
+ "${CMAKE_COMMAND}"
+ "-Dexpected_dir=${CMAKE_CURRENT_SOURCE_DIR}"
+ "-Dimport_std_export_no_std_DIR=${CMAKE_CURRENT_BINARY_DIR}"
+ ${generator}
+ -S "${CMAKE_CURRENT_SOURCE_DIR}/test"
+ -B "${CMAKE_CURRENT_BINARY_DIR}/test")
diff --git a/Tests/RunCMake/CXXModules/examples/import-std-export-no-std-build/impl-uses-std.cxx b/Tests/RunCMake/CXXModules/examples/import-std-export-no-std-build/impl-uses-std.cxx
new file mode 100644
index 0000000..ee19332
--- /dev/null
+++ b/Tests/RunCMake/CXXModules/examples/import-std-export-no-std-build/impl-uses-std.cxx
@@ -0,0 +1,3 @@
+export module uses_std;
+
+export int f();
diff --git a/Tests/RunCMake/CXXModules/examples/import-std-export-no-std-build/main.cxx b/Tests/RunCMake/CXXModules/examples/import-std-export-no-std-build/main.cxx
new file mode 100644
index 0000000..a6dd8d8
--- /dev/null
+++ b/Tests/RunCMake/CXXModules/examples/import-std-export-no-std-build/main.cxx
@@ -0,0 +1,6 @@
+import uses_std;
+
+int main(int argc, char* argv[])
+{
+ return f();
+}
diff --git a/Tests/RunCMake/CXXModules/examples/import-std-export-no-std-build/test/CMakeLists.txt b/Tests/RunCMake/CXXModules/examples/import-std-export-no-std-build/test/CMakeLists.txt
new file mode 100644
index 0000000..e37f174
--- /dev/null
+++ b/Tests/RunCMake/CXXModules/examples/import-std-export-no-std-build/test/CMakeLists.txt
@@ -0,0 +1,45 @@
+cmake_minimum_required(VERSION 3.29)
+project(cxx_modules_library NONE)
+
+find_package(import_std_export_no_std REQUIRED)
+
+if (NOT TARGET CXXModules::import_std_export_no_std)
+ message(FATAL_ERROR
+ "Missing imported target")
+endif ()
+
+function (check_property expected property)
+ get_property(actual TARGET CXXModules::import_std_export_no_std
+ PROPERTY "${property}")
+ if (NOT DEFINED actual)
+ if (NOT expected STREQUAL "<UNDEF>")
+ message(SEND_ERROR
+ "Mismatch for ${property}:\n expected: ${expected}\n actual: NOT-DEFINED")
+ endif ()
+ elseif (NOT actual STREQUAL expected)
+ message(SEND_ERROR
+ "Mismatch for ${property}:\n expected: ${expected}\n actual: ${actual}")
+ endif ()
+endfunction ()
+
+check_property("<UNDEF>" "IMPORTED_CXX_MODULES_INCLUDE_DIRECTORIES")
+check_property("<UNDEF>" "IMPORTED_CXX_MODULES_COMPILE_DEFINITIONS")
+check_property("cxx_std_23" "IMPORTED_CXX_MODULES_COMPILE_FEATURES")
+check_property("" "IMPORTED_CXX_MODULES_LINK_LIBRARIES")
+check_property("<UNDEF>" "INTERFACE_LINK_LIBRARIES")
+check_property("$<BOOL:>" "CXX_MODULE_STD")
+
+# Extract the export-dependent targets from the export file.
+file(STRINGS "${import_std_export_no_std_DIR}/import_std_export_no_std-targets.cmake" usage_dependent_targets
+ REGEX "foreach._target ")
+# Rudimentary argument splitting.
+string(REPLACE " " ";" usage_dependent_targets "${usage_dependent_targets}")
+# Remove exported "target" names.
+list(FILTER usage_dependent_targets EXCLUDE REGEX "CXXModules::")
+# Strip quotes.
+string(REPLACE "\"" "" usage_dependent_targets "${usage_dependent_targets}")
+
+if ("__CMAKE::CXX23" IN_LIST usage_dependent_targets)
+ message(SEND_ERROR
+ "The main export requires the '__CMAKE::CXX23' target")
+endif ()
diff --git a/Tests/RunCMake/CXXModules/examples/import-std-export-no-std-build/uses-std.cxx b/Tests/RunCMake/CXXModules/examples/import-std-export-no-std-build/uses-std.cxx
new file mode 100644
index 0000000..bd91093
--- /dev/null
+++ b/Tests/RunCMake/CXXModules/examples/import-std-export-no-std-build/uses-std.cxx
@@ -0,0 +1,8 @@
+module uses_std;
+
+import std;
+
+int f()
+{
+ return 0;
+}
diff --git a/Tests/RunCMake/CXXModules/examples/import-std-export-no-std-install-stderr.txt b/Tests/RunCMake/CXXModules/examples/import-std-export-no-std-install-stderr.txt
new file mode 100644
index 0000000..3589448
--- /dev/null
+++ b/Tests/RunCMake/CXXModules/examples/import-std-export-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_create_cxx_import_std\)
+ .*/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/CXXModules/examples/import-std-export-no-std-install/CMakeLists.txt b/Tests/RunCMake/CXXModules/examples/import-std-export-no-std-install/CMakeLists.txt
new file mode 100644
index 0000000..62d9d91
--- /dev/null
+++ b/Tests/RunCMake/CXXModules/examples/import-std-export-no-std-install/CMakeLists.txt
@@ -0,0 +1,61 @@
+set(CMAKE_EXPERIMENTAL_CXX_IMPORT_STD
+ "0e5b6991-d74f-4b3d-a41c-cf096e0b2508")
+
+cmake_minimum_required(VERSION 3.29)
+project(cxx_modules_import_std_export_no_std CXX)
+
+include("${CMAKE_SOURCE_DIR}/../cxx-modules-rules.cmake")
+
+add_library(import_std_export_no_std)
+target_sources(import_std_export_no_std
+ PRIVATE
+ uses-std.cxx
+ PUBLIC
+ FILE_SET use_std TYPE CXX_MODULES FILES
+ impl-uses-std.cxx)
+target_compile_features(import_std_export_no_std PUBLIC cxx_std_23)
+set_property(TARGET import_std_export_no_std
+ PROPERTY
+ CXX_MODULE_STD "$<BOOL:$<BUILD_LOCAL_INTERFACE:1>>")
+
+add_executable(main
+ main.cxx)
+target_link_libraries(main PRIVATE import_std_export_no_std)
+
+install(TARGETS import_std_export_no_std
+ EXPORT export
+ ARCHIVE DESTINATION "lib"
+ FILE_SET use_std DESTINATION "lib/cxx/miu")
+install(
+ EXPORT export
+ NAMESPACE CXXModules::
+ DESTINATION "lib/cmake/import_std_export_no_std"
+ FILE "import_std_export_no_std-targets.cmake")
+file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/import_std_export_no_std-config.cmake"
+ "include(\"\${CMAKE_CURRENT_LIST_DIR}/import_std_export_no_std-targets.cmake\")
+set(\${CMAKE_FIND_PACKAGE_NAME}_FOUND 1)
+")
+install(FILES "${CMAKE_CURRENT_BINARY_DIR}/import_std_export_no_std-config.cmake"
+ DESTINATION "lib/cmake/import_std_export_no_std")
+
+add_test(NAME main COMMAND main)
+
+set(generator
+ -G "${CMAKE_GENERATOR}")
+if (CMAKE_GENERATOR_TOOLSET)
+ list(APPEND generator
+ -T "${CMAKE_GENERATOR_TOOLSET}")
+endif ()
+if (CMAKE_GENERATOR_PLATFORM)
+ list(APPEND generator
+ -A "${CMAKE_GENERATOR_PLATFORM}")
+endif ()
+
+add_test(NAME import_std_export_no_std_build
+ COMMAND
+ "${CMAKE_COMMAND}"
+ "-Dexpected_dir=${CMAKE_INSTALL_PREFIX}/lib/cxx/miu"
+ "-Dimport_std_export_no_std_DIR=${CMAKE_INSTALL_PREFIX}/lib/cmake/import_std_export_no_std"
+ ${generator}
+ -S "${CMAKE_CURRENT_SOURCE_DIR}/test"
+ -B "${CMAKE_CURRENT_BINARY_DIR}/test")
diff --git a/Tests/RunCMake/CXXModules/examples/import-std-export-no-std-install/impl-uses-std.cxx b/Tests/RunCMake/CXXModules/examples/import-std-export-no-std-install/impl-uses-std.cxx
new file mode 100644
index 0000000..ee19332
--- /dev/null
+++ b/Tests/RunCMake/CXXModules/examples/import-std-export-no-std-install/impl-uses-std.cxx
@@ -0,0 +1,3 @@
+export module uses_std;
+
+export int f();
diff --git a/Tests/RunCMake/CXXModules/examples/import-std-export-no-std-install/main.cxx b/Tests/RunCMake/CXXModules/examples/import-std-export-no-std-install/main.cxx
new file mode 100644
index 0000000..a6dd8d8
--- /dev/null
+++ b/Tests/RunCMake/CXXModules/examples/import-std-export-no-std-install/main.cxx
@@ -0,0 +1,6 @@
+import uses_std;
+
+int main(int argc, char* argv[])
+{
+ return f();
+}
diff --git a/Tests/RunCMake/CXXModules/examples/import-std-export-no-std-install/test/CMakeLists.txt b/Tests/RunCMake/CXXModules/examples/import-std-export-no-std-install/test/CMakeLists.txt
new file mode 100644
index 0000000..e37f174
--- /dev/null
+++ b/Tests/RunCMake/CXXModules/examples/import-std-export-no-std-install/test/CMakeLists.txt
@@ -0,0 +1,45 @@
+cmake_minimum_required(VERSION 3.29)
+project(cxx_modules_library NONE)
+
+find_package(import_std_export_no_std REQUIRED)
+
+if (NOT TARGET CXXModules::import_std_export_no_std)
+ message(FATAL_ERROR
+ "Missing imported target")
+endif ()
+
+function (check_property expected property)
+ get_property(actual TARGET CXXModules::import_std_export_no_std
+ PROPERTY "${property}")
+ if (NOT DEFINED actual)
+ if (NOT expected STREQUAL "<UNDEF>")
+ message(SEND_ERROR
+ "Mismatch for ${property}:\n expected: ${expected}\n actual: NOT-DEFINED")
+ endif ()
+ elseif (NOT actual STREQUAL expected)
+ message(SEND_ERROR
+ "Mismatch for ${property}:\n expected: ${expected}\n actual: ${actual}")
+ endif ()
+endfunction ()
+
+check_property("<UNDEF>" "IMPORTED_CXX_MODULES_INCLUDE_DIRECTORIES")
+check_property("<UNDEF>" "IMPORTED_CXX_MODULES_COMPILE_DEFINITIONS")
+check_property("cxx_std_23" "IMPORTED_CXX_MODULES_COMPILE_FEATURES")
+check_property("" "IMPORTED_CXX_MODULES_LINK_LIBRARIES")
+check_property("<UNDEF>" "INTERFACE_LINK_LIBRARIES")
+check_property("$<BOOL:>" "CXX_MODULE_STD")
+
+# Extract the export-dependent targets from the export file.
+file(STRINGS "${import_std_export_no_std_DIR}/import_std_export_no_std-targets.cmake" usage_dependent_targets
+ REGEX "foreach._target ")
+# Rudimentary argument splitting.
+string(REPLACE " " ";" usage_dependent_targets "${usage_dependent_targets}")
+# Remove exported "target" names.
+list(FILTER usage_dependent_targets EXCLUDE REGEX "CXXModules::")
+# Strip quotes.
+string(REPLACE "\"" "" usage_dependent_targets "${usage_dependent_targets}")
+
+if ("__CMAKE::CXX23" IN_LIST usage_dependent_targets)
+ message(SEND_ERROR
+ "The main export requires the '__CMAKE::CXX23' target")
+endif ()
diff --git a/Tests/RunCMake/CXXModules/examples/import-std-export-no-std-install/uses-std.cxx b/Tests/RunCMake/CXXModules/examples/import-std-export-no-std-install/uses-std.cxx
new file mode 100644
index 0000000..6b7e814
--- /dev/null
+++ b/Tests/RunCMake/CXXModules/examples/import-std-export-no-std-install/uses-std.cxx
@@ -0,0 +1,9 @@
+module uses_std;
+import std;
+
+int f()
+{
+ std::string str = "hello!";
+ std::cout << "program: " << str << std::endl;
+ return 0;
+}
diff --git a/Tests/RunCMake/CXXModules/examples/import-std-no-std-property-build-result.txt b/Tests/RunCMake/CXXModules/examples/import-std-no-std-property-build-result.txt
new file mode 100644
index 0000000..d00491f
--- /dev/null
+++ b/Tests/RunCMake/CXXModules/examples/import-std-no-std-property-build-result.txt
@@ -0,0 +1 @@
+1
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
new file mode 100644
index 0000000..d473333
--- /dev/null
+++ b/Tests/RunCMake/CXXModules/examples/import-std-no-std-property-build-stdout.txt
@@ -0,0 +1 @@
+((Clang)?module 'std' not found|(MSVC)?could not find module 'std')
diff --git a/Tests/RunCMake/CXXModules/examples/import-std-no-std-property-stderr.txt b/Tests/RunCMake/CXXModules/examples/import-std-no-std-property-stderr.txt
new file mode 100644
index 0000000..3589448
--- /dev/null
+++ b/Tests/RunCMake/CXXModules/examples/import-std-no-std-property-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_create_cxx_import_std\)
+ .*/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/CXXModules/examples/import-std-no-std-property/CMakeLists.txt b/Tests/RunCMake/CXXModules/examples/import-std-no-std-property/CMakeLists.txt
new file mode 100644
index 0000000..a605e95
--- /dev/null
+++ b/Tests/RunCMake/CXXModules/examples/import-std-no-std-property/CMakeLists.txt
@@ -0,0 +1,13 @@
+set(CMAKE_EXPERIMENTAL_CXX_IMPORT_STD
+ "0e5b6991-d74f-4b3d-a41c-cf096e0b2508")
+
+cmake_minimum_required(VERSION 3.29)
+project(cxx_modules_import_std_no_std_property CXX)
+
+include("${CMAKE_SOURCE_DIR}/../cxx-modules-rules.cmake")
+
+set(CMAKE_CXX_MODULE_STD 0)
+
+add_executable(main
+ main.cxx)
+target_compile_features(main PRIVATE cxx_std_23)
diff --git a/Tests/RunCMake/CXXModules/examples/import-std-no-std-property/main.cxx b/Tests/RunCMake/CXXModules/examples/import-std-no-std-property/main.cxx
new file mode 100644
index 0000000..fee84f1
--- /dev/null
+++ b/Tests/RunCMake/CXXModules/examples/import-std-no-std-property/main.cxx
@@ -0,0 +1,6 @@
+import std;
+
+int main(int argc, char* argv[])
+{
+ return 0;
+}
diff --git a/Tests/RunCMake/CXXModules/examples/import-std-not-in-export-build-stderr.txt b/Tests/RunCMake/CXXModules/examples/import-std-not-in-export-build-stderr.txt
new file mode 100644
index 0000000..3589448
--- /dev/null
+++ b/Tests/RunCMake/CXXModules/examples/import-std-not-in-export-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_create_cxx_import_std\)
+ .*/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/CXXModules/examples/import-std-not-in-export-build/CMakeLists.txt b/Tests/RunCMake/CXXModules/examples/import-std-not-in-export-build/CMakeLists.txt
new file mode 100644
index 0000000..3112002
--- /dev/null
+++ b/Tests/RunCMake/CXXModules/examples/import-std-not-in-export-build/CMakeLists.txt
@@ -0,0 +1,54 @@
+set(CMAKE_EXPERIMENTAL_CXX_IMPORT_STD
+ "0e5b6991-d74f-4b3d-a41c-cf096e0b2508")
+
+cmake_minimum_required(VERSION 3.29)
+project(cxx_modules_import_std_not_in_export CXX)
+
+include("${CMAKE_SOURCE_DIR}/../cxx-modules-rules.cmake")
+
+set(CMAKE_CXX_MODULE_STD 1)
+
+add_library(import_std_not_in_export)
+target_sources(import_std_not_in_export
+ PUBLIC
+ FILE_SET use_std TYPE CXX_MODULES FILES
+ uses-std.cxx)
+target_compile_features(import_std_not_in_export PUBLIC cxx_std_23)
+
+add_executable(main
+ main.cxx)
+target_link_libraries(main PRIVATE import_std_not_in_export)
+
+install(TARGETS import_std_not_in_export
+ EXPORT export
+ ARCHIVE DESTINATION "lib"
+ FILE_SET use_std DESTINATION "lib/cxx/miu")
+export(EXPORT export
+ NAMESPACE CXXModules::
+ FILE "${CMAKE_CURRENT_BINARY_DIR}/import_std_not_in_export-targets.cmake")
+file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/import_std_not_in_export-config.cmake"
+ "include(\"\${CMAKE_CURRENT_LIST_DIR}/import_std_not_in_export-targets.cmake\")
+set(\${CMAKE_FIND_PACKAGE_NAME}_FOUND 1)
+")
+
+add_test(NAME main COMMAND main)
+
+set(generator
+ -G "${CMAKE_GENERATOR}")
+if (CMAKE_GENERATOR_TOOLSET)
+ list(APPEND generator
+ -T "${CMAKE_GENERATOR_TOOLSET}")
+endif ()
+if (CMAKE_GENERATOR_PLATFORM)
+ list(APPEND generator
+ -A "${CMAKE_GENERATOR_PLATFORM}")
+endif ()
+
+add_test(NAME import_std_not_in_export_build
+ COMMAND
+ "${CMAKE_COMMAND}"
+ "-Dexpected_dir=${CMAKE_CURRENT_SOURCE_DIR}"
+ "-Dimport_std_not_in_export_DIR=${CMAKE_CURRENT_BINARY_DIR}"
+ ${generator}
+ -S "${CMAKE_CURRENT_SOURCE_DIR}/test"
+ -B "${CMAKE_CURRENT_BINARY_DIR}/test")
diff --git a/Tests/RunCMake/CXXModules/examples/import-std-not-in-export-build/main.cxx b/Tests/RunCMake/CXXModules/examples/import-std-not-in-export-build/main.cxx
new file mode 100644
index 0000000..a6dd8d8
--- /dev/null
+++ b/Tests/RunCMake/CXXModules/examples/import-std-not-in-export-build/main.cxx
@@ -0,0 +1,6 @@
+import uses_std;
+
+int main(int argc, char* argv[])
+{
+ return f();
+}
diff --git a/Tests/RunCMake/CXXModules/examples/import-std-not-in-export-build/test/CMakeLists.txt b/Tests/RunCMake/CXXModules/examples/import-std-not-in-export-build/test/CMakeLists.txt
new file mode 100644
index 0000000..4e994d2
--- /dev/null
+++ b/Tests/RunCMake/CXXModules/examples/import-std-not-in-export-build/test/CMakeLists.txt
@@ -0,0 +1,45 @@
+cmake_minimum_required(VERSION 3.29)
+project(cxx_modules_library NONE)
+
+find_package(import_std_not_in_export REQUIRED)
+
+if (NOT TARGET CXXModules::import_std_not_in_export)
+ message(FATAL_ERROR
+ "Missing imported target")
+endif ()
+
+function (check_property expected property)
+ get_property(actual TARGET CXXModules::import_std_not_in_export
+ PROPERTY "${property}")
+ if (NOT DEFINED actual)
+ if (NOT expected STREQUAL "<UNDEF>")
+ message(SEND_ERROR
+ "Mismatch for ${property}:\n expected: ${expected}\n actual: NOT-DEFINED")
+ endif ()
+ elseif (NOT actual STREQUAL expected)
+ message(SEND_ERROR
+ "Mismatch for ${property}:\n expected: ${expected}\n actual: ${actual}")
+ endif ()
+endfunction ()
+
+check_property("<UNDEF>" "IMPORTED_CXX_MODULES_INCLUDE_DIRECTORIES")
+check_property("<UNDEF>" "IMPORTED_CXX_MODULES_COMPILE_DEFINITIONS")
+check_property("cxx_std_23" "IMPORTED_CXX_MODULES_COMPILE_FEATURES")
+check_property("" "IMPORTED_CXX_MODULES_LINK_LIBRARIES")
+check_property("<UNDEF>" "INTERFACE_LINK_LIBRARIES")
+check_property("1" "CXX_MODULE_STD")
+
+# Extract the export-dependent targets from the export file.
+file(STRINGS "${import_std_not_in_export_DIR}/import_std_not_in_export-targets.cmake" usage_dependent_targets
+ REGEX "foreach._target ")
+# Rudimentary argument splitting.
+string(REPLACE " " ";" usage_dependent_targets "${usage_dependent_targets}")
+# Remove exported "target" names.
+list(FILTER usage_dependent_targets EXCLUDE REGEX "CXXModules::")
+# Strip quotes.
+string(REPLACE "\"" "" usage_dependent_targets "${usage_dependent_targets}")
+
+if ("__CMAKE::CXX23" IN_LIST usage_dependent_targets)
+ message(SEND_ERROR
+ "The main export requires the '__CMAKE::CXX23' target")
+endif ()
diff --git a/Tests/RunCMake/CXXModules/examples/import-std-not-in-export-build/uses-std.cxx b/Tests/RunCMake/CXXModules/examples/import-std-not-in-export-build/uses-std.cxx
new file mode 100644
index 0000000..aa45dd1
--- /dev/null
+++ b/Tests/RunCMake/CXXModules/examples/import-std-not-in-export-build/uses-std.cxx
@@ -0,0 +1,7 @@
+export module uses_std;
+import std;
+
+export int f()
+{
+ return 0;
+}
diff --git a/Tests/RunCMake/CXXModules/examples/import-std-not-in-export-install-stderr.txt b/Tests/RunCMake/CXXModules/examples/import-std-not-in-export-install-stderr.txt
new file mode 100644
index 0000000..3589448
--- /dev/null
+++ b/Tests/RunCMake/CXXModules/examples/import-std-not-in-export-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_create_cxx_import_std\)
+ .*/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/CXXModules/examples/import-std-not-in-export-install/CMakeLists.txt b/Tests/RunCMake/CXXModules/examples/import-std-not-in-export-install/CMakeLists.txt
new file mode 100644
index 0000000..788ea84
--- /dev/null
+++ b/Tests/RunCMake/CXXModules/examples/import-std-not-in-export-install/CMakeLists.txt
@@ -0,0 +1,58 @@
+set(CMAKE_EXPERIMENTAL_CXX_IMPORT_STD
+ "0e5b6991-d74f-4b3d-a41c-cf096e0b2508")
+
+cmake_minimum_required(VERSION 3.29)
+project(cxx_modules_import_std_not_in_export CXX)
+
+include("${CMAKE_SOURCE_DIR}/../cxx-modules-rules.cmake")
+
+set(CMAKE_CXX_MODULE_STD 1)
+
+add_library(import_std_not_in_export)
+target_sources(import_std_not_in_export
+ PUBLIC
+ FILE_SET use_std TYPE CXX_MODULES FILES
+ uses-std.cxx)
+target_compile_features(import_std_not_in_export PUBLIC cxx_std_23)
+
+add_executable(main
+ main.cxx)
+target_link_libraries(main PRIVATE import_std_not_in_export)
+
+install(TARGETS import_std_not_in_export
+ EXPORT export
+ ARCHIVE DESTINATION "lib"
+ FILE_SET use_std DESTINATION "lib/cxx/miu")
+install(
+ EXPORT export
+ NAMESPACE CXXModules::
+ DESTINATION "lib/cmake/import_std_not_in_export"
+ FILE "import_std_not_in_export-targets.cmake")
+file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/import_std_not_in_export-config.cmake"
+ "include(\"\${CMAKE_CURRENT_LIST_DIR}/import_std_not_in_export-targets.cmake\")
+set(\${CMAKE_FIND_PACKAGE_NAME}_FOUND 1)
+")
+install(FILES "${CMAKE_CURRENT_BINARY_DIR}/import_std_not_in_export-config.cmake"
+ DESTINATION "lib/cmake/import_std_not_in_export")
+
+add_test(NAME main COMMAND main)
+
+set(generator
+ -G "${CMAKE_GENERATOR}")
+if (CMAKE_GENERATOR_TOOLSET)
+ list(APPEND generator
+ -T "${CMAKE_GENERATOR_TOOLSET}")
+endif ()
+if (CMAKE_GENERATOR_PLATFORM)
+ list(APPEND generator
+ -A "${CMAKE_GENERATOR_PLATFORM}")
+endif ()
+
+add_test(NAME import_std_not_in_export_build
+ COMMAND
+ "${CMAKE_COMMAND}"
+ "-Dexpected_dir=${CMAKE_INSTALL_PREFIX}/lib/cxx/miu"
+ "-Dimport_std_not_in_export_DIR=${CMAKE_INSTALL_PREFIX}/lib/cmake/import_std_not_in_export"
+ ${generator}
+ -S "${CMAKE_CURRENT_SOURCE_DIR}/test"
+ -B "${CMAKE_CURRENT_BINARY_DIR}/test")
diff --git a/Tests/RunCMake/CXXModules/examples/import-std-not-in-export-install/main.cxx b/Tests/RunCMake/CXXModules/examples/import-std-not-in-export-install/main.cxx
new file mode 100644
index 0000000..a6dd8d8
--- /dev/null
+++ b/Tests/RunCMake/CXXModules/examples/import-std-not-in-export-install/main.cxx
@@ -0,0 +1,6 @@
+import uses_std;
+
+int main(int argc, char* argv[])
+{
+ return f();
+}
diff --git a/Tests/RunCMake/CXXModules/examples/import-std-not-in-export-install/test/CMakeLists.txt b/Tests/RunCMake/CXXModules/examples/import-std-not-in-export-install/test/CMakeLists.txt
new file mode 100644
index 0000000..4e994d2
--- /dev/null
+++ b/Tests/RunCMake/CXXModules/examples/import-std-not-in-export-install/test/CMakeLists.txt
@@ -0,0 +1,45 @@
+cmake_minimum_required(VERSION 3.29)
+project(cxx_modules_library NONE)
+
+find_package(import_std_not_in_export REQUIRED)
+
+if (NOT TARGET CXXModules::import_std_not_in_export)
+ message(FATAL_ERROR
+ "Missing imported target")
+endif ()
+
+function (check_property expected property)
+ get_property(actual TARGET CXXModules::import_std_not_in_export
+ PROPERTY "${property}")
+ if (NOT DEFINED actual)
+ if (NOT expected STREQUAL "<UNDEF>")
+ message(SEND_ERROR
+ "Mismatch for ${property}:\n expected: ${expected}\n actual: NOT-DEFINED")
+ endif ()
+ elseif (NOT actual STREQUAL expected)
+ message(SEND_ERROR
+ "Mismatch for ${property}:\n expected: ${expected}\n actual: ${actual}")
+ endif ()
+endfunction ()
+
+check_property("<UNDEF>" "IMPORTED_CXX_MODULES_INCLUDE_DIRECTORIES")
+check_property("<UNDEF>" "IMPORTED_CXX_MODULES_COMPILE_DEFINITIONS")
+check_property("cxx_std_23" "IMPORTED_CXX_MODULES_COMPILE_FEATURES")
+check_property("" "IMPORTED_CXX_MODULES_LINK_LIBRARIES")
+check_property("<UNDEF>" "INTERFACE_LINK_LIBRARIES")
+check_property("1" "CXX_MODULE_STD")
+
+# Extract the export-dependent targets from the export file.
+file(STRINGS "${import_std_not_in_export_DIR}/import_std_not_in_export-targets.cmake" usage_dependent_targets
+ REGEX "foreach._target ")
+# Rudimentary argument splitting.
+string(REPLACE " " ";" usage_dependent_targets "${usage_dependent_targets}")
+# Remove exported "target" names.
+list(FILTER usage_dependent_targets EXCLUDE REGEX "CXXModules::")
+# Strip quotes.
+string(REPLACE "\"" "" usage_dependent_targets "${usage_dependent_targets}")
+
+if ("__CMAKE::CXX23" IN_LIST usage_dependent_targets)
+ message(SEND_ERROR
+ "The main export requires the '__CMAKE::CXX23' target")
+endif ()
diff --git a/Tests/RunCMake/CXXModules/examples/import-std-not-in-export-install/uses-std.cxx b/Tests/RunCMake/CXXModules/examples/import-std-not-in-export-install/uses-std.cxx
new file mode 100644
index 0000000..aa45dd1
--- /dev/null
+++ b/Tests/RunCMake/CXXModules/examples/import-std-not-in-export-install/uses-std.cxx
@@ -0,0 +1,7 @@
+export module uses_std;
+import std;
+
+export int f()
+{
+ return 0;
+}
diff --git a/Tests/RunCMake/CXXModules/examples/import-std-stderr.txt b/Tests/RunCMake/CXXModules/examples/import-std-stderr.txt
new file mode 100644
index 0000000..3589448
--- /dev/null
+++ b/Tests/RunCMake/CXXModules/examples/import-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_create_cxx_import_std\)
+ .*/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/CXXModules/examples/import-std-transitive-not-in-export-build-stderr.txt b/Tests/RunCMake/CXXModules/examples/import-std-transitive-not-in-export-build-stderr.txt
new file mode 100644
index 0000000..3589448
--- /dev/null
+++ b/Tests/RunCMake/CXXModules/examples/import-std-transitive-not-in-export-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_create_cxx_import_std\)
+ .*/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/CXXModules/examples/import-std-transitive-not-in-export-install-stderr.txt b/Tests/RunCMake/CXXModules/examples/import-std-transitive-not-in-export-install-stderr.txt
new file mode 100644
index 0000000..3589448
--- /dev/null
+++ b/Tests/RunCMake/CXXModules/examples/import-std-transitive-not-in-export-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_create_cxx_import_std\)
+ .*/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/CXXModules/examples/import-std-transitive/CMakeLists.txt b/Tests/RunCMake/CXXModules/examples/import-std-transitive/CMakeLists.txt
new file mode 100644
index 0000000..2894d67
--- /dev/null
+++ b/Tests/RunCMake/CXXModules/examples/import-std-transitive/CMakeLists.txt
@@ -0,0 +1,28 @@
+set(CMAKE_EXPERIMENTAL_CXX_IMPORT_STD
+ "0e5b6991-d74f-4b3d-a41c-cf096e0b2508")
+
+cmake_minimum_required(VERSION 3.29)
+
+if (EXPORT_NO_STD)
+ # Block making C++ `import std` targets.
+ add_library(__CMAKE::CXX23 IMPORTED INTERFACE)
+endif ()
+
+project(cxx_modules_import_std_transitive CXX)
+
+include("${CMAKE_SOURCE_DIR}/../cxx-modules-rules.cmake")
+
+if (EXPORT_NO_STD)
+ set(package "import_std_export_no_std")
+else ()
+ set(package "import_std_not_in_export")
+endif ()
+find_package("${package}" REQUIRED)
+
+set(CMAKE_CXX_MODULE_STD 0)
+
+add_executable(main
+ main.cxx)
+target_link_libraries(main PRIVATE "CXXModules::${package}")
+
+add_test(NAME main COMMAND main)
diff --git a/Tests/RunCMake/CXXModules/examples/import-std-transitive/main.cxx b/Tests/RunCMake/CXXModules/examples/import-std-transitive/main.cxx
new file mode 100644
index 0000000..a6dd8d8
--- /dev/null
+++ b/Tests/RunCMake/CXXModules/examples/import-std-transitive/main.cxx
@@ -0,0 +1,6 @@
+import uses_std;
+
+int main(int argc, char* argv[])
+{
+ return f();
+}
diff --git a/Tests/RunCMake/CXXModules/examples/import-std/CMakeLists.txt b/Tests/RunCMake/CXXModules/examples/import-std/CMakeLists.txt
new file mode 100644
index 0000000..bffcd66
--- /dev/null
+++ b/Tests/RunCMake/CXXModules/examples/import-std/CMakeLists.txt
@@ -0,0 +1,15 @@
+set(CMAKE_EXPERIMENTAL_CXX_IMPORT_STD
+ "0e5b6991-d74f-4b3d-a41c-cf096e0b2508")
+
+cmake_minimum_required(VERSION 3.29)
+project(cxx_modules_import_std CXX)
+
+include("${CMAKE_SOURCE_DIR}/../cxx-modules-rules.cmake")
+
+set(CMAKE_CXX_MODULE_STD 1)
+
+add_executable(main
+ main.cxx)
+target_compile_features(main PRIVATE cxx_std_23)
+
+add_test(NAME main COMMAND main)
diff --git a/Tests/RunCMake/CXXModules/examples/import-std/main.cxx b/Tests/RunCMake/CXXModules/examples/import-std/main.cxx
new file mode 100644
index 0000000..6dafd01
--- /dev/null
+++ b/Tests/RunCMake/CXXModules/examples/import-std/main.cxx
@@ -0,0 +1,10 @@
+import std;
+
+int main(int argc, char* argv[])
+{
+ if (argc > 0 && argv[0]) {
+ std::string argv0 = argv[0];
+ std::cout << "program: " << argv0 << std::endl;
+ }
+ return 0;
+}
diff --git a/Tests/RunCMake/CXXModules/examples/vs-without-flags/CMakeLists.txt b/Tests/RunCMake/CXXModules/examples/vs-without-flags/CMakeLists.txt
index 0d18a66..c5958df 100644
--- a/Tests/RunCMake/CXXModules/examples/vs-without-flags/CMakeLists.txt
+++ b/Tests/RunCMake/CXXModules/examples/vs-without-flags/CMakeLists.txt
@@ -3,7 +3,7 @@ project(cxx_modules_vs_without_flags CXX)
include("${CMAKE_SOURCE_DIR}/../cxx-modules-rules.cmake")
-set(CMAKE_CXX_STANDARD 23)
+set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
set(CMAKE_CXX_SCAN_FOR_MODULES ON)