diff options
author | Ben Boeckel <ben.boeckel@kitware.com> | 2023-09-26 12:49:25 (GMT) |
---|---|---|
committer | Ben Boeckel <ben.boeckel@kitware.com> | 2023-09-26 18:42:54 (GMT) |
commit | 42654cc8183af23a0d570355571d0a9d52a9d84d (patch) | |
tree | 07625d4214513e1280edea4ac0059307927ab823 | |
parent | 7217cb78cf836706d1811140255ac75004fe2ef8 (diff) | |
download | CMake-42654cc8183af23a0d570355571d0a9d52a9d84d.zip CMake-42654cc8183af23a0d570355571d0a9d52a9d84d.tar.gz CMake-42654cc8183af23a0d570355571d0a9d52a9d84d.tar.bz2 |
Tests/CXXModules: add tests for modules with include requirements
23 files changed, 292 insertions, 0 deletions
diff --git a/Tests/RunCMake/CXXModules/RunCMakeTest.cmake b/Tests/RunCMake/CXXModules/RunCMakeTest.cmake index f27eef8..f111b74 100644 --- a/Tests/RunCMake/CXXModules/RunCMakeTest.cmake +++ b/Tests/RunCMake/CXXModules/RunCMakeTest.cmake @@ -188,6 +188,7 @@ endif () if ("export_bmi" IN_LIST CMake_TEST_MODULE_COMPILATION) run_cxx_module_test(export-interface-no-properties-build) run_cxx_module_test(export-interface-build) + run_cxx_module_test(export-include-directories-build) run_cxx_module_test(export-usage-build) run_cxx_module_test(export-bmi-and-interface-build) @@ -199,6 +200,9 @@ if ("export_bmi" IN_LIST CMake_TEST_MODULE_COMPILATION) set(test_suffix export-interface-no-properties-build) run_cxx_module_test(import-modules "import-modules-${test_suffix}" "-DCMAKE_PREFIX_PATH=${RunCMake_BINARY_DIR}/examples/${test_suffix}-build" -DNO_PROPERTIES=1) + set(test_suffix export-include-directories-build) + run_cxx_module_test(import-modules "import-modules-${test_suffix}" "-DCMAKE_PREFIX_PATH=${RunCMake_BINARY_DIR}/examples/${test_suffix}-build" -DINCLUDE_PROPERTIES=1) + set(test_suffix export-bmi-and-interface-build) run_cxx_module_test(import-modules "import-modules-${test_suffix}" "-DCMAKE_PREFIX_PATH=${RunCMake_BINARY_DIR}/examples/${test_suffix}-build" -DWITH_BMIS=1) endif () @@ -215,6 +219,7 @@ if ("install_bmi" IN_LIST CMake_TEST_MODULE_COMPILATION) if ("export_bmi" IN_LIST CMake_TEST_MODULE_COMPILATION) run_cxx_module_test(export-interface-no-properties-install) run_cxx_module_test(export-interface-install) + run_cxx_module_test(export-include-directories-install) run_cxx_module_test(export-usage-install) run_cxx_module_test(export-bmi-and-interface-install) @@ -227,6 +232,9 @@ if ("install_bmi" IN_LIST CMake_TEST_MODULE_COMPILATION) set(test_suffix export-interface-no-properties-install) run_cxx_module_test(import-modules "import-modules-${test_suffix}" "-DCMAKE_PREFIX_PATH=${RunCMake_BINARY_DIR}/examples/${test_suffix}-install" -DNO_PROPERTIES=1) + set(test_suffix export-include-directories-install) + run_cxx_module_test(import-modules "import-modules-${test_suffix}" "-DCMAKE_PREFIX_PATH=${RunCMake_BINARY_DIR}/examples/${test_suffix}-install" -DINCLUDE_PROPERTIES=1) + set(test_suffix export-bmi-and-interface-install) run_cxx_module_test(import-modules "import-modules-${test_suffix}" "-DCMAKE_PREFIX_PATH=${RunCMake_BINARY_DIR}/examples/${test_suffix}-install" -DWITH_BMIS=1) set(RunCMake_CXXModules_INSTALL 1) diff --git a/Tests/RunCMake/CXXModules/examples/export-include-directories-build-stderr.txt b/Tests/RunCMake/CXXModules/examples/export-include-directories-build-stderr.txt new file mode 100644 index 0000000..28a7b1f --- /dev/null +++ b/Tests/RunCMake/CXXModules/examples/export-include-directories-build-stderr.txt @@ -0,0 +1,4 @@ +CMake Warning \(dev\) at CMakeLists.txt:[0-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-include-directories-build/CMakeLists.txt b/Tests/RunCMake/CXXModules/examples/export-include-directories-build/CMakeLists.txt new file mode 100644 index 0000000..bc2ae7f --- /dev/null +++ b/Tests/RunCMake/CXXModules/examples/export-include-directories-build/CMakeLists.txt @@ -0,0 +1,63 @@ +cmake_minimum_required(VERSION 3.24) +project(cxx_modules_export_include_directories CXX) + +include("${CMAKE_SOURCE_DIR}/../cxx-modules-rules.cmake") + +add_library(export_include_directories STATIC + include/include.h) +target_sources(export_include_directories + 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_include_directories PUBLIC cxx_std_20) +target_include_directories(export_include_directories + PRIVATE + "$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>") + +add_library(no_modules STATIC no_modules.cxx) + +install(TARGETS export_include_directories no_modules + EXPORT CXXModules + FILE_SET modules DESTINATION "lib/cxx/miu") +export(EXPORT CXXModules + NAMESPACE CXXModules:: + FILE "${CMAKE_CURRENT_BINARY_DIR}/export_include_directories-targets.cmake" + CXX_MODULES_DIRECTORY "export_include_directories-cxx-modules") +file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/export_include_directories-config.cmake" + "include(\"\${CMAKE_CURRENT_LIST_DIR}/export_include_directories-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_include_directories_build + COMMAND + "${CMAKE_COMMAND}" + "-Dexpected_source_dir=${CMAKE_CURRENT_SOURCE_DIR}" + "-Dexpected_binary_dir=${CMAKE_CURRENT_BINARY_DIR}" + "-Dexport_include_directories_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-include-directories-build/forward.cxx b/Tests/RunCMake/CXXModules/examples/export-include-directories-build/forward.cxx new file mode 100644 index 0000000..7f53271 --- /dev/null +++ b/Tests/RunCMake/CXXModules/examples/export-include-directories-build/forward.cxx @@ -0,0 +1,6 @@ +import priv; + +int forwarding() +{ + return from_private(); +} diff --git a/Tests/RunCMake/CXXModules/examples/export-include-directories-build/importable.cxx b/Tests/RunCMake/CXXModules/examples/export-include-directories-build/importable.cxx new file mode 100644 index 0000000..6a1d83e --- /dev/null +++ b/Tests/RunCMake/CXXModules/examples/export-include-directories-build/importable.cxx @@ -0,0 +1,18 @@ +module; + +#include "include/include.h" + +#ifndef include_h_included +# error "include define not found" +#endif + +export module importable; + +extern "C++" { +int forwarding(); +} + +export int from_import() +{ + return forwarding(); +} diff --git a/Tests/RunCMake/CXXModules/examples/export-include-directories-build/include/include.h b/Tests/RunCMake/CXXModules/examples/export-include-directories-build/include/include.h new file mode 100644 index 0000000..e3eee34 --- /dev/null +++ b/Tests/RunCMake/CXXModules/examples/export-include-directories-build/include/include.h @@ -0,0 +1,3 @@ +#pragma once + +#define include_h_included diff --git a/Tests/RunCMake/CXXModules/examples/export-include-directories-build/no_modules.cxx b/Tests/RunCMake/CXXModules/examples/export-include-directories-build/no_modules.cxx new file mode 100644 index 0000000..eea854f --- /dev/null +++ b/Tests/RunCMake/CXXModules/examples/export-include-directories-build/no_modules.cxx @@ -0,0 +1,3 @@ +void no_modules() +{ +} diff --git a/Tests/RunCMake/CXXModules/examples/export-include-directories-build/private.cxx b/Tests/RunCMake/CXXModules/examples/export-include-directories-build/private.cxx new file mode 100644 index 0000000..c5b719a --- /dev/null +++ b/Tests/RunCMake/CXXModules/examples/export-include-directories-build/private.cxx @@ -0,0 +1,6 @@ +export module priv; + +export int from_private() +{ + return 0; +} diff --git a/Tests/RunCMake/CXXModules/examples/export-include-directories-build/subdir/importable.cxx b/Tests/RunCMake/CXXModules/examples/export-include-directories-build/subdir/importable.cxx new file mode 100644 index 0000000..07d6af6 --- /dev/null +++ b/Tests/RunCMake/CXXModules/examples/export-include-directories-build/subdir/importable.cxx @@ -0,0 +1,6 @@ +export module subdir_importable; + +export int from_subdir() +{ + return 0; +} diff --git a/Tests/RunCMake/CXXModules/examples/export-include-directories-build/test/CMakeLists.txt b/Tests/RunCMake/CXXModules/examples/export-include-directories-build/test/CMakeLists.txt new file mode 100644 index 0000000..f5bdfd4 --- /dev/null +++ b/Tests/RunCMake/CXXModules/examples/export-include-directories-build/test/CMakeLists.txt @@ -0,0 +1,20 @@ +cmake_minimum_required(VERSION 3.24) +project(cxx_modules_library NONE) + +set(CMAKE_EXPERIMENTAL_CXX_MODULE_CMAKE_API "ac01f462-0f5f-432a-86aa-acef252918a6") + +find_package(export_include_directories REQUIRED) + +if (NOT TARGET CXXModules::export_include_directories) + message(FATAL_ERROR + "Missing imported target") +endif () + +get_property(include_directories TARGET CXXModules::export_include_directories + PROPERTY IMPORTED_CXX_MODULES_INCLUDE_DIRECTORIES) +foreach (include_directory IN LISTS include_directories) + if (NOT EXISTS "${include_directory}") + message(FATAL_ERROR + "Missing include directory in C++ module interface CXXModules::export_include_directories:\n ${include_directory}") + endif () +endforeach () diff --git a/Tests/RunCMake/CXXModules/examples/export-include-directories-install-stderr.txt b/Tests/RunCMake/CXXModules/examples/export-include-directories-install-stderr.txt new file mode 100644 index 0000000..be89b8c --- /dev/null +++ b/Tests/RunCMake/CXXModules/examples/export-include-directories-install-stderr.txt @@ -0,0 +1,4 @@ +CMake Warning \(dev\) at CMakeLists.txt:[0-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-include-directories-install/CMakeLists.txt b/Tests/RunCMake/CXXModules/examples/export-include-directories-install/CMakeLists.txt new file mode 100644 index 0000000..444882d --- /dev/null +++ b/Tests/RunCMake/CXXModules/examples/export-include-directories-install/CMakeLists.txt @@ -0,0 +1,69 @@ +cmake_minimum_required(VERSION 3.24) +project(cxx_modules_export_include_directories CXX) + +include("${CMAKE_SOURCE_DIR}/../cxx-modules-rules.cmake") + +add_library(export_include_directories STATIC + include/include.h) +target_sources(export_include_directories + 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_include_directories PUBLIC cxx_std_20) +target_include_directories(export_include_directories + PRIVATE + "$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>" + "$<INSTALL_INTERFACE:include>") + +add_library(no_modules STATIC no_modules.cxx) + +install(TARGETS export_include_directories no_modules + EXPORT CXXModules + FILE_SET modules DESTINATION "lib/cxx/miu") +install(DIRECTORY include + DESTINATION "include") +install(EXPORT CXXModules + NAMESPACE CXXModules:: + DESTINATION "lib/cmake/export_include_directories" + FILE "export_include_directories-targets.cmake" + CXX_MODULES_DIRECTORY "export_include_directories-cxx-modules") +file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/export_include_directories-config.cmake" + "include(\"\${CMAKE_CURRENT_LIST_DIR}/export_include_directories-targets.cmake\") +set(\${CMAKE_FIND_PACKAGE_NAME}_FOUND 1) +") +install(FILES "${CMAKE_CURRENT_BINARY_DIR}/export_include_directories-config.cmake" + DESTINATION "lib/cmake/export_include_directories") + +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_include_directories_build + COMMAND + "${CMAKE_COMMAND}" + "-Dexpected_source_dir=${CMAKE_INSTALL_PREFIX}/lib/cxx/miu" + "-Dexpected_binary_dir=${CMAKE_INSTALL_PREFIX}/lib/cxx/bmi" + "-Dexport_include_directories_DIR=${CMAKE_INSTALL_PREFIX}/lib/cmake/export_include_directories" + ${generator} + -S "${CMAKE_CURRENT_SOURCE_DIR}/test" + -B "${CMAKE_CURRENT_BINARY_DIR}/test") diff --git a/Tests/RunCMake/CXXModules/examples/export-include-directories-install/forward.cxx b/Tests/RunCMake/CXXModules/examples/export-include-directories-install/forward.cxx new file mode 100644 index 0000000..7f53271 --- /dev/null +++ b/Tests/RunCMake/CXXModules/examples/export-include-directories-install/forward.cxx @@ -0,0 +1,6 @@ +import priv; + +int forwarding() +{ + return from_private(); +} diff --git a/Tests/RunCMake/CXXModules/examples/export-include-directories-install/importable.cxx b/Tests/RunCMake/CXXModules/examples/export-include-directories-install/importable.cxx new file mode 100644 index 0000000..6a1d83e --- /dev/null +++ b/Tests/RunCMake/CXXModules/examples/export-include-directories-install/importable.cxx @@ -0,0 +1,18 @@ +module; + +#include "include/include.h" + +#ifndef include_h_included +# error "include define not found" +#endif + +export module importable; + +extern "C++" { +int forwarding(); +} + +export int from_import() +{ + return forwarding(); +} diff --git a/Tests/RunCMake/CXXModules/examples/export-include-directories-install/include/include.h b/Tests/RunCMake/CXXModules/examples/export-include-directories-install/include/include.h new file mode 100644 index 0000000..e3eee34 --- /dev/null +++ b/Tests/RunCMake/CXXModules/examples/export-include-directories-install/include/include.h @@ -0,0 +1,3 @@ +#pragma once + +#define include_h_included diff --git a/Tests/RunCMake/CXXModules/examples/export-include-directories-install/no_modules.cxx b/Tests/RunCMake/CXXModules/examples/export-include-directories-install/no_modules.cxx new file mode 100644 index 0000000..eea854f --- /dev/null +++ b/Tests/RunCMake/CXXModules/examples/export-include-directories-install/no_modules.cxx @@ -0,0 +1,3 @@ +void no_modules() +{ +} diff --git a/Tests/RunCMake/CXXModules/examples/export-include-directories-install/private.cxx b/Tests/RunCMake/CXXModules/examples/export-include-directories-install/private.cxx new file mode 100644 index 0000000..c5b719a --- /dev/null +++ b/Tests/RunCMake/CXXModules/examples/export-include-directories-install/private.cxx @@ -0,0 +1,6 @@ +export module priv; + +export int from_private() +{ + return 0; +} diff --git a/Tests/RunCMake/CXXModules/examples/export-include-directories-install/subdir/importable.cxx b/Tests/RunCMake/CXXModules/examples/export-include-directories-install/subdir/importable.cxx new file mode 100644 index 0000000..07d6af6 --- /dev/null +++ b/Tests/RunCMake/CXXModules/examples/export-include-directories-install/subdir/importable.cxx @@ -0,0 +1,6 @@ +export module subdir_importable; + +export int from_subdir() +{ + return 0; +} diff --git a/Tests/RunCMake/CXXModules/examples/export-include-directories-install/test/CMakeLists.txt b/Tests/RunCMake/CXXModules/examples/export-include-directories-install/test/CMakeLists.txt new file mode 100644 index 0000000..9cdb7ff --- /dev/null +++ b/Tests/RunCMake/CXXModules/examples/export-include-directories-install/test/CMakeLists.txt @@ -0,0 +1,18 @@ +cmake_minimum_required(VERSION 3.24) +project(cxx_modules_library NONE) + +set(CMAKE_EXPERIMENTAL_CXX_MODULE_CMAKE_API "ac01f462-0f5f-432a-86aa-acef252918a6") + +find_package(export_include_directories REQUIRED) + +if (NOT TARGET CXXModules::export_include_directories) + message(FATAL_ERROR + "Missing imported target") +endif () + +get_property(file_sets TARGET CXXModules::export_include_directories + PROPERTY INTERFACE_CXX_MODULE_SETS) +if (NOT file_sets STREQUAL "modules") + message(FATAL_ERROR + "Incorrect exported file sets in CXXModules::export_include_directories:\n ${file_sets}") +endif () diff --git a/Tests/RunCMake/CXXModules/examples/import-modules-export-include-directories-build-stderr.txt b/Tests/RunCMake/CXXModules/examples/import-modules-export-include-directories-build-stderr.txt new file mode 100644 index 0000000..4ea3679 --- /dev/null +++ b/Tests/RunCMake/CXXModules/examples/import-modules-export-include-directories-build-stderr.txt @@ -0,0 +1,7 @@ +CMake Warning \(dev\) at .*/Tests/RunCMake/CXXModules/examples/export-include-directories-build-build/export_include_directories-targets.cmake:[0-9]+ \(target_sources\): + CMake's C\+\+ module support is experimental. It is meant only for + experimentation and feedback to CMake developers. +Call Stack \(most recent call first\): + .*/Tests/RunCMake/CXXModules/examples/export-include-directories-build-build/export_include_directories-config.cmake:[0-9]+ \(include\) + CMakeLists.txt:[0-9]+ \(find_package\) +This warning is for project developers. Use -Wno-dev to suppress it. diff --git a/Tests/RunCMake/CXXModules/examples/import-modules-export-include-directories-install-stderr.txt b/Tests/RunCMake/CXXModules/examples/import-modules-export-include-directories-install-stderr.txt new file mode 100644 index 0000000..50ad6b9 --- /dev/null +++ b/Tests/RunCMake/CXXModules/examples/import-modules-export-include-directories-install-stderr.txt @@ -0,0 +1,7 @@ +CMake Warning \(dev\) at .*/Tests/RunCMake/CXXModules/examples/export-include-directories-install-install/lib/cmake/export_include_directories/export_include_directories-targets.cmake:[0-9]+ \(target_sources\): + CMake's C\+\+ module support is experimental. It is meant only for + experimentation and feedback to CMake developers. +Call Stack \(most recent call first\): + .*/Tests/RunCMake/CXXModules/examples/export-include-directories-install-install/lib/cmake/export_include_directories/export_include_directories-config.cmake:[0-9]+ \(include\) + CMakeLists.txt:[0-9]+ \(find_package\) +This warning is for project developers. Use -Wno-dev to suppress it. diff --git a/Tests/RunCMake/CXXModules/examples/import-modules/CMakeLists.txt b/Tests/RunCMake/CXXModules/examples/import-modules/CMakeLists.txt index 3e6f379..946792c 100644 --- a/Tests/RunCMake/CXXModules/examples/import-modules/CMakeLists.txt +++ b/Tests/RunCMake/CXXModules/examples/import-modules/CMakeLists.txt @@ -7,6 +7,8 @@ if (NO_PROPERTIES) set(package_name "export_interfaces_no_properties") elseif (WITH_BMIS) set(package_name "export_bmi_and_interfaces") +elseif (INCLUDE_PROPERTIES) + set(package_name "export_include_directories") else () set(package_name "export_interfaces") endif () diff --git a/Tests/RunCMake/CXXModules/examples/import-modules/use.cxx b/Tests/RunCMake/CXXModules/examples/import-modules/use.cxx index feb38d2..2da1913 100644 --- a/Tests/RunCMake/CXXModules/examples/import-modules/use.cxx +++ b/Tests/RunCMake/CXXModules/examples/import-modules/use.cxx @@ -1,3 +1,9 @@ +#if defined(__has_include) +# if __has_include(<include/include.h>) +# error "include directories leaked from private module requirements" +# endif +#endif + import importable; int main(int argc, char* argv[]) |