From 9a45c9fbd55798f9636778504562cd03e293da2e Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Tue, 13 Feb 2024 12:16:59 -0500 Subject: cmNinjaTargetGenerator: use `emplace_back` for scanning deps --- Source/cmNinjaTargetGenerator.cxx | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/Source/cmNinjaTargetGenerator.cxx b/Source/cmNinjaTargetGenerator.cxx index 99aa7f2..8ae4cd4 100644 --- a/Source/cmNinjaTargetGenerator.cxx +++ b/Source/cmNinjaTargetGenerator.cxx @@ -1190,7 +1190,7 @@ void cmNinjaTargetGenerator::WriteObjectBuildStatements( cmNinjaBuild build(this->LanguageDyndepRule(language, config)); build.Outputs.push_back(this->GetDyndepFilePath(language, config)); - build.ImplicitOuts.push_back( + build.ImplicitOuts.emplace_back( cmStrCat(this->Makefile->GetCurrentBinaryDirectory(), '/', this->LocalGenerator->GetTargetDirectory(this->GeneratorTarget), this->GetGlobalGenerator()->ConfigDirectory(config), '/', @@ -1209,10 +1209,12 @@ void cmNinjaTargetGenerator::WriteObjectBuildStatements( auto const linked_directories = this->GetLinkedTargetDirectories(language, config); for (std::string const& l : linked_directories.Direct) { - build.ImplicitDeps.push_back(cmStrCat(l, '/', language, "Modules.json")); + build.ImplicitDeps.emplace_back( + cmStrCat(l, '/', language, "Modules.json")); } for (std::string const& l : linked_directories.Forward) { - build.ImplicitDeps.push_back(cmStrCat(l, '/', language, "Modules.json")); + build.ImplicitDeps.emplace_back( + cmStrCat(l, '/', language, "Modules.json")); } this->GetGlobalGenerator()->WriteBuild(this->GetImplFileStream(fileConfig), -- cgit v0.12 From 52036ce090cf6f94a9389c2614b88cc8966f6e32 Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Wed, 14 Feb 2024 17:19:42 -0500 Subject: Tests/CXXModules: test that objects depend on dependent modules json files --- Tests/RunCMake/CXXModules/RunCMakeTest.cmake | 1 + .../depchain-modules-json-file-rebuild-check.cmake | 12 +++++++++++ .../depchain-modules-json-file/CMakeLists.txt | 23 ++++++++++++++++++++++ .../depchain-modules-json-file/importable.cxx | 6 ++++++ .../examples/depchain-modules-json-file/main.cxx | 6 ++++++ .../depchain-modules-json-file/pre-rebuild.cmake | 7 +++++++ 6 files changed, 55 insertions(+) create mode 100644 Tests/RunCMake/CXXModules/examples/depchain-modules-json-file-rebuild-check.cmake create mode 100644 Tests/RunCMake/CXXModules/examples/depchain-modules-json-file/CMakeLists.txt create mode 100644 Tests/RunCMake/CXXModules/examples/depchain-modules-json-file/importable.cxx create mode 100644 Tests/RunCMake/CXXModules/examples/depchain-modules-json-file/main.cxx create mode 100644 Tests/RunCMake/CXXModules/examples/depchain-modules-json-file/pre-rebuild.cmake diff --git a/Tests/RunCMake/CXXModules/RunCMakeTest.cmake b/Tests/RunCMake/CXXModules/RunCMakeTest.cmake index b996df0..7958166 100644 --- a/Tests/RunCMake/CXXModules/RunCMakeTest.cmake +++ b/Tests/RunCMake/CXXModules/RunCMakeTest.cmake @@ -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. diff --git a/Tests/RunCMake/CXXModules/examples/depchain-modules-json-file-rebuild-check.cmake b/Tests/RunCMake/CXXModules/examples/depchain-modules-json-file-rebuild-check.cmake new file mode 100644 index 0000000..452f446 --- /dev/null +++ b/Tests/RunCMake/CXXModules/examples/depchain-modules-json-file-rebuild-check.cmake @@ -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 () diff --git a/Tests/RunCMake/CXXModules/examples/depchain-modules-json-file/CMakeLists.txt b/Tests/RunCMake/CXXModules/examples/depchain-modules-json-file/CMakeLists.txt new file mode 100644 index 0000000..9828ee6 --- /dev/null +++ b/Tests/RunCMake/CXXModules/examples/depchain-modules-json-file/CMakeLists.txt @@ -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) diff --git a/Tests/RunCMake/CXXModules/examples/depchain-modules-json-file/importable.cxx b/Tests/RunCMake/CXXModules/examples/depchain-modules-json-file/importable.cxx new file mode 100644 index 0000000..607680a --- /dev/null +++ b/Tests/RunCMake/CXXModules/examples/depchain-modules-json-file/importable.cxx @@ -0,0 +1,6 @@ +export module importable; + +export int from_import() +{ + return 0; +} diff --git a/Tests/RunCMake/CXXModules/examples/depchain-modules-json-file/main.cxx b/Tests/RunCMake/CXXModules/examples/depchain-modules-json-file/main.cxx new file mode 100644 index 0000000..feb38d2 --- /dev/null +++ b/Tests/RunCMake/CXXModules/examples/depchain-modules-json-file/main.cxx @@ -0,0 +1,6 @@ +import importable; + +int main(int argc, char* argv[]) +{ + return from_import(); +} diff --git a/Tests/RunCMake/CXXModules/examples/depchain-modules-json-file/pre-rebuild.cmake b/Tests/RunCMake/CXXModules/examples/depchain-modules-json-file/pre-rebuild.cmake new file mode 100644 index 0000000..9c3f2ff --- /dev/null +++ b/Tests/RunCMake/CXXModules/examples/depchain-modules-json-file/pre-rebuild.cmake @@ -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}") -- cgit v0.12 From 60a8736378bbef58688c8a3dbfb2d0bce6aa1b6b Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Tue, 13 Feb 2024 12:17:15 -0500 Subject: cmNinjaTargetGenerator: scanning depends on the module metadata Fixes: #25531 --- Source/cmNinjaTargetGenerator.cxx | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Source/cmNinjaTargetGenerator.cxx b/Source/cmNinjaTargetGenerator.cxx index 8ae4cd4..9c75cd6 100644 --- a/Source/cmNinjaTargetGenerator.cxx +++ b/Source/cmNinjaTargetGenerator.cxx @@ -1195,6 +1195,8 @@ void cmNinjaTargetGenerator::WriteObjectBuildStatements( this->LocalGenerator->GetTargetDirectory(this->GeneratorTarget), this->GetGlobalGenerator()->ConfigDirectory(config), '/', language, "Modules.json")); + build.ImplicitDeps.emplace_back( + this->GetTargetDependInfoPath(language, config)); for (auto const& scanFiles : scanningFiles) { if (!scanFiles.ScanningOutput.empty()) { build.ExplicitDeps.push_back(scanFiles.ScanningOutput); -- cgit v0.12