summaryrefslogtreecommitdiffstats
path: root/Tests
diff options
context:
space:
mode:
authorBen Boeckel <ben.boeckel@kitware.com>2023-07-19 23:00:05 (GMT)
committerBen Boeckel <ben.boeckel@kitware.com>2023-07-31 15:59:47 (GMT)
commitb768d293c5c358dd734234cacab7c34e61c88c54 (patch)
treec509fe68fab1661f978acd7a07b0aa3132c0d20c /Tests
parent93993c7ad4f634451fb1c8f67f00d4d959d199ac (diff)
downloadCMake-b768d293c5c358dd734234cacab7c34e61c88c54.zip
CMake-b768d293c5c358dd734234cacab7c34e61c88c54.tar.gz
CMake-b768d293c5c358dd734234cacab7c34e61c88c54.tar.bz2
cmCoreTryCompile: use the source type context for source files
Also add a test to `RunCMake/CXXModules` to test `try_compile` with C++ modules. Fixes: #25097
Diffstat (limited to 'Tests')
-rw-r--r--Tests/RunCMake/CXXModules/RunCMakeTest.cmake2
-rw-r--r--Tests/RunCMake/CXXModules/examples/try-compile-stderr.txt4
-rw-r--r--Tests/RunCMake/CXXModules/examples/try-compile/CMakeLists.txt19
-rw-r--r--Tests/RunCMake/CXXModules/examples/try-compile/importable.cxx6
-rw-r--r--Tests/RunCMake/CXXModules/examples/try-compile/use_importable.cxx6
-rw-r--r--Tests/RunCMake/CXXModules/examples/try-run-stderr.txt4
-rw-r--r--Tests/RunCMake/CXXModules/examples/try-run/CMakeLists.txt23
-rw-r--r--Tests/RunCMake/CXXModules/examples/try-run/importable.cxx6
-rw-r--r--Tests/RunCMake/CXXModules/examples/try-run/main.cxx6
9 files changed, 76 insertions, 0 deletions
diff --git a/Tests/RunCMake/CXXModules/RunCMakeTest.cmake b/Tests/RunCMake/CXXModules/RunCMakeTest.cmake
index d324ec9..25670bd 100644
--- a/Tests/RunCMake/CXXModules/RunCMakeTest.cmake
+++ b/Tests/RunCMake/CXXModules/RunCMakeTest.cmake
@@ -148,6 +148,8 @@ if ("named" IN_LIST CMake_TEST_MODULE_COMPILATION)
run_cxx_module_test(duplicate)
set(RunCMake_CXXModules_NO_TEST 1)
run_cxx_module_test(circular)
+ run_cxx_module_test(try-compile)
+ run_cxx_module_test(try-run)
unset(RunCMake_CXXModules_NO_TEST)
run_cxx_module_test(same-src-name)
run_cxx_module_test(scan_properties)
diff --git a/Tests/RunCMake/CXXModules/examples/try-compile-stderr.txt b/Tests/RunCMake/CXXModules/examples/try-compile-stderr.txt
new file mode 100644
index 0000000..571bb9c
--- /dev/null
+++ b/Tests/RunCMake/CXXModules/examples/try-compile-stderr.txt
@@ -0,0 +1,4 @@
+CMake Warning \(dev\) at CMakeLists.txt:[0-9]* \(try_compile\):
+ 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.
diff --git a/Tests/RunCMake/CXXModules/examples/try-compile/CMakeLists.txt b/Tests/RunCMake/CXXModules/examples/try-compile/CMakeLists.txt
new file mode 100644
index 0000000..dee61f1
--- /dev/null
+++ b/Tests/RunCMake/CXXModules/examples/try-compile/CMakeLists.txt
@@ -0,0 +1,19 @@
+cmake_minimum_required(VERSION 3.24)
+project(cxx_modules_try_compile CXX)
+
+include("${CMAKE_SOURCE_DIR}/../cxx-modules-rules.cmake")
+
+set(CMAKE_TRY_COMPILE_TARGET_TYPE "STATIC_LIBRARY")
+try_compile(can_use_modules
+ SOURCES_TYPE CXX_MODULE
+ SOURCES
+ "${CMAKE_CURRENT_LIST_DIR}/importable.cxx"
+ SOURCES_TYPE NORMAL
+ SOURCE_FROM_FILE
+ use_importable.cxx "${CMAKE_CURRENT_LIST_DIR}/use_importable.cxx"
+ CXX_STANDARD 20)
+
+if (NOT can_use_modules)
+ message(FATAL_ERROR
+ "`try_compile` could not compile sources using modules.")
+endif ()
diff --git a/Tests/RunCMake/CXXModules/examples/try-compile/importable.cxx b/Tests/RunCMake/CXXModules/examples/try-compile/importable.cxx
new file mode 100644
index 0000000..607680a
--- /dev/null
+++ b/Tests/RunCMake/CXXModules/examples/try-compile/importable.cxx
@@ -0,0 +1,6 @@
+export module importable;
+
+export int from_import()
+{
+ return 0;
+}
diff --git a/Tests/RunCMake/CXXModules/examples/try-compile/use_importable.cxx b/Tests/RunCMake/CXXModules/examples/try-compile/use_importable.cxx
new file mode 100644
index 0000000..8d6bab2
--- /dev/null
+++ b/Tests/RunCMake/CXXModules/examples/try-compile/use_importable.cxx
@@ -0,0 +1,6 @@
+import importable;
+
+int foo()
+{
+ return from_import();
+}
diff --git a/Tests/RunCMake/CXXModules/examples/try-run-stderr.txt b/Tests/RunCMake/CXXModules/examples/try-run-stderr.txt
new file mode 100644
index 0000000..508db55
--- /dev/null
+++ b/Tests/RunCMake/CXXModules/examples/try-run-stderr.txt
@@ -0,0 +1,4 @@
+CMake Warning \(dev\) at CMakeLists.txt:[0-9]* \(try_run\):
+ 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.
diff --git a/Tests/RunCMake/CXXModules/examples/try-run/CMakeLists.txt b/Tests/RunCMake/CXXModules/examples/try-run/CMakeLists.txt
new file mode 100644
index 0000000..fb03571
--- /dev/null
+++ b/Tests/RunCMake/CXXModules/examples/try-run/CMakeLists.txt
@@ -0,0 +1,23 @@
+cmake_minimum_required(VERSION 3.24)
+project(cxx_modules_try_run CXX)
+
+include("${CMAKE_SOURCE_DIR}/../cxx-modules-rules.cmake")
+
+try_run(can_run_modules_result can_compile_modules
+ SOURCES_TYPE CXX_MODULE
+ SOURCES
+ "${CMAKE_CURRENT_LIST_DIR}/importable.cxx"
+ SOURCES_TYPE NORMAL
+ SOURCE_FROM_FILE
+ main.cxx "${CMAKE_CURRENT_LIST_DIR}/main.cxx"
+ CXX_STANDARD 20)
+
+if (NOT can_compile_modules)
+ message(FATAL_ERROR
+ "`try_run` could not compile sources using modules.")
+endif ()
+
+if (can_run_modules_result)
+ message(FATAL_ERROR
+ "`try_run` could not run sources using modules.")
+endif ()
diff --git a/Tests/RunCMake/CXXModules/examples/try-run/importable.cxx b/Tests/RunCMake/CXXModules/examples/try-run/importable.cxx
new file mode 100644
index 0000000..607680a
--- /dev/null
+++ b/Tests/RunCMake/CXXModules/examples/try-run/importable.cxx
@@ -0,0 +1,6 @@
+export module importable;
+
+export int from_import()
+{
+ return 0;
+}
diff --git a/Tests/RunCMake/CXXModules/examples/try-run/main.cxx b/Tests/RunCMake/CXXModules/examples/try-run/main.cxx
new file mode 100644
index 0000000..5c1bb42
--- /dev/null
+++ b/Tests/RunCMake/CXXModules/examples/try-run/main.cxx
@@ -0,0 +1,6 @@
+import importable;
+
+int main(int argc, char* argv[])
+{
+ return from_import() == 1;
+}