summaryrefslogtreecommitdiffstats
path: root/Tests/RunCMake
diff options
context:
space:
mode:
authorBen Boeckel <ben.boeckel@kitware.com>2022-11-17 18:50:24 (GMT)
committerBen Boeckel <ben.boeckel@kitware.com>2022-11-18 12:54:31 (GMT)
commita02d792c6e9bf9200ab652db6b6da415d80b578c (patch)
tree6c9d224ad9d3f53ca53cbf0e51b7092834c4308d /Tests/RunCMake
parent008c09d6db60f7c24781b47414ffa26edbd0e22d (diff)
downloadCMake-a02d792c6e9bf9200ab652db6b6da415d80b578c.zip
CMake-a02d792c6e9bf9200ab652db6b6da415d80b578c.tar.gz
CMake-a02d792c6e9bf9200ab652db6b6da415d80b578c.tar.bz2
cxxmodules: add properties to control scanning
The `CXX_SCAN_FOR_MODULES` property may be used to control scanning for targets and for source files rather than assuming "C++20 always needs to be scanned".
Diffstat (limited to 'Tests/RunCMake')
-rw-r--r--Tests/RunCMake/CXXModules/RunCMakeTest.cmake1
-rw-r--r--Tests/RunCMake/CXXModules/examples/scan_properties-stderr.txt9
-rw-r--r--Tests/RunCMake/CXXModules/examples/scan_properties/CMakeLists.txt54
-rw-r--r--Tests/RunCMake/CXXModules/examples/scan_properties/always_scan.cxx10
-rw-r--r--Tests/RunCMake/CXXModules/examples/scan_properties/join.cxx17
-rw-r--r--Tests/RunCMake/CXXModules/examples/scan_properties/main.cxx16
-rw-r--r--Tests/RunCMake/CXXModules/examples/scan_properties/module.cxx10
-rw-r--r--Tests/RunCMake/CXXModules/examples/scan_properties/never_scan.cxx8
8 files changed, 125 insertions, 0 deletions
diff --git a/Tests/RunCMake/CXXModules/RunCMakeTest.cmake b/Tests/RunCMake/CXXModules/RunCMakeTest.cmake
index 921fabd..81a086a 100644
--- a/Tests/RunCMake/CXXModules/RunCMakeTest.cmake
+++ b/Tests/RunCMake/CXXModules/RunCMakeTest.cmake
@@ -138,6 +138,7 @@ if ("named" IN_LIST CMake_TEST_MODULE_COMPILATION)
set(RunCMake_CXXModules_NO_TEST 1)
run_cxx_module_test(circular)
unset(RunCMake_CXXModules_NO_TEST)
+ run_cxx_module_test(scan_properties)
endif ()
# Tests which use named modules in shared libraries.
diff --git a/Tests/RunCMake/CXXModules/examples/scan_properties-stderr.txt b/Tests/RunCMake/CXXModules/examples/scan_properties-stderr.txt
new file mode 100644
index 0000000..7d79bad
--- /dev/null
+++ b/Tests/RunCMake/CXXModules/examples/scan_properties-stderr.txt
@@ -0,0 +1,9 @@
+CMake Warning \(dev\) at CMakeLists.txt:20 \(target_sources\):
+ CMake's C\+\+ module support is experimental. It is meant only for
+ experimentation and feedback to CMake developers.
+This warning is for project developers. Use -Wno-dev to suppress it.
+
+CMake Warning \(dev\):
+ C\+\+20 modules support via CMAKE_EXPERIMENTAL_CXX_MODULE_DYNDEP is
+ experimental. It is meant only for compiler developers to try.
+This warning is for project developers. Use -Wno-dev to suppress it.
diff --git a/Tests/RunCMake/CXXModules/examples/scan_properties/CMakeLists.txt b/Tests/RunCMake/CXXModules/examples/scan_properties/CMakeLists.txt
new file mode 100644
index 0000000..551c55c
--- /dev/null
+++ b/Tests/RunCMake/CXXModules/examples/scan_properties/CMakeLists.txt
@@ -0,0 +1,54 @@
+cmake_minimum_required(VERSION 3.24)
+project(scan_properties CXX)
+
+include("${CMAKE_SOURCE_DIR}/../cxx-modules-rules.cmake")
+
+# To detect that not-to-be scanned sources are not scanned, add a `-D` to the
+# scan flags so that the files can detect whether scanning happened and error
+# if not.
+string(APPEND CMAKE_EXPERIMENTAL_CXX_MODULE_MAP_FLAG
+ " -DCMAKE_SCANNED_THIS_SOURCE")
+string(APPEND CMAKE_EXPERIMENTAL_CXX_SCANDEP_SOURCE
+ " -DCMAKE_SCANNED_THIS_SOURCE")
+
+set_property(SOURCE always_scan.cxx
+ PROPERTY CXX_SCAN_FOR_MODULES 1)
+set_property(SOURCE never_scan.cxx
+ PROPERTY CXX_SCAN_FOR_MODULES 0)
+
+add_executable(scans_everything)
+target_sources(scans_everything
+ PRIVATE
+ main.cxx
+ join.cxx
+ always_scan.cxx
+ never_scan.cxx
+ PRIVATE
+ FILE_SET CXX_MODULES
+ BASE_DIRS
+ "${CMAKE_CURRENT_SOURCE_DIR}"
+ FILES
+ module.cxx)
+target_compile_features(scans_everything PRIVATE cxx_std_20)
+target_compile_definitions(scans_everything PRIVATE SCAN_AT_TARGET_LEVEL=1)
+
+set(CMAKE_CXX_SCAN_FOR_MODULES 0)
+
+add_executable(no_scan_everything)
+target_sources(no_scan_everything
+ PRIVATE
+ main.cxx
+ join.cxx
+ always_scan.cxx
+ never_scan.cxx
+ PRIVATE
+ FILE_SET CXX_MODULES
+ BASE_DIRS
+ "${CMAKE_CURRENT_SOURCE_DIR}"
+ FILES
+ module.cxx)
+target_compile_features(no_scan_everything PRIVATE cxx_std_20)
+target_compile_definitions(no_scan_everything PRIVATE SCAN_AT_TARGET_LEVEL=0)
+
+add_test(NAME scanned COMMAND scans_everything)
+add_test(NAME unscanned COMMAND no_scan_everything)
diff --git a/Tests/RunCMake/CXXModules/examples/scan_properties/always_scan.cxx b/Tests/RunCMake/CXXModules/examples/scan_properties/always_scan.cxx
new file mode 100644
index 0000000..27087d7
--- /dev/null
+++ b/Tests/RunCMake/CXXModules/examples/scan_properties/always_scan.cxx
@@ -0,0 +1,10 @@
+#ifndef CMAKE_SCANNED_THIS_SOURCE
+# error "This file should have been scanned"
+#endif
+
+import M;
+
+int scanned_file()
+{
+ return from_module();
+}
diff --git a/Tests/RunCMake/CXXModules/examples/scan_properties/join.cxx b/Tests/RunCMake/CXXModules/examples/scan_properties/join.cxx
new file mode 100644
index 0000000..8184a40
--- /dev/null
+++ b/Tests/RunCMake/CXXModules/examples/scan_properties/join.cxx
@@ -0,0 +1,17 @@
+#if SCAN_AT_TARGET_LEVEL
+# ifndef CMAKE_SCANNED_THIS_SOURCE
+# error "This file should have been scanned"
+# endif
+#else
+# ifdef CMAKE_SCANNED_THIS_SOURCE
+# error "This file should not have been scanned"
+# endif
+#endif
+
+int scanned_file();
+int never_scan();
+
+int join()
+{
+ return scanned_file() + never_scan();
+}
diff --git a/Tests/RunCMake/CXXModules/examples/scan_properties/main.cxx b/Tests/RunCMake/CXXModules/examples/scan_properties/main.cxx
new file mode 100644
index 0000000..81e93f4
--- /dev/null
+++ b/Tests/RunCMake/CXXModules/examples/scan_properties/main.cxx
@@ -0,0 +1,16 @@
+#if SCAN_AT_TARGET_LEVEL
+# ifndef CMAKE_SCANNED_THIS_SOURCE
+# error "This file should have been scanned"
+# endif
+#else
+# ifdef CMAKE_SCANNED_THIS_SOURCE
+# error "This file should not have been scanned"
+# endif
+#endif
+
+int join();
+
+int main(int argc, char** argv)
+{
+ return join();
+}
diff --git a/Tests/RunCMake/CXXModules/examples/scan_properties/module.cxx b/Tests/RunCMake/CXXModules/examples/scan_properties/module.cxx
new file mode 100644
index 0000000..ad1e04d
--- /dev/null
+++ b/Tests/RunCMake/CXXModules/examples/scan_properties/module.cxx
@@ -0,0 +1,10 @@
+#ifndef CMAKE_SCANNED_THIS_SOURCE
+# error "This file should have been scanned"
+#endif
+
+export module M;
+
+export int from_module()
+{
+ return 0;
+}
diff --git a/Tests/RunCMake/CXXModules/examples/scan_properties/never_scan.cxx b/Tests/RunCMake/CXXModules/examples/scan_properties/never_scan.cxx
new file mode 100644
index 0000000..8374110
--- /dev/null
+++ b/Tests/RunCMake/CXXModules/examples/scan_properties/never_scan.cxx
@@ -0,0 +1,8 @@
+#ifdef CMAKE_SCANNED_THIS_SOURCE
+# error "This file should not have been scanned"
+#endif
+
+int never_scan()
+{
+ return 0;
+}