diff options
author | Ben Boeckel <ben.boeckel@kitware.com> | 2024-04-27 00:13:33 (GMT) |
---|---|---|
committer | Ben Boeckel <ben.boeckel@kitware.com> | 2024-04-27 00:15:05 (GMT) |
commit | 051c2110c8cb7538b931075d1d712ac72789c127 (patch) | |
tree | e95916e0f5f02c5b48efc46dcee40ef31fdb4f30 | |
parent | b5602e7254c8ce4a6f732c017d784cd80559e5aa (diff) | |
download | CMake-051c2110c8cb7538b931075d1d712ac72789c127.zip CMake-051c2110c8cb7538b931075d1d712ac72789c127.tar.gz CMake-051c2110c8cb7538b931075d1d712ac72789c127.tar.bz2 |
Tests/CXXModules: test exporting modules which include headers
Test that headers that are part of the same target are available to
modules in the target itself.
10 files changed, 184 insertions, 0 deletions
diff --git a/Tests/RunCMake/CXXModules/RunCMakeTest.cmake b/Tests/RunCMake/CXXModules/RunCMakeTest.cmake index 14829a1..6547701 100644 --- a/Tests/RunCMake/CXXModules/RunCMakeTest.cmake +++ b/Tests/RunCMake/CXXModules/RunCMakeTest.cmake @@ -267,6 +267,7 @@ if ("export_bmi" IN_LIST CMake_TEST_MODULE_COMPILATION) 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" ) + run_cxx_module_test(export-with-headers-build) if ("collation" IN_LIST CMake_TEST_MODULE_COMPILATION AND "bmionly" IN_LIST CMake_TEST_MODULE_COMPILATION) @@ -287,6 +288,9 @@ if ("export_bmi" IN_LIST CMake_TEST_MODULE_COMPILATION) 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) + + set(test_suffix export-with-headers-build) + run_cxx_module_test(import-modules "import-modules-${test_suffix}" "-DCMAKE_PREFIX_PATH=${RunCMake_BINARY_DIR}/examples/${test_suffix}-build" -DWITH_HEADERS=1) endif () endif () @@ -308,6 +312,7 @@ if ("install_bmi" IN_LIST CMake_TEST_MODULE_COMPILATION) 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" ) + run_cxx_module_test(export-with-headers-install) if ("collation" IN_LIST CMake_TEST_MODULE_COMPILATION AND "bmionly" IN_LIST CMake_TEST_MODULE_COMPILATION) @@ -329,6 +334,9 @@ if ("install_bmi" IN_LIST CMake_TEST_MODULE_COMPILATION) 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(test_suffix export-with-headers-install) + run_cxx_module_test(import-modules "import-modules-${test_suffix}" "-DCMAKE_PREFIX_PATH=${RunCMake_BINARY_DIR}/examples/${test_suffix}-install" -DWITH_HEADERS=1) set(RunCMake_CXXModules_INSTALL 1) endif () endif () diff --git a/Tests/RunCMake/CXXModules/examples/export-with-headers-build/CMakeLists.txt b/Tests/RunCMake/CXXModules/examples/export-with-headers-build/CMakeLists.txt new file mode 100644 index 0000000..e329189 --- /dev/null +++ b/Tests/RunCMake/CXXModules/examples/export-with-headers-build/CMakeLists.txt @@ -0,0 +1,49 @@ +cmake_minimum_required(VERSION 3.28) +project(export_with_headers CXX) + +include("${CMAKE_SOURCE_DIR}/../cxx-modules-rules.cmake") + +add_library(export_with_headers) +target_sources(export_with_headers + PUBLIC + FILE_SET headers TYPE HEADERS + BASE_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/include" + FILES + "${CMAKE_CURRENT_SOURCE_DIR}/include/subdir/header.h" + PUBLIC + FILE_SET modules TYPE CXX_MODULES + FILES + importable.cxx) +target_compile_features(export_with_headers PUBLIC cxx_std_20) + +install(TARGETS export_with_headers + EXPORT CXXModules + FILE_SET headers + FILE_SET modules DESTINATION ${CMAKE_INSTALL_LIBDIR}/miu) +export(EXPORT CXXModules + NAMESPACE CXXModules:: + FILE "${CMAKE_CURRENT_BINARY_DIR}/export_with_headers-targets.cmake" + CXX_MODULES_DIRECTORY "export_with_headers-cxx-modules") +file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/export_with_headers-config.cmake" + "include(\"\${CMAKE_CURRENT_LIST_DIR}/export_with_headers-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_with_headers_build + COMMAND + "${CMAKE_COMMAND}" + "-Dexport_with_headers_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-with-headers-build/importable.cxx b/Tests/RunCMake/CXXModules/examples/export-with-headers-build/importable.cxx new file mode 100644 index 0000000..83d5b50 --- /dev/null +++ b/Tests/RunCMake/CXXModules/examples/export-with-headers-build/importable.cxx @@ -0,0 +1,14 @@ +module; + +#include <subdir/header.h> + +#ifndef from_subdir_header_h +# error "Define from header found" +#endif + +export module importable; + +export int from_import() +{ + return 0; +} diff --git a/Tests/RunCMake/CXXModules/examples/export-with-headers-build/include/subdir/header.h b/Tests/RunCMake/CXXModules/examples/export-with-headers-build/include/subdir/header.h new file mode 100644 index 0000000..81e8215 --- /dev/null +++ b/Tests/RunCMake/CXXModules/examples/export-with-headers-build/include/subdir/header.h @@ -0,0 +1,3 @@ +#pragma once + +#define from_subdir_header_h 1 diff --git a/Tests/RunCMake/CXXModules/examples/export-with-headers-build/test/CMakeLists.txt b/Tests/RunCMake/CXXModules/examples/export-with-headers-build/test/CMakeLists.txt new file mode 100644 index 0000000..11b0dae --- /dev/null +++ b/Tests/RunCMake/CXXModules/examples/export-with-headers-build/test/CMakeLists.txt @@ -0,0 +1,19 @@ +cmake_minimum_required(VERSION 3.28) +project(cxx_modules_library NONE) + +find_package(export_with_headers REQUIRED) + +if (NOT TARGET CXXModules::export_with_headers) + message(FATAL_ERROR + "Missing imported target") +endif () + +get_property(iface_includes TARGET CXXModules::export_with_headers + PROPERTY INTERFACE_INCLUDE_DIRECTORIES) +set(include_dir "${CMAKE_CURRENT_SOURCE_DIR}") +cmake_path(GET include_dir PARENT_PATH include_dir) +string(APPEND include_dir "/include") +if (NOT iface_includes STREQUAL "${include_dir};$<BUILD_INTERFACE:${include_dir}>") + message(FATAL_ERROR + "Incorrect include interface for CXXModules::export_with_headers:\n ${iface_includes}") +endif () diff --git a/Tests/RunCMake/CXXModules/examples/export-with-headers-install/CMakeLists.txt b/Tests/RunCMake/CXXModules/examples/export-with-headers-install/CMakeLists.txt new file mode 100644 index 0000000..f6aefaf --- /dev/null +++ b/Tests/RunCMake/CXXModules/examples/export-with-headers-install/CMakeLists.txt @@ -0,0 +1,51 @@ +cmake_minimum_required(VERSION 3.28) +project(export_with_headers CXX) + +include("${CMAKE_SOURCE_DIR}/../cxx-modules-rules.cmake") + +add_library(export_with_headers) +target_sources(export_with_headers + PUBLIC + FILE_SET headers TYPE HEADERS + BASE_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/include" + FILES + "${CMAKE_CURRENT_SOURCE_DIR}/include/subdir/header.h" + PUBLIC + FILE_SET modules TYPE CXX_MODULES + FILES + importable.cxx) +target_compile_features(export_with_headers PUBLIC cxx_std_20) + +install(TARGETS export_with_headers + EXPORT CXXModules + FILE_SET headers + FILE_SET modules DESTINATION lib/miu) +install(EXPORT CXXModules + NAMESPACE CXXModules:: + DESTINATION "lib/cmake/export_with_headers" + FILE "export_with_headers-targets.cmake") +file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/export_with_headers-config.cmake" + "include(\"\${CMAKE_CURRENT_LIST_DIR}/export_with_headers-targets.cmake\") +set(\${CMAKE_FIND_PACKAGE_NAME}_FOUND 1) +") +install(FILES "${CMAKE_CURRENT_BINARY_DIR}/export_with_headers-config.cmake" + DESTINATION "lib/cmake/export_with_headers") + +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_with_headers_build + COMMAND + "${CMAKE_COMMAND}" + "-Dexport_with_headers_DIR=${CMAKE_INSTALL_PREFIX}/lib/cmake/export_with_headers" + ${generator} + -S "${CMAKE_CURRENT_SOURCE_DIR}/test" + -B "${CMAKE_CURRENT_BINARY_DIR}/test") diff --git a/Tests/RunCMake/CXXModules/examples/export-with-headers-install/importable.cxx b/Tests/RunCMake/CXXModules/examples/export-with-headers-install/importable.cxx new file mode 100644 index 0000000..83d5b50 --- /dev/null +++ b/Tests/RunCMake/CXXModules/examples/export-with-headers-install/importable.cxx @@ -0,0 +1,14 @@ +module; + +#include <subdir/header.h> + +#ifndef from_subdir_header_h +# error "Define from header found" +#endif + +export module importable; + +export int from_import() +{ + return 0; +} diff --git a/Tests/RunCMake/CXXModules/examples/export-with-headers-install/include/subdir/header.h b/Tests/RunCMake/CXXModules/examples/export-with-headers-install/include/subdir/header.h new file mode 100644 index 0000000..81e8215 --- /dev/null +++ b/Tests/RunCMake/CXXModules/examples/export-with-headers-install/include/subdir/header.h @@ -0,0 +1,3 @@ +#pragma once + +#define from_subdir_header_h 1 diff --git a/Tests/RunCMake/CXXModules/examples/export-with-headers-install/test/CMakeLists.txt b/Tests/RunCMake/CXXModules/examples/export-with-headers-install/test/CMakeLists.txt new file mode 100644 index 0000000..40d66cb --- /dev/null +++ b/Tests/RunCMake/CXXModules/examples/export-with-headers-install/test/CMakeLists.txt @@ -0,0 +1,21 @@ +cmake_minimum_required(VERSION 3.28) +project(cxx_modules_library NONE) + +find_package(export_with_headers REQUIRED) + +if (NOT TARGET CXXModules::export_with_headers) + message(FATAL_ERROR + "Missing imported target") +endif () + +get_property(iface_includes TARGET CXXModules::export_with_headers + PROPERTY INTERFACE_INCLUDE_DIRECTORIES) +set(include_dir "${export_with_headers_DIR}") +cmake_path(GET include_dir PARENT_PATH include_dir) +cmake_path(GET include_dir PARENT_PATH include_dir) +cmake_path(GET include_dir PARENT_PATH include_dir) +string(APPEND include_dir "/include") +if (NOT iface_includes STREQUAL "$<BUILD_INTERFACE:${include_dir}>") + message(FATAL_ERROR + "Incorrect include interface for CXXModules::export_with_headers:\n ${iface_includes}") +endif () diff --git a/Tests/RunCMake/CXXModules/examples/import-modules/CMakeLists.txt b/Tests/RunCMake/CXXModules/examples/import-modules/CMakeLists.txt index c2bbb2e..494b91a 100644 --- a/Tests/RunCMake/CXXModules/examples/import-modules/CMakeLists.txt +++ b/Tests/RunCMake/CXXModules/examples/import-modules/CMakeLists.txt @@ -15,6 +15,8 @@ elseif (TRANSITIVE_TARGETS) set(package_name "export_transitive_targets") elseif (TRANSITIVE_MODULES) set(package_name "export_transitive_modules") +elseif (WITH_HEADERS) + set(package_name "export_with_headers") else () set(package_name "export_interfaces") endif () |