diff options
author | Ben Boeckel <ben.boeckel@kitware.com> | 2024-02-16 22:28:55 (GMT) |
---|---|---|
committer | Ben Boeckel <ben.boeckel@kitware.com> | 2024-02-20 15:53:31 (GMT) |
commit | a2e3e61a3189f56668364aa79cae97da1830231f (patch) | |
tree | fed1741478150cb8c040a38a9f32926c3668dd57 | |
parent | 583641ac92b83f91341e701c057ec5e6da8eb8fc (diff) | |
download | CMake-a2e3e61a3189f56668364aa79cae97da1830231f.zip CMake-a2e3e61a3189f56668364aa79cae97da1830231f.tar.gz CMake-a2e3e61a3189f56668364aa79cae97da1830231f.tar.bz2 |
Tests/CXXModules: test transitive modules usage
14 files changed, 294 insertions, 0 deletions
diff --git a/Tests/RunCMake/CXXModules/RunCMakeTest.cmake b/Tests/RunCMake/CXXModules/RunCMakeTest.cmake index 2f91d6a..ece190c 100644 --- a/Tests/RunCMake/CXXModules/RunCMakeTest.cmake +++ b/Tests/RunCMake/CXXModules/RunCMakeTest.cmake @@ -263,6 +263,8 @@ if ("export_bmi" IN_LIST CMake_TEST_MODULE_COMPILATION) run_cxx_module_test(export-usage-build) run_cxx_module_test(export-bmi-and-interface-build) run_cxx_module_test(export-transitive-targets-build) + run_cxx_module_test(export-transitive-modules1-build) + run_cxx_module_test(export-transitive-modules-build export-transitive-modules-build "-DCMAKE_PREFIX_PATH=${RunCMake_BINARY_DIR}/examples/export-transitive-modules1-build-build" ) if ("collation" IN_LIST CMake_TEST_MODULE_COMPILATION AND "bmionly" IN_LIST CMake_TEST_MODULE_COMPILATION) @@ -280,6 +282,9 @@ if ("export_bmi" IN_LIST CMake_TEST_MODULE_COMPILATION) set(test_suffix export-transitive-targets-build) run_cxx_module_test(import-modules "import-modules-${test_suffix}" "-DCMAKE_PREFIX_PATH=${RunCMake_BINARY_DIR}/examples/${test_suffix}-build" -DTRANSITIVE_TARGETS=1) + + set(test_suffix export-transitive-modules-build) + run_cxx_module_test(import-modules "import-modules-${test_suffix}" "-DCMAKE_PREFIX_PATH=${RunCMake_BINARY_DIR}/examples/${test_suffix}-build" -DTRANSITIVE_MODULES=1) endif () endif () @@ -298,6 +303,8 @@ if ("install_bmi" IN_LIST CMake_TEST_MODULE_COMPILATION) run_cxx_module_test(export-usage-install) run_cxx_module_test(export-bmi-and-interface-install) run_cxx_module_test(export-transitive-targets-install) + run_cxx_module_test(export-transitive-modules1-install) + run_cxx_module_test(export-transitive-modules-install export-transitive-modules-install "-DCMAKE_PREFIX_PATH=${RunCMake_BINARY_DIR}/examples/export-transitive-modules1-install-install" ) if ("collation" IN_LIST CMake_TEST_MODULE_COMPILATION AND "bmionly" IN_LIST CMake_TEST_MODULE_COMPILATION) @@ -316,6 +323,9 @@ if ("install_bmi" IN_LIST CMake_TEST_MODULE_COMPILATION) set(test_suffix export-transitive-targets-install) run_cxx_module_test(import-modules "import-modules-${test_suffix}" "-DCMAKE_PREFIX_PATH=${RunCMake_BINARY_DIR}/examples/${test_suffix}-install" -DTRANSITIVE_TARGETS=1) + + set(test_suffix export-transitive-modules-install) + run_cxx_module_test(import-modules "import-modules-${test_suffix}" "-DCMAKE_PREFIX_PATH=${RunCMake_BINARY_DIR}/examples/${test_suffix}-install" -DTRANSITIVE_MODULES=1) set(RunCMake_CXXModules_INSTALL 1) endif () endif () diff --git a/Tests/RunCMake/CXXModules/examples/export-transitive-modules-build/CMakeLists.txt b/Tests/RunCMake/CXXModules/examples/export-transitive-modules-build/CMakeLists.txt new file mode 100644 index 0000000..3610d93 --- /dev/null +++ b/Tests/RunCMake/CXXModules/examples/export-transitive-modules-build/CMakeLists.txt @@ -0,0 +1,54 @@ +cmake_minimum_required(VERSION 3.24...3.28) +project(cxx_modules_export_transitive_modules CXX) + +include("${CMAKE_SOURCE_DIR}/../cxx-modules-rules.cmake") + +find_package(export_transitive_modules1 REQUIRED) + +add_library(export_transitive_modules STATIC) +target_sources(export_transitive_modules + PUBLIC + FILE_SET modules TYPE CXX_MODULES + BASE_DIRS + "${CMAKE_CURRENT_SOURCE_DIR}" + FILES + importable.cxx + ) +target_compile_features(export_transitive_modules PUBLIC cxx_std_20) +target_link_libraries(export_transitive_modules PRIVATE CXXModules::export_transitive_modules1) + +install(TARGETS export_transitive_modules + EXPORT CXXModules + FILE_SET modules DESTINATION "lib/cxx/miu") +export(EXPORT CXXModules + NAMESPACE CXXModules:: + FILE "${CMAKE_CURRENT_BINARY_DIR}/export_transitive_modules-targets.cmake" + CXX_MODULES_DIRECTORY "export_transitive_modules-cxx-modules") +file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/export_transitive_modules-config.cmake" + "include(CMakeFindDependencyMacro) +set(export_transitive_modules1_DIR \"${export_transitive_modules1_DIR}\") +find_dependency(export_transitive_modules1) +include(\"\${CMAKE_CURRENT_LIST_DIR}/export_transitive_modules-targets.cmake\") +set(\${CMAKE_FIND_PACKAGE_NAME}_FOUND 1) +") + +set(generator + -G "${CMAKE_GENERATOR}") +if (CMAKE_GENERATOR_TOOLSET) + list(APPEND generator + -T "${CMAKE_GENERATOR_TOOLSET}") +endif () +if (CMAKE_GENERATOR_PLATFORM) + list(APPEND generator + -A "${CMAKE_GENERATOR_PLATFORM}") +endif () + +add_test(NAME export_transitive_modules_build + COMMAND + "${CMAKE_COMMAND}" + "-Dexpected_source_dir=${CMAKE_CURRENT_SOURCE_DIR}" + "-Dexpected_binary_dir=${CMAKE_CURRENT_BINARY_DIR}" + "-Dexport_transitive_modules_DIR=${CMAKE_CURRENT_BINARY_DIR}" + ${generator} + -S "${CMAKE_CURRENT_SOURCE_DIR}/test" + -B "${CMAKE_CURRENT_BINARY_DIR}/test") diff --git a/Tests/RunCMake/CXXModules/examples/export-transitive-modules-build/importable.cxx b/Tests/RunCMake/CXXModules/examples/export-transitive-modules-build/importable.cxx new file mode 100644 index 0000000..73133ea --- /dev/null +++ b/Tests/RunCMake/CXXModules/examples/export-transitive-modules-build/importable.cxx @@ -0,0 +1,7 @@ +export module importable; +import module1; + +export int from_import() +{ + return from_inner_import(); +} diff --git a/Tests/RunCMake/CXXModules/examples/export-transitive-modules-build/test/CMakeLists.txt b/Tests/RunCMake/CXXModules/examples/export-transitive-modules-build/test/CMakeLists.txt new file mode 100644 index 0000000..c8ee9f0 --- /dev/null +++ b/Tests/RunCMake/CXXModules/examples/export-transitive-modules-build/test/CMakeLists.txt @@ -0,0 +1,14 @@ +cmake_minimum_required(VERSION 3.28) +project(cxx_modules_library NONE) + +find_package(export_transitive_modules REQUIRED) + +if (NOT TARGET CXXModules::export_transitive_modules1) + message(FATAL_ERROR + "Missing transitive imported target") +endif () + +if (NOT TARGET CXXModules::export_transitive_modules) + message(FATAL_ERROR + "Missing imported target") +endif () diff --git a/Tests/RunCMake/CXXModules/examples/export-transitive-modules-install/CMakeLists.txt b/Tests/RunCMake/CXXModules/examples/export-transitive-modules-install/CMakeLists.txt new file mode 100644 index 0000000..3076ffc --- /dev/null +++ b/Tests/RunCMake/CXXModules/examples/export-transitive-modules-install/CMakeLists.txt @@ -0,0 +1,57 @@ +cmake_minimum_required(VERSION 3.24...3.28) +project(cxx_modules_export_transitive_modules CXX) + +include("${CMAKE_SOURCE_DIR}/../cxx-modules-rules.cmake") + +find_package(export_transitive_modules1 REQUIRED) + +add_library(export_transitive_modules STATIC) +target_sources(export_transitive_modules + PUBLIC + FILE_SET modules TYPE CXX_MODULES + BASE_DIRS + "${CMAKE_CURRENT_SOURCE_DIR}" + FILES + importable.cxx + ) +target_compile_features(export_transitive_modules PUBLIC cxx_std_20) +target_link_libraries(export_transitive_modules PRIVATE CXXModules::export_transitive_modules1) + +install(TARGETS export_transitive_modules + EXPORT CXXModules + FILE_SET modules DESTINATION "lib/cxx/miu") +install(EXPORT CXXModules + NAMESPACE CXXModules:: + DESTINATION "lib/cmake/export_transitive_modules" + FILE "export_transitive_modules-targets.cmake" + CXX_MODULES_DIRECTORY "export_transitive_modules-cxx-modules") +file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/export_transitive_modules-config.cmake" + "include(CMakeFindDependencyMacro) +set(export_transitive_modules1_DIR \"${export_transitive_modules1_DIR}\") +find_dependency(export_transitive_modules1) +include(\"\${CMAKE_CURRENT_LIST_DIR}/export_transitive_modules-targets.cmake\") +set(\${CMAKE_FIND_PACKAGE_NAME}_FOUND 1) +") +install(FILES "${CMAKE_CURRENT_BINARY_DIR}/export_transitive_modules-config.cmake" + DESTINATION "lib/cmake/export_transitive_modules") + +set(generator + -G "${CMAKE_GENERATOR}") +if (CMAKE_GENERATOR_TOOLSET) + list(APPEND generator + -T "${CMAKE_GENERATOR_TOOLSET}") +endif () +if (CMAKE_GENERATOR_PLATFORM) + list(APPEND generator + -A "${CMAKE_GENERATOR_PLATFORM}") +endif () + +add_test(NAME export_transitive_modules_build + COMMAND + "${CMAKE_COMMAND}" + "-Dexpected_source_dir=${CMAKE_INSTALL_PREFIX}/lib/cxx/miu" + "-Dexpected_binary_dir=${CMAKE_INSTALL_PREFIX}/lib/cxx/bmi" + "-Dexport_transitive_modules_DIR=${CMAKE_INSTALL_PREFIX}/lib/cmake/export_transitive_modules" + ${generator} + -S "${CMAKE_CURRENT_SOURCE_DIR}/test" + -B "${CMAKE_CURRENT_BINARY_DIR}/test") diff --git a/Tests/RunCMake/CXXModules/examples/export-transitive-modules-install/importable.cxx b/Tests/RunCMake/CXXModules/examples/export-transitive-modules-install/importable.cxx new file mode 100644 index 0000000..73133ea --- /dev/null +++ b/Tests/RunCMake/CXXModules/examples/export-transitive-modules-install/importable.cxx @@ -0,0 +1,7 @@ +export module importable; +import module1; + +export int from_import() +{ + return from_inner_import(); +} diff --git a/Tests/RunCMake/CXXModules/examples/export-transitive-modules-install/test/CMakeLists.txt b/Tests/RunCMake/CXXModules/examples/export-transitive-modules-install/test/CMakeLists.txt new file mode 100644 index 0000000..c8ee9f0 --- /dev/null +++ b/Tests/RunCMake/CXXModules/examples/export-transitive-modules-install/test/CMakeLists.txt @@ -0,0 +1,14 @@ +cmake_minimum_required(VERSION 3.28) +project(cxx_modules_library NONE) + +find_package(export_transitive_modules REQUIRED) + +if (NOT TARGET CXXModules::export_transitive_modules1) + message(FATAL_ERROR + "Missing transitive imported target") +endif () + +if (NOT TARGET CXXModules::export_transitive_modules) + message(FATAL_ERROR + "Missing imported target") +endif () diff --git a/Tests/RunCMake/CXXModules/examples/export-transitive-modules1-build/CMakeLists.txt b/Tests/RunCMake/CXXModules/examples/export-transitive-modules1-build/CMakeLists.txt new file mode 100644 index 0000000..0a70abd --- /dev/null +++ b/Tests/RunCMake/CXXModules/examples/export-transitive-modules1-build/CMakeLists.txt @@ -0,0 +1,48 @@ +cmake_minimum_required(VERSION 3.24...3.28) +project(cxx_modules_export_transitive_modules1 CXX) + +include("${CMAKE_SOURCE_DIR}/../cxx-modules-rules.cmake") + +add_library(export_transitive_modules1 STATIC) +target_sources(export_transitive_modules1 + PUBLIC + FILE_SET modules TYPE CXX_MODULES + BASE_DIRS + "${CMAKE_CURRENT_SOURCE_DIR}" + FILES + importable.cxx + ) +target_compile_features(export_transitive_modules1 PUBLIC cxx_std_20) + +install(TARGETS export_transitive_modules1 + EXPORT CXXModules + FILE_SET modules DESTINATION "lib/cxx/miu") +export(EXPORT CXXModules + NAMESPACE CXXModules:: + FILE "${CMAKE_CURRENT_BINARY_DIR}/export_transitive_modules1-targets.cmake" + CXX_MODULES_DIRECTORY "export_transitive_modules1-cxx-modules") +file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/export_transitive_modules1-config.cmake" + "include(\"\${CMAKE_CURRENT_LIST_DIR}/export_transitive_modules1-targets.cmake\") +set(\${CMAKE_FIND_PACKAGE_NAME}_FOUND 1) +") + +set(generator + -G "${CMAKE_GENERATOR}") +if (CMAKE_GENERATOR_TOOLSET) + list(APPEND generator + -T "${CMAKE_GENERATOR_TOOLSET}") +endif () +if (CMAKE_GENERATOR_PLATFORM) + list(APPEND generator + -A "${CMAKE_GENERATOR_PLATFORM}") +endif () + +add_test(NAME export_transitive_modules1_build + COMMAND + "${CMAKE_COMMAND}" + "-Dexpected_source_dir=${CMAKE_CURRENT_SOURCE_DIR}" + "-Dexpected_binary_dir=${CMAKE_CURRENT_BINARY_DIR}" + "-Dexport_transitive_modules1_DIR=${CMAKE_CURRENT_BINARY_DIR}" + ${generator} + -S "${CMAKE_CURRENT_SOURCE_DIR}/test" + -B "${CMAKE_CURRENT_BINARY_DIR}/test") diff --git a/Tests/RunCMake/CXXModules/examples/export-transitive-modules1-build/importable.cxx b/Tests/RunCMake/CXXModules/examples/export-transitive-modules1-build/importable.cxx new file mode 100644 index 0000000..ca6d526 --- /dev/null +++ b/Tests/RunCMake/CXXModules/examples/export-transitive-modules1-build/importable.cxx @@ -0,0 +1,6 @@ +export module module1; + +export int from_inner_import() +{ + return 0; +} diff --git a/Tests/RunCMake/CXXModules/examples/export-transitive-modules1-build/test/CMakeLists.txt b/Tests/RunCMake/CXXModules/examples/export-transitive-modules1-build/test/CMakeLists.txt new file mode 100644 index 0000000..35d8a68 --- /dev/null +++ b/Tests/RunCMake/CXXModules/examples/export-transitive-modules1-build/test/CMakeLists.txt @@ -0,0 +1,9 @@ +cmake_minimum_required(VERSION 3.28) +project(cxx_modules_library NONE) + +find_package(export_transitive_modules1 REQUIRED) + +if (NOT TARGET CXXModules::export_transitive_modules1) + message(FATAL_ERROR + "Missing imported target") +endif () diff --git a/Tests/RunCMake/CXXModules/examples/export-transitive-modules1-install/CMakeLists.txt b/Tests/RunCMake/CXXModules/examples/export-transitive-modules1-install/CMakeLists.txt new file mode 100644 index 0000000..d6f9bbf --- /dev/null +++ b/Tests/RunCMake/CXXModules/examples/export-transitive-modules1-install/CMakeLists.txt @@ -0,0 +1,51 @@ +cmake_minimum_required(VERSION 3.24...3.28) +project(cxx_modules_export_transitive_modules1 CXX) + +include("${CMAKE_SOURCE_DIR}/../cxx-modules-rules.cmake") + +add_library(export_transitive_modules1 STATIC) +target_sources(export_transitive_modules1 + PUBLIC + FILE_SET modules TYPE CXX_MODULES + BASE_DIRS + "${CMAKE_CURRENT_SOURCE_DIR}" + FILES + importable.cxx + ) +target_compile_features(export_transitive_modules1 PUBLIC cxx_std_20) + +install(TARGETS export_transitive_modules1 + EXPORT CXXModules + FILE_SET modules DESTINATION "lib/cxx/miu") +install(EXPORT CXXModules + NAMESPACE CXXModules:: + DESTINATION "lib/cmake/export_transitive_modules1" + FILE "export_transitive_modules1-targets.cmake" + CXX_MODULES_DIRECTORY "export_transitive_modules1-cxx-modules") +file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/export_transitive_modules1-config.cmake" + "include(\"\${CMAKE_CURRENT_LIST_DIR}/export_transitive_modules1-targets.cmake\") +set(\${CMAKE_FIND_PACKAGE_NAME}_FOUND 1) +") +install(FILES "${CMAKE_CURRENT_BINARY_DIR}/export_transitive_modules1-config.cmake" + DESTINATION "lib/cmake/export_transitive_modules1") + +set(generator + -G "${CMAKE_GENERATOR}") +if (CMAKE_GENERATOR_TOOLSET) + list(APPEND generator + -T "${CMAKE_GENERATOR_TOOLSET}") +endif () +if (CMAKE_GENERATOR_PLATFORM) + list(APPEND generator + -A "${CMAKE_GENERATOR_PLATFORM}") +endif () + +add_test(NAME export_transitive_modules1_build + COMMAND + "${CMAKE_COMMAND}" + "-Dexpected_source_dir=${CMAKE_INSTALL_PREFIX}/lib/cxx/miu" + "-Dexpected_binary_dir=${CMAKE_INSTALL_PREFIX}/lib/cxx/bmi" + "-Dexport_transitive_modules1_DIR=${CMAKE_INSTALL_PREFIX}/lib/cmake/export_transitive_modules1" + ${generator} + -S "${CMAKE_CURRENT_SOURCE_DIR}/test" + -B "${CMAKE_CURRENT_BINARY_DIR}/test") diff --git a/Tests/RunCMake/CXXModules/examples/export-transitive-modules1-install/importable.cxx b/Tests/RunCMake/CXXModules/examples/export-transitive-modules1-install/importable.cxx new file mode 100644 index 0000000..ca6d526 --- /dev/null +++ b/Tests/RunCMake/CXXModules/examples/export-transitive-modules1-install/importable.cxx @@ -0,0 +1,6 @@ +export module module1; + +export int from_inner_import() +{ + return 0; +} diff --git a/Tests/RunCMake/CXXModules/examples/export-transitive-modules1-install/test/CMakeLists.txt b/Tests/RunCMake/CXXModules/examples/export-transitive-modules1-install/test/CMakeLists.txt new file mode 100644 index 0000000..35d8a68 --- /dev/null +++ b/Tests/RunCMake/CXXModules/examples/export-transitive-modules1-install/test/CMakeLists.txt @@ -0,0 +1,9 @@ +cmake_minimum_required(VERSION 3.28) +project(cxx_modules_library NONE) + +find_package(export_transitive_modules1 REQUIRED) + +if (NOT TARGET CXXModules::export_transitive_modules1) + message(FATAL_ERROR + "Missing imported target") +endif () diff --git a/Tests/RunCMake/CXXModules/examples/import-modules/CMakeLists.txt b/Tests/RunCMake/CXXModules/examples/import-modules/CMakeLists.txt index 0b125ba..c2bbb2e 100644 --- a/Tests/RunCMake/CXXModules/examples/import-modules/CMakeLists.txt +++ b/Tests/RunCMake/CXXModules/examples/import-modules/CMakeLists.txt @@ -13,6 +13,8 @@ elseif (FROM_NINJA) set(package_name "export_from_ninja") elseif (TRANSITIVE_TARGETS) set(package_name "export_transitive_targets") +elseif (TRANSITIVE_MODULES) + set(package_name "export_transitive_modules") else () set(package_name "export_interfaces") endif () |