summaryrefslogtreecommitdiffstats
path: root/Source/cmGeneratorTarget.cxx
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2020-01-17 14:41:02 (GMT)
committerKitware Robot <kwrobot@kitware.com>2020-01-17 14:41:10 (GMT)
commita7fca06c464e7de3267a734aa26c043901b92f43 (patch)
treede47b7d8ac9f2bdccf44e46395e1e857f265c0c1 /Source/cmGeneratorTarget.cxx
parentcd6f6b2a9f62564127a055cf8160404141fe2259 (diff)
parentf0e67da0615bd746626cab8e4dff2ba60c7aa2fe (diff)
downloadCMake-a7fca06c464e7de3267a734aa26c043901b92f43.zip
CMake-a7fca06c464e7de3267a734aa26c043901b92f43.tar.gz
CMake-a7fca06c464e7de3267a734aa26c043901b92f43.tar.bz2
Merge topic 'out-of-dir-link-list'
f0e67da061 target_link_libraries: Fix out-of-dir linking of a list of targets acee629103 cmTargetLinkLibrariesCommand: Move HandleLibrary to helper struct ba675f1ecc Tests: Enable CMP0022 in ExportImport out-of-dir linking case Acked-by: Kitware Robot <kwrobot@kitware.com> Merge-request: !4226
Diffstat (limited to 'Source/cmGeneratorTarget.cxx')
-rw-r--r--Source/cmGeneratorTarget.cxx77
1 files changed, 46 insertions, 31 deletions
diff --git a/Source/cmGeneratorTarget.cxx b/Source/cmGeneratorTarget.cxx
index b3fb132..4158c53 100644
--- a/Source/cmGeneratorTarget.cxx
+++ b/Source/cmGeneratorTarget.cxx
@@ -5407,16 +5407,39 @@ void cmGeneratorTarget::ReportPropertyOrigin(
areport);
}
+bool cmGeneratorTarget::IsLinkLookupScope(std::string const& n,
+ cmLocalGenerator const*& lg) const
+{
+ if (cmHasLiteralPrefix(n, CMAKE_DIRECTORY_ID_SEP)) {
+ cmDirectoryId const dirId = n.substr(sizeof(CMAKE_DIRECTORY_ID_SEP) - 1);
+ if (dirId.String.empty()) {
+ lg = this->LocalGenerator;
+ return true;
+ }
+ if (cmLocalGenerator const* otherLG =
+ this->GlobalGenerator->FindLocalGenerator(dirId)) {
+ lg = otherLG;
+ return true;
+ }
+ }
+ return false;
+}
+
void cmGeneratorTarget::LookupLinkItems(std::vector<std::string> const& names,
cmListFileBacktrace const& bt,
std::vector<cmLinkItem>& items) const
{
+ cmLocalGenerator const* lg = this->LocalGenerator;
for (std::string const& n : names) {
+ if (this->IsLinkLookupScope(n, lg)) {
+ continue;
+ }
+
std::string name = this->CheckCMP0004(n);
if (name == this->GetName() || name.empty()) {
continue;
}
- items.push_back(this->ResolveLinkItem(name, bt));
+ items.push_back(this->ResolveLinkItem(name, bt, lg));
}
}
@@ -5425,6 +5448,7 @@ void cmGeneratorTarget::ExpandLinkItems(
cmGeneratorTarget const* headTarget, bool usage_requirements_only,
std::vector<cmLinkItem>& items, bool& hadHeadSensitiveCondition) const
{
+ // Keep this logic in sync with ComputeLinkImplementationLibraries.
cmGeneratorExpression ge;
cmGeneratorExpressionDAGChecker dagChecker(this, prop, nullptr, nullptr);
// The $<LINK_ONLY> expression may be in a link interface to specify private
@@ -6500,6 +6524,7 @@ void cmGeneratorTarget::ComputeLinkImplementationLibraries(
const std::string& config, cmOptionalLinkImplementation& impl,
cmGeneratorTarget const* head) const
{
+ cmLocalGenerator const* lg = this->LocalGenerator;
cmStringRange entryRange = this->Target->GetLinkImplementationEntries();
cmBacktraceRange btRange = this->Target->GetLinkImplementationBacktraces();
cmBacktraceRange::const_iterator btIt = btRange.begin();
@@ -6508,6 +6533,7 @@ void cmGeneratorTarget::ComputeLinkImplementationLibraries(
end = entryRange.end();
le != end; ++le, ++btIt) {
std::vector<std::string> llibs;
+ // Keep this logic in sync with ExpandLinkItems.
cmGeneratorExpressionDAGChecker dagChecker(this, "LINK_LIBRARIES", nullptr,
nullptr);
cmGeneratorExpression ge(*btIt);
@@ -6520,6 +6546,10 @@ void cmGeneratorTarget::ComputeLinkImplementationLibraries(
}
for (std::string const& lib : llibs) {
+ if (this->IsLinkLookupScope(lib, lg)) {
+ continue;
+ }
+
// Skip entries that resolve to the target itself or are empty.
std::string name = this->CheckCMP0004(lib);
if (name == this->GetName() || name.empty()) {
@@ -6554,7 +6584,7 @@ void cmGeneratorTarget::ComputeLinkImplementationLibraries(
}
// The entry is meant for this configuration.
- impl.Libraries.emplace_back(this->ResolveLinkItem(name, *btIt),
+ impl.Libraries.emplace_back(this->ResolveLinkItem(name, *btIt, lg),
evaluated != *le);
}
@@ -6591,38 +6621,16 @@ void cmGeneratorTarget::ComputeLinkImplementationLibraries(
cmGeneratorTarget::TargetOrString cmGeneratorTarget::ResolveTargetReference(
std::string const& name) const
{
- cmLocalGenerator const* lg = this->LocalGenerator;
- std::string const* lookupName = &name;
-
- // When target_link_libraries() is called with a LHS target that is
- // not created in the calling directory it adds a directory id suffix
- // that we can use to look up the calling directory. It is that scope
- // in which the item name is meaningful. This case is relatively rare
- // so we allocate a separate string only when the directory id is present.
- std::string::size_type pos = name.find(CMAKE_DIRECTORY_ID_SEP);
- std::string plainName;
- if (pos != std::string::npos) {
- // We will look up the plain name without the directory id suffix.
- plainName = name.substr(0, pos);
-
- // We will look up in the scope of the directory id.
- // If we do not recognize the id then leave the original
- // syntax in place to produce an indicative error later.
- cmDirectoryId const dirId =
- name.substr(pos + sizeof(CMAKE_DIRECTORY_ID_SEP) - 1);
- if (cmLocalGenerator const* otherLG =
- this->GlobalGenerator->FindLocalGenerator(dirId)) {
- lg = otherLG;
- lookupName = &plainName;
- }
- }
+ return this->ResolveTargetReference(name, this->LocalGenerator);
+}
+cmGeneratorTarget::TargetOrString cmGeneratorTarget::ResolveTargetReference(
+ std::string const& name, cmLocalGenerator const* lg) const
+{
TargetOrString resolved;
- if (cmGeneratorTarget* tgt = lg->FindGeneratorTargetToUse(*lookupName)) {
+ if (cmGeneratorTarget* tgt = lg->FindGeneratorTargetToUse(name)) {
resolved.Target = tgt;
- } else if (lookupName == &plainName) {
- resolved.String = std::move(plainName);
} else {
resolved.String = name;
}
@@ -6633,7 +6641,14 @@ cmGeneratorTarget::TargetOrString cmGeneratorTarget::ResolveTargetReference(
cmLinkItem cmGeneratorTarget::ResolveLinkItem(
std::string const& name, cmListFileBacktrace const& bt) const
{
- TargetOrString resolved = this->ResolveTargetReference(name);
+ return this->ResolveLinkItem(name, bt, this->LocalGenerator);
+}
+
+cmLinkItem cmGeneratorTarget::ResolveLinkItem(std::string const& name,
+ cmListFileBacktrace const& bt,
+ cmLocalGenerator const* lg) const
+{
+ TargetOrString resolved = this->ResolveTargetReference(name, lg);
if (!resolved.Target) {
return cmLinkItem(resolved.String, bt);