summaryrefslogtreecommitdiffstats
path: root/Tests/RunCMake/CXXModules
diff options
context:
space:
mode:
authorBen Boeckel <ben.boeckel@kitware.com>2023-07-02 22:44:17 (GMT)
committerBen Boeckel <ben.boeckel@kitware.com>2023-07-09 15:04:29 (GMT)
commit677b28dc7b28feda9efb15ae27a267ec5d709b44 (patch)
treec861b020877fd5f52bc680e6ac523e1a2ab383a3 /Tests/RunCMake/CXXModules
parentb384058e4ba77defdff8741db636f60d6843d87d (diff)
downloadCMake-677b28dc7b28feda9efb15ae27a267ec5d709b44.zip
CMake-677b28dc7b28feda9efb15ae27a267ec5d709b44.tar.gz
CMake-677b28dc7b28feda9efb15ae27a267ec5d709b44.tar.bz2
Ninja: include module mapper flags in `compile_commands.json`
Fixes: #24618
Diffstat (limited to 'Tests/RunCMake/CXXModules')
-rw-r--r--Tests/RunCMake/CXXModules/RunCMakeTest.cmake5
-rw-r--r--Tests/RunCMake/CXXModules/examples/export-compile-commands-check.cmake25
-rw-r--r--Tests/RunCMake/CXXModules/examples/export-compile-commands-stderr.txt4
-rw-r--r--Tests/RunCMake/CXXModules/examples/export-compile-commands/CMakeLists.txt20
-rw-r--r--Tests/RunCMake/CXXModules/examples/export-compile-commands/importable.cxx6
-rw-r--r--Tests/RunCMake/CXXModules/examples/export-compile-commands/main.cxx6
6 files changed, 66 insertions, 0 deletions
diff --git a/Tests/RunCMake/CXXModules/RunCMakeTest.cmake b/Tests/RunCMake/CXXModules/RunCMakeTest.cmake
index ada0c65..1009ce4 100644
--- a/Tests/RunCMake/CXXModules/RunCMakeTest.cmake
+++ b/Tests/RunCMake/CXXModules/RunCMakeTest.cmake
@@ -152,6 +152,11 @@ if ("named" IN_LIST CMake_TEST_MODULE_COMPILATION)
run_cxx_module_test(scan_properties)
endif ()
+# Tests which require compile commands support.
+if ("compile_commands" IN_LIST CMake_TEST_MODULE_COMPILATION)
+ run_cxx_module_test(export-compile-commands)
+endif ()
+
# Tests which require collation work.
if ("collation" IN_LIST CMake_TEST_MODULE_COMPILATION)
run_cxx_module_test(public-req-private)
diff --git a/Tests/RunCMake/CXXModules/examples/export-compile-commands-check.cmake b/Tests/RunCMake/CXXModules/examples/export-compile-commands-check.cmake
new file mode 100644
index 0000000..5d7224b
--- /dev/null
+++ b/Tests/RunCMake/CXXModules/examples/export-compile-commands-check.cmake
@@ -0,0 +1,25 @@
+if (NOT EXISTS "${RunCMake_TEST_BINARY_DIR}/compile_commands.json")
+ list(APPEND RunCMake_TEST_FAILED
+ "No compile commands database detected.")
+endif ()
+
+file(READ "${RunCMake_TEST_BINARY_DIR}/compile_commands.json" compile_commands)
+
+string(JSON length
+ LENGTH "${compile_commands}")
+math(EXPR length "${length} - 1")
+foreach (item RANGE "${length}")
+ string(JSON entry
+ GET "${compile_commands}"
+ "${item}")
+ string(JSON command
+ GET "${entry}"
+ "command")
+ if (NOT command MATCHES "(@|-fmodule-mapper=).*\\.modmap")
+ string(JSON output
+ GET "${entry}"
+ "output")
+ list(APPEND RunCMake_TEST_FAILED
+ "Missing `.modmap` argument for '${output}'")
+ endif ()
+endforeach ()
diff --git a/Tests/RunCMake/CXXModules/examples/export-compile-commands-stderr.txt b/Tests/RunCMake/CXXModules/examples/export-compile-commands-stderr.txt
new file mode 100644
index 0000000..e868787
--- /dev/null
+++ b/Tests/RunCMake/CXXModules/examples/export-compile-commands-stderr.txt
@@ -0,0 +1,4 @@
+CMake Warning \(dev\) at CMakeLists.txt:9 \(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.
diff --git a/Tests/RunCMake/CXXModules/examples/export-compile-commands/CMakeLists.txt b/Tests/RunCMake/CXXModules/examples/export-compile-commands/CMakeLists.txt
new file mode 100644
index 0000000..2eb4d5f
--- /dev/null
+++ b/Tests/RunCMake/CXXModules/examples/export-compile-commands/CMakeLists.txt
@@ -0,0 +1,20 @@
+cmake_minimum_required(VERSION 3.24)
+project(cxx_modules_export_compile_commands CXX)
+
+include("${CMAKE_SOURCE_DIR}/../cxx-modules-rules.cmake")
+
+set(CMAKE_EXPORT_COMPILE_COMMANDS 1)
+
+add_executable(export-compile-commands)
+target_sources(export-compile-commands
+ PRIVATE
+ main.cxx
+ PRIVATE
+ FILE_SET CXX_MODULES
+ BASE_DIRS
+ "${CMAKE_CURRENT_SOURCE_DIR}"
+ FILES
+ importable.cxx)
+target_compile_features(export-compile-commands PUBLIC cxx_std_20)
+
+add_test(NAME export-compile-commands COMMAND export-compile-commands)
diff --git a/Tests/RunCMake/CXXModules/examples/export-compile-commands/importable.cxx b/Tests/RunCMake/CXXModules/examples/export-compile-commands/importable.cxx
new file mode 100644
index 0000000..607680a
--- /dev/null
+++ b/Tests/RunCMake/CXXModules/examples/export-compile-commands/importable.cxx
@@ -0,0 +1,6 @@
+export module importable;
+
+export int from_import()
+{
+ return 0;
+}
diff --git a/Tests/RunCMake/CXXModules/examples/export-compile-commands/main.cxx b/Tests/RunCMake/CXXModules/examples/export-compile-commands/main.cxx
new file mode 100644
index 0000000..feb38d2
--- /dev/null
+++ b/Tests/RunCMake/CXXModules/examples/export-compile-commands/main.cxx
@@ -0,0 +1,6 @@
+import importable;
+
+int main(int argc, char* argv[])
+{
+ return from_import();
+}