summaryrefslogtreecommitdiffstats
path: root/Tests/RunCMake/CXXModules/examples
diff options
context:
space:
mode:
Diffstat (limited to 'Tests/RunCMake/CXXModules/examples')
-rw-r--r--Tests/RunCMake/CXXModules/examples/ninja-cmp0154-build-check.cmake4
-rw-r--r--Tests/RunCMake/CXXModules/examples/ninja-cmp0154/CMakeLists.txt31
-rw-r--r--Tests/RunCMake/CXXModules/examples/ninja-cmp0154/importable.cxx.in5
-rw-r--r--Tests/RunCMake/CXXModules/examples/ninja-cmp0154/main.cxx8
-rw-r--r--Tests/RunCMake/CXXModules/examples/ninja-cmp0154/unrelated.cxx4
5 files changed, 52 insertions, 0 deletions
diff --git a/Tests/RunCMake/CXXModules/examples/ninja-cmp0154-build-check.cmake b/Tests/RunCMake/CXXModules/examples/ninja-cmp0154-build-check.cmake
new file mode 100644
index 0000000..6c4812b
--- /dev/null
+++ b/Tests/RunCMake/CXXModules/examples/ninja-cmp0154-build-check.cmake
@@ -0,0 +1,4 @@
+if (EXISTS "${RunCMake_TEST_BINARY_DIR}/importable.cxx")
+ list(APPEND RunCMake_TEST_FAILED
+ "The `importable.cxx` file should not be generated to compile `unrelated`'s object")
+endif ()
diff --git a/Tests/RunCMake/CXXModules/examples/ninja-cmp0154/CMakeLists.txt b/Tests/RunCMake/CXXModules/examples/ninja-cmp0154/CMakeLists.txt
new file mode 100644
index 0000000..1aa36c1
--- /dev/null
+++ b/Tests/RunCMake/CXXModules/examples/ninja-cmp0154/CMakeLists.txt
@@ -0,0 +1,31 @@
+cmake_minimum_required(VERSION 3.24...3.28)
+project(cxx_modules_ninja_cmp0154 CXX)
+
+include("${CMAKE_SOURCE_DIR}/../cxx-modules-rules.cmake")
+
+add_custom_command(
+ OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/importable.cxx"
+ DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/importable.cxx.in"
+ COMMAND "${CMAKE_COMMAND}"
+ -E copy_if_different
+ "${CMAKE_CURRENT_SOURCE_DIR}/importable.cxx.in"
+ "${CMAKE_CURRENT_BINARY_DIR}/importable.cxx"
+ COMMENT "Copying 'importable.cxx'")
+
+add_executable(ninja_cmp0154)
+target_sources(ninja_cmp0154
+ PRIVATE
+ main.cxx
+ unrelated.cxx
+ PUBLIC
+ FILE_SET CXX_MODULES
+ BASE_DIRS
+ "${CMAKE_CURRENT_BINARY_DIR}"
+ FILES
+ "${CMAKE_CURRENT_BINARY_DIR}/importable.cxx")
+target_compile_features(ninja_cmp0154 PUBLIC cxx_std_20)
+set_property(SOURCE unrelated.cxx
+ PROPERTY
+ CXX_SCAN_FOR_MODULES 0)
+
+add_test(NAME ninja_cmp0154 COMMAND ninja_cmp0154)
diff --git a/Tests/RunCMake/CXXModules/examples/ninja-cmp0154/importable.cxx.in b/Tests/RunCMake/CXXModules/examples/ninja-cmp0154/importable.cxx.in
new file mode 100644
index 0000000..a9287d7
--- /dev/null
+++ b/Tests/RunCMake/CXXModules/examples/ninja-cmp0154/importable.cxx.in
@@ -0,0 +1,5 @@
+export module importable;
+
+export int from_import() {
+ return 0;
+}
diff --git a/Tests/RunCMake/CXXModules/examples/ninja-cmp0154/main.cxx b/Tests/RunCMake/CXXModules/examples/ninja-cmp0154/main.cxx
new file mode 100644
index 0000000..1ac4850
--- /dev/null
+++ b/Tests/RunCMake/CXXModules/examples/ninja-cmp0154/main.cxx
@@ -0,0 +1,8 @@
+import importable;
+
+extern int unrelated();
+
+int main(int argc, char* argv[])
+{
+ return from_import() + unrelated();
+}
diff --git a/Tests/RunCMake/CXXModules/examples/ninja-cmp0154/unrelated.cxx b/Tests/RunCMake/CXXModules/examples/ninja-cmp0154/unrelated.cxx
new file mode 100644
index 0000000..d54a47f
--- /dev/null
+++ b/Tests/RunCMake/CXXModules/examples/ninja-cmp0154/unrelated.cxx
@@ -0,0 +1,4 @@
+int unrelated()
+{
+ return 0;
+}