diff options
author | Brad King <brad.king@kitware.com> | 2021-05-26 14:44:41 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2021-05-28 18:27:38 (GMT) |
commit | 7f506b95a78a3238d3481539810441ca955a0901 (patch) | |
tree | dffb4bf2d614a866cebd1f1af8dfbd3ef61aff19 /Source | |
parent | 96809a8541513c7adb52a65766154d417281227e (diff) | |
download | CMake-7f506b95a78a3238d3481539810441ca955a0901.zip CMake-7f506b95a78a3238d3481539810441ca955a0901.tar.gz CMake-7f506b95a78a3238d3481539810441ca955a0901.tar.bz2 |
cmGeneratorTarget: Refactor link item lookup
Look up items individually so the call sites can do something with the
result besides appending to a vector.
Diffstat (limited to 'Source')
-rw-r--r-- | Source/cmGeneratorTarget.cxx | 37 | ||||
-rw-r--r-- | Source/cmGeneratorTarget.h | 5 | ||||
-rw-r--r-- | Source/cmTargetLinkLibrariesCommand.cxx | 2 |
3 files changed, 26 insertions, 18 deletions
diff --git a/Source/cmGeneratorTarget.cxx b/Source/cmGeneratorTarget.cxx index ca18f53..51742cf 100644 --- a/Source/cmGeneratorTarget.cxx +++ b/Source/cmGeneratorTarget.cxx @@ -6255,22 +6255,21 @@ bool cmGeneratorTarget::IsLinkLookupScope(std::string const& n, return false; } -void cmGeneratorTarget::LookupLinkItems(std::vector<std::string> const& names, - cmListFileBacktrace const& bt, - std::vector<cmLinkItem>& items) const +cm::optional<cmLinkItem> cmGeneratorTarget::LookupLinkItem( + std::string const& n, cmListFileBacktrace const& bt) const { + cm::optional<cmLinkItem> maybeItem; cmLocalGenerator const* lg = this->LocalGenerator; - for (std::string const& n : names) { - if (this->IsLinkLookupScope(n, lg)) { - continue; - } + if (this->IsLinkLookupScope(n, lg)) { + return maybeItem; + } - std::string name = this->CheckCMP0004(n); - if (name == this->GetName() || name.empty()) { - continue; - } - items.push_back(this->ResolveLinkItem(name, bt, lg)); + std::string name = this->CheckCMP0004(n); + if (name == this->GetName() || name.empty()) { + return maybeItem; } + maybeItem = this->ResolveLinkItem(name, bt, lg); + return maybeItem; } void cmGeneratorTarget::ExpandLinkItems( @@ -6295,7 +6294,12 @@ void cmGeneratorTarget::ExpandLinkItems( cmExpandList(cge->Evaluate(this->LocalGenerator, config, headTarget, &dagChecker, this, headTarget->LinkerLanguage), libs); - this->LookupLinkItems(libs, cge->GetBacktrace(), items); + for (std::string const& lib : libs) { + if (cm::optional<cmLinkItem> maybeItem = + this->LookupLinkItem(lib, cge->GetBacktrace())) { + items.emplace_back(std::move(*maybeItem)); + } + } hadHeadSensitiveCondition = cge->GetHadHeadSensitiveCondition(); hadContextSensitiveCondition = cge->GetHadContextSensitiveCondition(); hadLinkLanguageSensitiveCondition = @@ -6903,7 +6907,12 @@ const cmLinkInterface* cmGeneratorTarget::GetImportLinkInterface( iface.HadContextSensitiveCondition, iface.HadLinkLanguageSensitiveCondition); std::vector<std::string> deps = cmExpandedList(info->SharedDeps); - this->LookupLinkItems(deps, cmListFileBacktrace(), iface.SharedDeps); + for (std::string const& dep : deps) { + if (cm::optional<cmLinkItem> maybeItem = + this->LookupLinkItem(dep, cmListFileBacktrace())) { + iface.SharedDeps.emplace_back(std::move(*maybeItem)); + } + } } return &iface; diff --git a/Source/cmGeneratorTarget.h b/Source/cmGeneratorTarget.h index 2935e0b..dbc47b8 100644 --- a/Source/cmGeneratorTarget.h +++ b/Source/cmGeneratorTarget.h @@ -1039,9 +1039,8 @@ private: bool& hadHeadSensitiveCondition, bool& hadContextSensitiveCondition, bool& hadLinkLanguageSensitiveCondition) const; - void LookupLinkItems(std::vector<std::string> const& names, - cmListFileBacktrace const& bt, - std::vector<cmLinkItem>& items) const; + cm::optional<cmLinkItem> LookupLinkItem(std::string const& n, + cmListFileBacktrace const& bt) const; std::vector<BT<std::string>> GetSourceFilePaths( std::string const& config) const; diff --git a/Source/cmTargetLinkLibrariesCommand.cxx b/Source/cmTargetLinkLibrariesCommand.cxx index aecc18e..3423b30 100644 --- a/Source/cmTargetLinkLibrariesCommand.cxx +++ b/Source/cmTargetLinkLibrariesCommand.cxx @@ -565,7 +565,7 @@ void TLL::AffectsProperty(std::string const& prop) if (!this->EncodeRemoteReference) { return; } - // Add a wrapper to the expression to tell LookupLinkItems to look up + // Add a wrapper to the expression to tell LookupLinkItem to look up // names in the caller's directory. if (this->Props.insert(prop).second) { this->Target->AppendProperty(prop, this->DirectoryId); |