RunCMake/CXXModules: add a "deep-chain" test

This tests that transitive usages are propogated properly across long
import chains between targets.
This commit is contained in:
Ben Boeckel
2022-07-19 16:10:20 -04:00
parent 297e0f4dce
commit c49d5f137b
9 changed files with 116 additions and 0 deletions

View File

@@ -131,6 +131,7 @@ if ("named" IN_LIST CMake_TEST_MODULE_COMPILATION)
run_cxx_module_test(library library-static -DBUILD_SHARED_LIBS=OFF)
run_cxx_module_test(generated)
run_cxx_module_test(public-req-private)
run_cxx_module_test(deep-chain)
endif ()
# Tests which use named modules in shared libraries.

View File

@@ -0,0 +1,9 @@
CMake Warning \(dev\) at CMakeLists.txt:7 \(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.
CMake Warning \(dev\):
C\+\+20 modules support via CMAKE_EXPERIMENTAL_CXX_MODULE_DYNDEP is
experimental. It is meant only for compiler developers to try.
This warning is for project developers. Use -Wno-dev to suppress it.

View File

@@ -0,0 +1,66 @@
cmake_minimum_required(VERSION 3.24)
project(cxx_modules_deep_chain CXX)
include("${CMAKE_SOURCE_DIR}/../cxx-modules-rules.cmake")
add_library(a STATIC)
target_sources(a
PUBLIC
FILE_SET CXX_MODULES
BASE_DIRS
"${CMAKE_CURRENT_SOURCE_DIR}"
FILES
a.cxx)
target_compile_features(a PUBLIC cxx_std_20)
add_library(b STATIC)
target_sources(b
PUBLIC
FILE_SET CXX_MODULES
BASE_DIRS
"${CMAKE_CURRENT_SOURCE_DIR}"
FILES
b.cxx)
target_compile_features(b PUBLIC cxx_std_20)
target_link_libraries(b PUBLIC a)
add_library(c STATIC)
target_sources(c
PUBLIC
FILE_SET CXX_MODULES
BASE_DIRS
"${CMAKE_CURRENT_SOURCE_DIR}"
FILES
c.cxx)
target_compile_features(c PUBLIC cxx_std_20)
target_link_libraries(c PUBLIC b)
add_library(d STATIC)
target_sources(d
PUBLIC
FILE_SET CXX_MODULES
BASE_DIRS
"${CMAKE_CURRENT_SOURCE_DIR}"
FILES
d.cxx)
target_compile_features(d PUBLIC cxx_std_20)
target_link_libraries(d PUBLIC c)
add_library(e STATIC)
target_sources(e
PUBLIC
FILE_SET CXX_MODULES
BASE_DIRS
"${CMAKE_CURRENT_SOURCE_DIR}"
FILES
e.cxx)
target_compile_features(e PUBLIC cxx_std_20)
target_link_libraries(e PUBLIC d)
add_executable(exe)
target_link_libraries(exe PRIVATE e)
target_sources(exe
PRIVATE
main.cxx)
add_test(NAME exe COMMAND exe)

View File

@@ -0,0 +1,6 @@
export module a;
export int a()
{
return 0;
}

View File

@@ -0,0 +1,7 @@
export module b;
import a;
export int b()
{
return a();
}

View File

@@ -0,0 +1,7 @@
export module c;
import b;
export int c()
{
return b();
}

View File

@@ -0,0 +1,7 @@
export module d;
import c;
export int d()
{
return c();
}

View File

@@ -0,0 +1,7 @@
export module e;
import d;
export int e()
{
return d();
}

View File

@@ -0,0 +1,6 @@
import e;
int main(int argc, char* argv[])
{
return e();
}