summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2024-02-19 14:23:58 (GMT)
committerBrad King <brad.king@kitware.com>2024-02-19 14:23:58 (GMT)
commit00d908a01f2bd3ea7349757b0b8202e3239c7461 (patch)
tree1e46f8ba5c93447372df7d91750d7d24ccb1aa71
parentfb0988a276438f68f0d4d6b17a1ed381a050d6d0 (diff)
parent5261af94248153b66d30504bd67e288c25aad7f1 (diff)
downloadCMake-00d908a01f2bd3ea7349757b0b8202e3239c7461.zip
CMake-00d908a01f2bd3ea7349757b0b8202e3239c7461.tar.gz
CMake-00d908a01f2bd3ea7349757b0b8202e3239c7461.tar.bz2
Merge topic 'cxxmodules-nmc-duplicate-synthetic-targets' into release-3.28
5261af9424 cmGeneratorTarget: store synthetic targets in its cache e0633a9517 Tests/CXXModules: add a test importing from a `Ninja` install 150d7dbd68 Tests/CXXModules: support building a project with `Ninja` e48e5e5506 Tests/CXXModules: document `CMake_TEST_MODULE_COMPILATION` items Acked-by: Kitware Robot <kwrobot@kitware.com> Merge-request: !9263
-rw-r--r--Source/cmGeneratorTarget.cxx1
-rw-r--r--Tests/RunCMake/CXXModules/RunCMakeTest.cmake45
-rw-r--r--Tests/RunCMake/CXXModules/examples/export-modules-from-ninja/CMakeLists.txt41
-rw-r--r--Tests/RunCMake/CXXModules/examples/export-modules-from-ninja/forward.cxx6
-rw-r--r--Tests/RunCMake/CXXModules/examples/export-modules-from-ninja/importable.cxx10
-rw-r--r--Tests/RunCMake/CXXModules/examples/export-modules-from-ninja/no_modules.cxx3
-rw-r--r--Tests/RunCMake/CXXModules/examples/export-modules-from-ninja/private.cxx6
-rw-r--r--Tests/RunCMake/CXXModules/examples/export-modules-from-ninja/subdir/importable.cxx6
-rw-r--r--Tests/RunCMake/CXXModules/examples/import-modules/CMakeLists.txt2
9 files changed, 120 insertions, 0 deletions
diff --git a/Source/cmGeneratorTarget.cxx b/Source/cmGeneratorTarget.cxx
index 5b7f526..3cfa5a9 100644
--- a/Source/cmGeneratorTarget.cxx
+++ b/Source/cmGeneratorTarget.cxx
@@ -8379,6 +8379,7 @@ bool cmGeneratorTarget::DiscoverSyntheticTargets(cmSyntheticTargetCache& cache,
// Create the generator target and attach it to the local generator.
auto gtp = cm::make_unique<cmGeneratorTarget>(tgt, lg);
synthDep = gtp.get();
+ cache.CxxModuleTargets[targetName] = synthDep;
lg->AddGeneratorTarget(std::move(gtp));
} else {
synthDep = cached->second;
diff --git a/Tests/RunCMake/CXXModules/RunCMakeTest.cmake b/Tests/RunCMake/CXXModules/RunCMakeTest.cmake
index 421c509..aaf289c 100644
--- a/Tests/RunCMake/CXXModules/RunCMakeTest.cmake
+++ b/Tests/RunCMake/CXXModules/RunCMakeTest.cmake
@@ -168,7 +168,25 @@ function (run_cxx_module_test_rebuild directory)
run_cxx_module_test("${directory}" ${ARGN})
endfunction ()
+# Module compilation features:
+# Compiler-based:
+# - `named`: basic support for named modules is available
+# - `shared`: shared libraries are supported
+# - `partitions`: module partitions are supported
+# - `internal_partitions`: internal module partitions are supported
+# - `bmionly`: the compiler supports BMI-only builds
+#
+# Generator-based:
+# - `compile_commands`: the generator supports `compile_commands.json`
+# - `collation`: the generator supports module collation features
+# - `export_bmi`: the generator supports exporting BMIs
+# - `ninja`: a `ninja` binary is available to perform `Ninja`-only testing
+# (assumed if the generator matches `Ninja`).
string(REPLACE "," ";" CMake_TEST_MODULE_COMPILATION "${CMake_TEST_MODULE_COMPILATION}")
+if (RunCMake_GENERATOR MATCHES "Ninja")
+ list(APPEND CMake_TEST_MODULE_COMPILATION
+ "ninja")
+endif ()
if (RunCMake_GENERATOR MATCHES "Ninja")
if (RunCMake_GENERATOR_IS_MULTI_CONFIG)
@@ -294,3 +312,30 @@ if ("install_bmi" IN_LIST CMake_TEST_MODULE_COMPILATION)
endif ()
endif ()
endif ()
+
+# All remaining tests require a working `Ninja` generator to set up a test case
+# for the current generator.
+if (NOT "ninja" IN_LIST CMake_TEST_MODULE_COMPILATION)
+ return ()
+endif ()
+# All remaining tests require `bmionly` in order to consume from the `ninja`
+# build.
+if (NOT "bmionly" IN_LIST CMake_TEST_MODULE_COMPILATION)
+ return ()
+endif ()
+
+function (run_cxx_module_test_ninja directory)
+ set(RunCMake_GENERATOR "Ninja")
+ set(RunCMake_CXXModules_NO_TEST 1)
+ set(RunCMake_CXXModules_INSTALL 1)
+ # `Ninja` is not a multi-config generator.
+ set(RunCMake_GENERATOR_IS_MULTI_CONFIG 0)
+ run_cxx_module_test("${directory}" "${directory}-ninja" ${ARGN})
+endfunction ()
+
+# Installation happens within `run_cxx_module_test_ninja`.
+set(RunCMake_CXXModules_INSTALL 0)
+
+set(test_set modules-from-ninja)
+run_cxx_module_test_ninja("export-${test_set}")
+run_cxx_module_test(import-modules "import-${test_set}" "-DCMAKE_PREFIX_PATH=${RunCMake_BINARY_DIR}/examples/export-${test_set}-ninja-install" -DFROM_NINJA=1)
diff --git a/Tests/RunCMake/CXXModules/examples/export-modules-from-ninja/CMakeLists.txt b/Tests/RunCMake/CXXModules/examples/export-modules-from-ninja/CMakeLists.txt
new file mode 100644
index 0000000..6036fde
--- /dev/null
+++ b/Tests/RunCMake/CXXModules/examples/export-modules-from-ninja/CMakeLists.txt
@@ -0,0 +1,41 @@
+cmake_minimum_required(VERSION 3.24...3.28)
+project(cxx_modules_export_from_ninja CXX)
+
+include("${CMAKE_SOURCE_DIR}/../cxx-modules-rules.cmake")
+
+add_library(export_from_ninja STATIC)
+target_sources(export_from_ninja
+ PRIVATE
+ forward.cxx
+ PRIVATE
+ FILE_SET modules_private TYPE CXX_MODULES
+ BASE_DIRS
+ "${CMAKE_CURRENT_SOURCE_DIR}"
+ FILES
+ private.cxx
+ PUBLIC
+ FILE_SET modules TYPE CXX_MODULES
+ BASE_DIRS
+ "${CMAKE_CURRENT_SOURCE_DIR}"
+ FILES
+ importable.cxx
+ subdir/importable.cxx
+ )
+target_compile_features(export_from_ninja PUBLIC cxx_std_20)
+
+add_library(no_modules STATIC no_modules.cxx)
+
+install(TARGETS export_from_ninja no_modules
+ EXPORT CXXModules
+ FILE_SET modules DESTINATION "lib/cxx/miu")
+install(EXPORT CXXModules
+ NAMESPACE CXXModules::
+ DESTINATION "lib/cmake/export_from_ninja"
+ FILE "export_from_ninja-targets.cmake"
+ CXX_MODULES_DIRECTORY "export_from_ninja-cxx-modules")
+file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/export_from_ninja-config.cmake"
+ "include(\"\${CMAKE_CURRENT_LIST_DIR}/export_from_ninja-targets.cmake\")
+set(\${CMAKE_FIND_PACKAGE_NAME}_FOUND 1)
+")
+install(FILES "${CMAKE_CURRENT_BINARY_DIR}/export_from_ninja-config.cmake"
+ DESTINATION "lib/cmake/export_from_ninja")
diff --git a/Tests/RunCMake/CXXModules/examples/export-modules-from-ninja/forward.cxx b/Tests/RunCMake/CXXModules/examples/export-modules-from-ninja/forward.cxx
new file mode 100644
index 0000000..7f53271
--- /dev/null
+++ b/Tests/RunCMake/CXXModules/examples/export-modules-from-ninja/forward.cxx
@@ -0,0 +1,6 @@
+import priv;
+
+int forwarding()
+{
+ return from_private();
+}
diff --git a/Tests/RunCMake/CXXModules/examples/export-modules-from-ninja/importable.cxx b/Tests/RunCMake/CXXModules/examples/export-modules-from-ninja/importable.cxx
new file mode 100644
index 0000000..8dfc41b
--- /dev/null
+++ b/Tests/RunCMake/CXXModules/examples/export-modules-from-ninja/importable.cxx
@@ -0,0 +1,10 @@
+export module importable;
+
+extern "C++" {
+int forwarding();
+}
+
+export int from_import()
+{
+ return forwarding();
+}
diff --git a/Tests/RunCMake/CXXModules/examples/export-modules-from-ninja/no_modules.cxx b/Tests/RunCMake/CXXModules/examples/export-modules-from-ninja/no_modules.cxx
new file mode 100644
index 0000000..eea854f
--- /dev/null
+++ b/Tests/RunCMake/CXXModules/examples/export-modules-from-ninja/no_modules.cxx
@@ -0,0 +1,3 @@
+void no_modules()
+{
+}
diff --git a/Tests/RunCMake/CXXModules/examples/export-modules-from-ninja/private.cxx b/Tests/RunCMake/CXXModules/examples/export-modules-from-ninja/private.cxx
new file mode 100644
index 0000000..c5b719a
--- /dev/null
+++ b/Tests/RunCMake/CXXModules/examples/export-modules-from-ninja/private.cxx
@@ -0,0 +1,6 @@
+export module priv;
+
+export int from_private()
+{
+ return 0;
+}
diff --git a/Tests/RunCMake/CXXModules/examples/export-modules-from-ninja/subdir/importable.cxx b/Tests/RunCMake/CXXModules/examples/export-modules-from-ninja/subdir/importable.cxx
new file mode 100644
index 0000000..07d6af6
--- /dev/null
+++ b/Tests/RunCMake/CXXModules/examples/export-modules-from-ninja/subdir/importable.cxx
@@ -0,0 +1,6 @@
+export module subdir_importable;
+
+export int from_subdir()
+{
+ return 0;
+}
diff --git a/Tests/RunCMake/CXXModules/examples/import-modules/CMakeLists.txt b/Tests/RunCMake/CXXModules/examples/import-modules/CMakeLists.txt
index 8e1db5d..16bc6d8 100644
--- a/Tests/RunCMake/CXXModules/examples/import-modules/CMakeLists.txt
+++ b/Tests/RunCMake/CXXModules/examples/import-modules/CMakeLists.txt
@@ -9,6 +9,8 @@ elseif (WITH_BMIS)
set(package_name "export_bmi_and_interfaces")
elseif (INCLUDE_PROPERTIES)
set(package_name "export_include_directories")
+elseif (FROM_NINJA)
+ set(package_name "export_from_ninja")
else ()
set(package_name "export_interfaces")
endif ()