From 3cac48e8cdfc80b2d416fa04e5e1cfc760dba294 Mon Sep 17 00:00:00 2001 From: Orkun Tokdemir Date: Tue, 26 Nov 2024 15:27:18 +0100 Subject: Autogen: Restore _autogen_timestamp_deps target Revert commit 91b2ce4a69 (Autogen: Remove ..._autogen_timestamp_deps target, 2024-06-27, v3.31.0-rc1~391^2). The `_autogen_timestamp_deps` target is needed for pre-`AUTOGEN_BETTER_GRAPH_MULTI_CONFIG` behavior. Issue: #26080 Issue: #26475 --- Source/cmQtAutoGenInitializer.cxx | 46 +++++++++++++++++++++++++++++---------- 1 file changed, 35 insertions(+), 11 deletions(-) diff --git a/Source/cmQtAutoGenInitializer.cxx b/Source/cmQtAutoGenInitializer.cxx index 1fd406c..63b97f3 100644 --- a/Source/cmQtAutoGenInitializer.cxx +++ b/Source/cmQtAutoGenInitializer.cxx @@ -1483,16 +1483,6 @@ bool cmQtAutoGenInitializer::InitAutogenTarget() } } - // For the Ninja, Makefile and Qt >= 5.15, add custom commands that create - // XXX_autogen/timestamp files. Those custom commands have a depfile - // assigned that is generated from the depfiles that were created by moc. - // - // The XXX_autogen targets merely wrap the XXX_autogen/timestamp custom - // commands. - // The dependency tree would then look like - // the original dependencies of '_autogen' target <-'/timestamp' file - // <- '_autogen' target - cmTarget* timestampTarget = nullptr; std::vector dependencies( this->AutogenTarget.DependFiles.begin(), @@ -1500,6 +1490,40 @@ bool cmQtAutoGenInitializer::InitAutogenTarget() if (useDepfile) { // Create a custom command that generates a timestamp file and // has a depfile assigned. The depfile is created by JobDepFilesMergeT. + // + // Also create an additional '_autogen_timestamp_deps' that the custom + // command will depend on. It will have no sources or commands to + // execute, but it will have dependencies that would originally be + // assigned to the pre-Qt 5.15 'autogen' target. These dependencies will + // serve as a list of order-only dependencies for the custom command, + // without forcing the custom command to re-execute. + // + // The dependency tree would then look like + // '_autogen_timestamp_deps (order-only)' <- '/timestamp' file <- + // '_autogen' target. + const auto timestampTargetName = + cmStrCat(this->GenTarget->GetName(), "_autogen_timestamp_deps"); + + auto cc = cm::make_unique(); + cc->SetWorkingDirectory(this->Dir.Work.c_str()); + cc->SetDepends(dependencies); + cc->SetEscapeOldStyle(false); + timestampTarget = this->LocalGen->AddUtilityCommand(timestampTargetName, + true, std::move(cc)); + + this->LocalGen->AddGeneratorTarget( + cm::make_unique(timestampTarget, this->LocalGen)); + + // Set FOLDER property on the timestamp target, so it appears in the + // appropriate folder in an IDE or in the file api. + if (!this->TargetsFolder.empty()) { + timestampTarget->SetProperty("FOLDER", this->TargetsFolder); + } + + // Make '/timestamp' file depend on '_autogen_timestamp_deps' and on the + // moc and uic executables (whichever are enabled). + dependencies.clear(); + dependencies.push_back(timestampTargetName); AddAutogenExecutableToDependencies(this->Moc, dependencies); AddAutogenExecutableToDependencies(this->Uic, dependencies); @@ -1544,7 +1568,7 @@ bool cmQtAutoGenInitializer::InitAutogenTarget() { cmSystemTools::GetCMakeCommand(), "-E", "touch", outputFile })); this->AddGeneratedSource(outputFile, this->Moc); } - auto cc = cm::make_unique(); + cc = cm::make_unique(); cc->SetOutputs(outputFile); cc->SetByproducts(timestampByproducts); cc->SetDepends(dependencies); -- cgit v0.12 From 8a526f6a4481cbf69ffed6dc045457f4c1436783 Mon Sep 17 00:00:00 2001 From: Orkun Tokdemir Date: Tue, 26 Nov 2024 11:44:43 +0100 Subject: Autogen: Fix Ninja Multi-Config dependency graph regression In commit 5363bebc1e (Autogen: Fix compilation of unchanged source files, 2024-07-16, v3.31.0-rc1~328^2) we relied on Ninja Multi-Config dependency graph optimizations from commit 7c39dabdbc (Autogen: AUTO*_EXECUTABLE: add support for per-config values, 2023-10-18, v3.29.0-rc1~105^2~1). However, those graph optimizations are conditional on versions of Qt that enable [`AUTOGEN_BETTER_GRAPH_MULTI_CONFIG`](https://codereview.qt-project.org/c/qt/qtbase/+/513648). `UseBetterGraph` should be checked to add ui files to `timestampByproducts`. Fixes: #26475 --- Source/cmQtAutoGenInitializer.cxx | 25 +++++++++++++++++++------ Tests/RunCMake/Autogen_6/RunCMakeTest.cmake | 1 + 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/Source/cmQtAutoGenInitializer.cxx b/Source/cmQtAutoGenInitializer.cxx index 63b97f3..b75a574 100644 --- a/Source/cmQtAutoGenInitializer.cxx +++ b/Source/cmQtAutoGenInitializer.cxx @@ -1340,12 +1340,25 @@ bool cmQtAutoGenInitializer::InitAutogenTarget() } if (this->Uic.Enabled) { - // Make all ui_*.h files byproducts of the ${target}_autogen/timestamp - // custom command if the generation of depfile is enabled. - auto& byProducts = useDepfile ? timestampByproducts : autogenByproducts; - for (auto const& file : this->Uic.UiHeaders) { - this->AddGeneratedSource(file.first, this->Uic); - byProducts.push_back(file.second); + auto const useAdvancedUicGraph = [this]() -> bool { + if (this->MultiConfig && this->GlobalGen->IsNinja()) { + return this->UseBetterGraph; + } + return true; + }(); + if (useAdvancedUicGraph) { + // Make all ui_*.h files byproducts of the ${target}_autogen/timestamp + // custom command if the generation of depfile is enabled. + auto& byProducts = useDepfile ? timestampByproducts : autogenByproducts; + for (auto const& file : this->Uic.UiHeaders) { + this->AddGeneratedSource(file.first, this->Uic); + byProducts.push_back(file.second); + } + } else { + for (auto const& file : this->Uic.UiHeaders) { + this->AddGeneratedSource(file.first, this->Uic); + autogenByproducts.push_back(file.second); + } } } diff --git a/Tests/RunCMake/Autogen_6/RunCMakeTest.cmake b/Tests/RunCMake/Autogen_6/RunCMakeTest.cmake index b629a5c..66514f9 100644 --- a/Tests/RunCMake/Autogen_6/RunCMakeTest.cmake +++ b/Tests/RunCMake/Autogen_6/RunCMakeTest.cmake @@ -6,6 +6,7 @@ if (DEFINED with_qt_version) -Dwith_qt_version=${with_qt_version} "-DQt${with_qt_version}_DIR:PATH=${Qt${with_qt_version}_DIR}" "-DCMAKE_PREFIX_PATH:STRING=${CMAKE_PREFIX_PATH}" + "-DCMAKE_AUTOGEN_BETTER_GRAPH_MULTI_CONFIG=ON" ) if (QtCore_VERSION VERSION_GREATER_EQUAL 5.15.0) macro(set_test_variables_for_unwanted_builds) -- cgit v0.12