From c404f64289bbf93bb7212df913a115e8c0c81e9d Mon Sep 17 00:00:00 2001 From: Brad King Date: Tue, 27 Oct 2020 11:24:51 -0400 Subject: cmCustomCommandGenerator: Collect genex target references in commands These will become target-level dependencies. --- Source/cmCustomCommandGenerator.cxx | 26 ++++++++++++++++++++++---- Source/cmCustomCommandGenerator.h | 5 +++++ 2 files changed, 27 insertions(+), 4 deletions(-) diff --git a/Source/cmCustomCommandGenerator.cxx b/Source/cmCustomCommandGenerator.cxx index 13d2c37..08a0574 100644 --- a/Source/cmCustomCommandGenerator.cxx +++ b/Source/cmCustomCommandGenerator.cxx @@ -62,6 +62,10 @@ cmCustomCommandGenerator::cmCustomCommandGenerator(cmCustomCommand const& cc, for (std::string const& clarg : cmdline) { std::unique_ptr cge = ge.Parse(clarg); std::string parsed_arg = cge->Evaluate(this->LG, this->Config); + for (cmGeneratorTarget* gt : cge->GetTargets()) { + this->Utilities.emplace(BT>( + { gt->GetName(), true }, cge->GetBacktrace())); + } if (this->CC->GetCommandExpandLists()) { cm::append(argv, cmExpandedList(parsed_arg)); } else { @@ -69,10 +73,18 @@ cmCustomCommandGenerator::cmCustomCommandGenerator(cmCustomCommand const& cc, } } - // Later code assumes at least one entry exists, but expanding - // lists on an empty command may have left this empty. - // FIXME: Should we define behavior for removing empty commands? - if (argv.empty()) { + if (!argv.empty()) { + // If the command references an executable target by name, + // collect the target to add a target-level dependency on it. + cmGeneratorTarget* gt = this->LG->FindGeneratorTargetToUse(argv.front()); + if (gt && gt->GetType() == cmStateEnums::EXECUTABLE) { + this->Utilities.emplace(BT>( + { gt->GetName(), true }, cc.GetBacktrace())); + } + } else { + // Later code assumes at least one entry exists, but expanding + // lists on an empty command may have left this empty. + // FIXME: Should we define behavior for removing empty commands? argv.emplace_back(); } @@ -326,3 +338,9 @@ std::vector const& cmCustomCommandGenerator::GetDepends() const { return this->Depends; } + +std::set>> const& +cmCustomCommandGenerator::GetUtilities() const +{ + return this->Utilities; +} diff --git a/Source/cmCustomCommandGenerator.h b/Source/cmCustomCommandGenerator.h index c783b65..cb0d7df 100644 --- a/Source/cmCustomCommandGenerator.h +++ b/Source/cmCustomCommandGenerator.h @@ -4,10 +4,13 @@ #include "cmConfigure.h" // IWYU pragma: keep +#include #include +#include #include #include "cmCustomCommandLines.h" +#include "cmListFileCache.h" class cmCustomCommand; class cmLocalGenerator; @@ -24,6 +27,7 @@ class cmCustomCommandGenerator std::vector Byproducts; std::vector Depends; std::string WorkingDirectory; + std::set>> Utilities; void FillEmulatorsWithArguments(); std::vector GetCrossCompilingEmulator(unsigned int c) const; @@ -46,6 +50,7 @@ public: std::vector const& GetOutputs() const; std::vector const& GetByproducts() const; std::vector const& GetDepends() const; + std::set>> const& GetUtilities() const; bool HasOnlyEmptyCommandLines() const; std::string GetFullDepfile() const; std::string GetInternalDepfile() const; -- cgit v0.12