Autogen: Add timestamp file for CMAKE_GLOBAL_AUTORCC_TARGET

When `CMAKE_GLOBAL_AUTORCC_TARGET` is ON and qrc files are not
generated, `<target_name>_arcc_data` is always dirty. So this commit
adds a timestamp file which depens on what `<target_name>_arcc_data`
depends before and ``<target_name>_arcc_data` depends the timestamp
file.

The dependency graph before
(qrcFile, InfoFile) -> _arcc_target

The dependency graph after
(qrcFile, InfoFile) -> global_rcc_timestamp ->_arcc_target

Fixes: #26059
This commit is contained in:
Orkun Tokdemir
2024-06-24 18:28:27 +02:00
parent 003830f14f
commit 8d99e71b7e
2 changed files with 51 additions and 5 deletions
+35 -5
View File
@@ -1697,13 +1697,43 @@ bool cmQtAutoGenInitializer::InitRccTargets()
if (!qrc.Unique) {
ccName += cmStrCat('_', qrc.QrcPathChecksum);
}
cmTarget* autoRccTarget = nullptr;
// When CMAKE_GLOBAL_AUTORCC_TARGET is ON and qrc is not generated,
// Add generate a timestamp file and a custom command to touch it.
// This will ensure that the global autorcc target is run only when the
// qrc file changes.
if (!qrc.Generated && this->Rcc.GlobalTarget) {
cm::string_view const timestampFileName = "global_rcc_timestamp";
auto const outputFile =
cmStrCat(this->Dir.Build, "/", timestampFileName);
commandLines.push_back(cmMakeCommandLine(
{ cmSystemTools::GetCMakeCommand(), "-E", "touch", outputFile }));
cc->SetByproducts(ccOutput);
cc->SetDepends(ccDepends);
cc->SetEscapeOldStyle(false);
cc->SetOutputs(outputFile);
cc->SetCommandLines(commandLines);
this->LocalGen->AddCustomCommandToOutput(std::move(cc));
this->AddGeneratedSource(outputFile, this->Rcc);
ccDepends.clear();
ccDepends.push_back(outputFile);
cc->SetByproducts(ccOutput);
cc->SetDepends(ccDepends);
cc->SetEscapeOldStyle(false);
cmTarget* autoRccTarget =
this->LocalGen->AddUtilityCommand(ccName, true, std::move(cc));
auto ccRccTarget = cm::make_unique<cmCustomCommand>();
ccRccTarget->SetWorkingDirectory(this->Dir.Work.c_str());
ccRccTarget->SetComment(ccComment.c_str());
ccRccTarget->SetStdPipesUTF8(true);
ccRccTarget->SetDepends(ccDepends);
ccRccTarget->SetEscapeOldStyle(false);
autoRccTarget = this->LocalGen->AddUtilityCommand(
ccName, true, std::move(ccRccTarget));
} else {
cc->SetByproducts(ccOutput);
cc->SetDepends(ccDepends);
cc->SetEscapeOldStyle(false);
autoRccTarget =
this->LocalGen->AddUtilityCommand(ccName, true, std::move(cc));
}
// Create autogen generator target
this->LocalGen->AddGeneratorTarget(
cm::make_unique<cmGeneratorTarget>(autoRccTarget, this->LocalGen));