summaryrefslogtreecommitdiff
path: root/Source
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2021-06-29 15:57:16 -0400
committerBrad King <brad.king@kitware.com>2021-06-29 16:52:12 -0400
commite27a76f1311ab4ad1be07df018ac748d4b725cea (patch)
treed52fc751827893cd9468f86460d2dc8994c94b5d /Source
parentfb02657b6a4f66cfb1b1673c170136f07945eda2 (diff)
downloadcmake-e27a76f1311ab4ad1be07df018ac748d4b725cea.tar.gz
target_link_libraries: Restore transitive out-of-dir linking
Refactoring in commit 7f506b95a7 (cmGeneratorTarget: Refactor link item lookup, 2021-05-26, v3.21.0-rc1~103^2~4) accidentally dropped the persistent lookup scope tracking across multiple items that was added by commit f0e67da061 (target_link_libraries: Fix out-of-dir linking of a list of targets, 2020-01-14, v3.17.0-rc1~149^2). This broke a transitive out-of-dir linking case not covered by our test suite. Restore the scope tracking and add a test case. Fixes: #22363
Diffstat (limited to 'Source')
-rw-r--r--Source/cmGeneratorTarget.cxx14
-rw-r--r--Source/cmGeneratorTarget.h7
2 files changed, 14 insertions, 7 deletions
diff --git a/Source/cmGeneratorTarget.cxx b/Source/cmGeneratorTarget.cxx
index f268c6c3e6..f1ef130afe 100644
--- a/Source/cmGeneratorTarget.cxx
+++ b/Source/cmGeneratorTarget.cxx
@@ -6346,11 +6346,11 @@ bool cmGeneratorTarget::IsLinkLookupScope(std::string const& n,
}
cm::optional<cmLinkItem> cmGeneratorTarget::LookupLinkItem(
- std::string const& n, cmListFileBacktrace const& bt) const
+ std::string const& n, cmListFileBacktrace const& bt,
+ LookupLinkItemScope* scope) const
{
cm::optional<cmLinkItem> maybeItem;
- cmLocalGenerator const* lg = this->LocalGenerator;
- if (this->IsLinkLookupScope(n, lg)) {
+ if (this->IsLinkLookupScope(n, scope->LG)) {
return maybeItem;
}
@@ -6358,7 +6358,7 @@ cm::optional<cmLinkItem> cmGeneratorTarget::LookupLinkItem(
if (name == this->GetName() || name.empty()) {
return maybeItem;
}
- maybeItem = this->ResolveLinkItem(name, bt, lg);
+ maybeItem = this->ResolveLinkItem(name, bt, scope->LG);
return maybeItem;
}
@@ -6385,9 +6385,10 @@ void cmGeneratorTarget::ExpandLinkItems(
&dagChecker, this, headTarget->LinkerLanguage),
libs);
cmMakefile const* mf = this->LocalGenerator->GetMakefile();
+ LookupLinkItemScope scope{ this->LocalGenerator };
for (std::string const& lib : libs) {
if (cm::optional<cmLinkItem> maybeItem =
- this->LookupLinkItem(lib, cge->GetBacktrace())) {
+ this->LookupLinkItem(lib, cge->GetBacktrace(), &scope)) {
if (!maybeItem->Target) {
// Report explicitly linked object files separately.
std::string const& maybeObj = maybeItem->AsStr();
@@ -7089,9 +7090,10 @@ const cmLinkInterface* cmGeneratorTarget::GetImportLinkInterface(
iface.HadContextSensitiveCondition,
iface.HadLinkLanguageSensitiveCondition);
std::vector<std::string> deps = cmExpandedList(info->SharedDeps);
+ LookupLinkItemScope scope{ this->LocalGenerator };
for (std::string const& dep : deps) {
if (cm::optional<cmLinkItem> maybeItem =
- this->LookupLinkItem(dep, cmListFileBacktrace())) {
+ this->LookupLinkItem(dep, cmListFileBacktrace(), &scope)) {
iface.SharedDeps.emplace_back(std::move(*maybeItem));
}
}
diff --git a/Source/cmGeneratorTarget.h b/Source/cmGeneratorTarget.h
index ed66fb1a81..6d2aa85ed2 100644
--- a/Source/cmGeneratorTarget.h
+++ b/Source/cmGeneratorTarget.h
@@ -1042,8 +1042,13 @@ private:
bool& hadHeadSensitiveCondition,
bool& hadContextSensitiveCondition,
bool& hadLinkLanguageSensitiveCondition) const;
+ struct LookupLinkItemScope
+ {
+ cmLocalGenerator const* LG;
+ };
cm::optional<cmLinkItem> LookupLinkItem(std::string const& n,
- cmListFileBacktrace const& bt) const;
+ cmListFileBacktrace const& bt,
+ LookupLinkItemScope* scope) const;
std::vector<BT<std::string>> GetSourceFilePaths(
std::string const& config) const;