Autogen: Enable depfile support for Visual Studio and Xcode generators

Extend the depfile-based AUTOGEN incremental build support to Visual
Studio and Xcode generators, in addition to the existing Ninja and
Makefile support.  Use generator name matching rather than
SupportsCustomCommandDepfile() to select generators explicitly, because
not all generators that claim depfile support handle the resulting build
graph correctly.  In particular, when depfiles are used, CMake introduces
a _autogen_timestamp_deps utility target to express ordering constraints,
and the FASTBuild generator does not correctly propagate dependencies
through utility targets that have no commands, breaking the build when
generated files are AUTOMOC inputs.

When depfiles are used, disable the PRE_BUILD optimization for Visual
Studio because PRE_BUILD events cannot carry depfile dependencies.

Fixes: #25233
Fixes: #25234
This commit is contained in:
Joerg Bornemann
2026-03-25 09:05:58 +01:00
parent d9f569c246
commit 680fbb112a
+6 -1
View File
@@ -1372,7 +1372,8 @@ bool cmQtAutoGenInitializer::InitAutogenTarget()
auto const& gen = this->GlobalGen->GetName();
return this->QtVersion >= IntegerVersion(5, 15) &&
(gen.find("Ninja") != std::string::npos ||
gen.find("Make") != std::string::npos);
gen.find("Make") != std::string::npos ||
gen.find("Visual Studio") != std::string::npos || gen == "Xcode");
}();
// Files provided by the autogen target
@@ -1453,6 +1454,10 @@ bool cmQtAutoGenInitializer::InitAutogenTarget()
if (this->AutogenTarget.GlobalTarget) {
usePRE_BUILD = false;
}
// Cannot use PRE_BUILD with depfiles
if (useDepfile) {
usePRE_BUILD = false;
}
}
// Create the autogen target/command
if (usePRE_BUILD) {