4 cmake_policy(SET CMP0057 NEW)
6 run_cmake(compiler_introspection)
7 include("${RunCMake_BINARY_DIR}/compiler_introspection-build/info.cmake")
9 # Test negative cases where C++20 modules do not work.
11 if ("cxx_std_20" IN_LIST CMAKE_CXX_COMPILE_FEATURES)
12 # This test requires that the compiler be told to compile in an older-than-20
13 # standard. If the compiler forces a standard to be used, skip it.
14 if (NOT forced_cxx_standard)
18 # This test uses C++20, but another prerequisite is missing, so forced
19 # standards don't matter.
20 run_cmake(NoCXX20ModuleFlag)
23 if (RunCMake_GENERATOR MATCHES "Ninja")
25 COMMAND "${CMAKE_MAKE_PROGRAM}" --version
27 OUTPUT_VARIABLE ninja_version
29 OUTPUT_STRIP_TRAILING_WHITESPACE
30 ERROR_STRIP_TRAILING_WHITESPACE)
34 "Failed to determine `ninja` version: ${err}")
35 set(ninja_version "0")
39 # Test behavior when the generator does not support C++20 modules.
40 if (NOT RunCMake_GENERATOR MATCHES "Ninja" OR
41 ninja_version VERSION_LESS "1.10" OR
42 NOT "cxx_std_20" IN_LIST CMAKE_CXX_COMPILE_FEATURES)
43 if ("cxx_std_20" IN_LIST CMAKE_CXX_COMPILE_FEATURES)
44 run_cmake(NoDyndepSupport)
47 # Bail; the remaining tests require the generator to successfully generate
48 # with C++20 modules in the source list.
59 foreach (fileset_type IN LISTS fileset_types)
60 foreach (scope IN LISTS scopes)
61 run_cmake("FileSet${fileset_type}${scope}")
63 run_cmake("FileSet${fileset_type}InterfaceImported")
65 # Test the error message when a non-C++ source file is found in the source
67 run_cmake("NotCXXSource${fileset_type}")
71 run_cmake(InstallBMIGenericArgs)
72 run_cmake(InstallBMIIgnore)
74 run_cmake(ExportBuildCxxModules)
75 run_cmake(ExportInstallCxxModules)
77 # Generator-specific tests.
78 if (RunCMake_GENERATOR MATCHES "Ninja")
79 run_cmake(NinjaDependInfoFileSet)
80 run_cmake(NinjaDependInfoExport)
81 run_cmake(NinjaDependInfoBMIInstall)
84 "Please add 'DependInfo' tests for the '${RunCMake_GENERATOR}' generator.")
87 # Actual compilation tests.
88 if (NOT CMake_TEST_MODULE_COMPILATION)
92 function (run_cxx_module_test directory)
93 set(test_name "${directory}")
94 if (NOT ARGN STREQUAL "")
95 list(POP_FRONT ARGN test_name)
98 set(RunCMake_TEST_SOURCE_DIR "${CMAKE_CURRENT_LIST_DIR}/examples/${directory}")
99 set(RunCMake_TEST_BINARY_DIR "${RunCMake_BINARY_DIR}/examples/${test_name}-build")
101 if (RunCMake_GENERATOR_IS_MULTI_CONFIG)
102 set(RunCMake_TEST_OPTIONS -DCMAKE_CONFIGURATION_TYPES=Debug)
104 set(RunCMake_TEST_OPTIONS -DCMAKE_BUILD_TYPE=Debug)
107 if (RunCMake_CXXModules_INSTALL)
108 set(prefix "${RunCMake_BINARY_DIR}/examples/${test_name}-install")
109 file(REMOVE_RECURSE "${prefix}")
110 list(APPEND RunCMake_TEST_OPTIONS
111 "-DCMAKE_INSTALL_PREFIX=${prefix}")
114 list(APPEND RunCMake_TEST_OPTIONS
115 "-DCMake_TEST_MODULE_COMPILATION_RULES=${CMake_TEST_MODULE_COMPILATION_RULES}"
117 run_cmake("examples/${test_name}")
118 set(RunCMake_TEST_NO_CLEAN 1)
119 run_cmake_command("examples/${test_name}-build" "${CMAKE_COMMAND}" --build . --config Debug)
120 if (RunCMake_CXXModules_INSTALL)
121 run_cmake_command("examples/${test_name}-install" "${CMAKE_COMMAND}" --build . --target install --config Debug)
123 run_cmake_command("examples/${test_name}-test" "${CMAKE_CTEST_COMMAND}" -C Debug --output-on-failure)
126 string(REPLACE "," ";" CMake_TEST_MODULE_COMPILATION "${CMake_TEST_MODULE_COMPILATION}")
128 # Tests which use named modules.
129 if ("named" IN_LIST CMake_TEST_MODULE_COMPILATION)
130 run_cxx_module_test(simple)
131 run_cxx_module_test(library library-static -DBUILD_SHARED_LIBS=OFF)
132 run_cxx_module_test(generated)
133 run_cxx_module_test(public-req-private)
134 run_cxx_module_test(deep-chain)
137 # Tests which use named modules in shared libraries.
138 if ("shared" IN_LIST CMake_TEST_MODULE_COMPILATION)
139 run_cxx_module_test(library library-shared -DBUILD_SHARED_LIBS=ON)
142 # Tests which use partitions.
143 if ("partitions" IN_LIST CMake_TEST_MODULE_COMPILATION)
144 run_cxx_module_test(partitions)
147 # Tests which use internal partitions.
148 if ("internal_partitions" IN_LIST CMake_TEST_MODULE_COMPILATION)
149 run_cxx_module_test(internal-partitions)
152 # Tests which install BMIs
153 if ("export_bmi" IN_LIST CMake_TEST_MODULE_COMPILATION)
154 run_cxx_module_test(export-interface-build)
155 run_cxx_module_test(export-bmi-and-interface-build)
158 # All of the following tests perform installation.
159 set(RunCMake_CXXModules_INSTALL 1)
161 # Tests which install BMIs
162 if ("install_bmi" IN_LIST CMake_TEST_MODULE_COMPILATION)
163 run_cxx_module_test(install-bmi)
164 run_cxx_module_test(install-bmi-and-interfaces)
166 if ("export_bmi" IN_LIST CMake_TEST_MODULE_COMPILATION)
167 run_cxx_module_test(export-interface-install)
168 run_cxx_module_test(export-bmi-and-interface-install)