Tests/CXXModules: test that objects depend on their modmap files

This commit is contained in:
Ben Boeckel
2024-02-14 14:20:57 -05:00
parent 681ee92030
commit 940628d48d
6 changed files with 49 additions and 0 deletions

View File

@@ -214,6 +214,7 @@ if ("collation" IN_LIST CMake_TEST_MODULE_COMPILATION)
set(RunCMake_CXXModules_NO_TEST 1)
run_cxx_module_test(req-private-other-target)
unset(RunCMake_CXXModules_NO_TEST)
run_cxx_module_test_rebuild(depchain-modmap)
endif ()
# Tests which use named modules in shared libraries.

View File

@@ -0,0 +1,11 @@
if (RunCMake_GENERATOR_IS_MULTI_CONFIG)
set(object_path "CMakeFiles/depchain_modmap.dir/Debug/main.cxx${CMAKE_CXX_OUTPUT_EXTENSION}")
else ()
set(object_path "CMakeFiles/depchain_modmap.dir/main.cxx${CMAKE_CXX_OUTPUT_EXTENSION}")
endif ()
set(modmap_path "${object_path}.modmap")
if ("${RunCMake_TEST_BINARY_DIR}/${modmap_path}" IS_NEWER_THAN "${RunCMake_TEST_BINARY_DIR}/${object_path}")
list(APPEND RunCMake_TEST_FAILED
"Object '${object_path}' should have recompiled if '${modmap_path}' changed.")
endif ()

View File

@@ -0,0 +1,18 @@
cmake_minimum_required(VERSION 3.28)
project(cxx_modules_depchain_modmap CXX)
include("${CMAKE_SOURCE_DIR}/../cxx-modules-rules.cmake")
add_executable(depchain_modmap)
target_sources(depchain_modmap
PRIVATE
main.cxx
PRIVATE
FILE_SET CXX_MODULES
BASE_DIRS
"${CMAKE_CURRENT_SOURCE_DIR}"
FILES
importable.cxx)
target_compile_features(depchain_modmap PUBLIC cxx_std_20)
add_test(NAME depchain_modmap COMMAND depchain_modmap)

View File

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

View File

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

View File

@@ -0,0 +1,7 @@
if (RunCMake_GENERATOR_IS_MULTI_CONFIG)
set(modmap_path "CMakeFiles/depchain_modmap.dir/Debug/main.cxx${CMAKE_CXX_OUTPUT_EXTENSION}.modmap")
else ()
set(modmap_path "CMakeFiles/depchain_modmap.dir/main.cxx${CMAKE_CXX_OUTPUT_EXTENSION}.modmap")
endif ()
file(TOUCH_NOCREATE "${RunCMake_TEST_BINARY_DIR}/${modmap_path}")