From 7047fa76f6ad8ec634c402496e5162b71270cf54 Mon Sep 17 00:00:00 2001 From: Roger Leigh Date: Fri, 30 Oct 2026 08:16:54 +0000 Subject: [PATCH] cmTestGenerator,cmInstallGenerator: Factor out BUILD_DEPENDS entry resolution Move the resolution of a single `BUILD_DEPENDS` entry to a target or file into a local helper in `cmTestGenerator::EvaluateBuildDependencies` and `cmInstallGenerator::ResolveBuildDepends`, in preparation for also using it on values evaluated from generator expressions. No change in behavior. --- Source/cmInstallGenerator.cxx | 26 +++++++++++++++++--------- Source/cmTestGenerator.cxx | 16 ++++++++++------ 2 files changed, 27 insertions(+), 15 deletions(-) diff --git a/Source/cmInstallGenerator.cxx b/Source/cmInstallGenerator.cxx index f5a87644a0..e2c6fdacbb 100644 --- a/Source/cmInstallGenerator.cxx +++ b/Source/cmInstallGenerator.cxx @@ -288,10 +288,12 @@ bool cmInstallGenerator::ResolveBuildDepends( return gg->FindArtifactOwningTarget(file, config); }); }; - for (std::string const& name : names) { + // Resolve a name to a target or a file. + auto const resolve = [this, lg, gg, &signature, &entries, + &isArtifact](std::string const& name) -> bool { if (cmGeneratorTarget const* target = lg->FindGeneratorTargetToUse(name)) { entries.Targets.push_back(target); - continue; + return true; } // A relative path is interpreted with respect to the current source // directory if the file exists there, and otherwise the current binary @@ -300,13 +302,19 @@ bool cmInstallGenerator::ResolveBuildDepends( if (gg->IsGeneratedByBuild(file) || isArtifact(file) || cmSystemTools::FileExists(file)) { entries.Files.push_back(std::move(file)); - } else { - lg->IssueMessage( - MessageType::FATAL_ERROR, - cmStrCat("install(", signature, ") BUILD_DEPENDS entry \"", name, - "\" is neither a target nor a file that exists or is " - "generated by the build."), - this->GetBacktrace()); + return true; + } + lg->IssueMessage( + MessageType::FATAL_ERROR, + cmStrCat("install(", signature, ") BUILD_DEPENDS entry \"", name, + "\" is neither a target nor a file that exists or is " + "generated by the build."), + this->GetBacktrace()); + return false; + }; + + for (std::string const& name : names) { + if (!resolve(name)) { return false; } } diff --git a/Source/cmTestGenerator.cxx b/Source/cmTestGenerator.cxx index 3f59162b78..2d8d7def24 100644 --- a/Source/cmTestGenerator.cxx +++ b/Source/cmTestGenerator.cxx @@ -132,21 +132,25 @@ bool cmTestGenerator::EvaluateBuildDependencies( } // Add dependencies from BUILD_DEPENDS keyword - for (std::string const& depName : buildDepends) { - if (depName.empty()) { - continue; - } + cmGlobalGenerator* gg = lg->GetGlobalGenerator(); + auto addBuildDependency = [lg, gg, &dependencies, + &info](std::string const& depName) { cmGeneratorTarget* depTarget = lg->FindGeneratorTargetToUse(depName); if (!depTarget) { - cmGlobalGenerator* gg = lg->GetGlobalGenerator(); BuildDependencies::FileDependency file; file.Path = lg->GetRealFileDependency(depName); file.Owner = gg->FindOutputOwningTarget(file.Path); file.Generated = gg->IsGeneratedByBuild(file.Path); info.Files.push_back(std::move(file)); - continue; + return; } dependencies.insert(depTarget); + }; + for (std::string const& depName : buildDepends) { + if (depName.empty()) { + continue; + } + addBuildDependency(depName); } for (cmGeneratorTarget* gt : dependencies) {