Tests/CXXModules: test that objects depend on dependent modules json files

This commit is contained in:
Ben Boeckel
2024-02-14 17:19:42 -05:00
parent 9a45c9fbd5
commit 52036ce090
6 changed files with 55 additions and 0 deletions

View File

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

View File

@@ -0,0 +1,12 @@
if (RunCMake_GENERATOR_IS_MULTI_CONFIG)
set(dep_modules_json_path "CMakeFiles/depchain_modules_json_file.dir/Debug/CXXModules.json")
set(modules_json_path "CMakeFiles/depchain_with_modules_json_file.dir/Debug/CXXModules.json")
else ()
set(dep_modules_json_path "CMakeFiles/depchain_modules_json_file.dir/CXXModules.json")
set(modules_json_path "CMakeFiles/depchain_with_modules_json_file.dir/CXXModules.json")
endif ()
if ("${RunCMake_TEST_BINARY_DIR}/${modules_json_path}" IS_NEWER_THAN "${RunCMake_TEST_BINARY_DIR}/${dep_modules_json_path}")
list(APPEND RunCMake_TEST_FAILED
"Object '${dep_modules_json_path}' should have recompiled if '${modules_json_path}' changed.")
endif ()

View File

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

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(modules_json_path "CMakeFiles/depchain_with_modules_json_file.dir/Debug/CXXModules.json")
else ()
set(modules_json_path "CMakeFiles/depchain_with_modules_json_file.dir/CXXModules.json")
endif ()
file(TOUCH_NOCREATE "${RunCMake_TEST_BINARY_DIR}/${modules_json_path}")