summaryrefslogtreecommitdiffstats
path: root/Source/cmTargetLinkLibrariesCommand.cxx
diff options
context:
space:
mode:
authorPatrick Stotko <stotko@cs.uni-bonn.de>2018-05-11 16:06:53 (GMT)
committerBrad King <brad.king@kitware.com>2018-05-15 14:22:35 (GMT)
commitc9349cc1b94a08b4f5ed86a397e72ceed50847dd (patch)
treed7df775c58c8f2c539e848abf7dc513a6f4d9a20 /Source/cmTargetLinkLibrariesCommand.cxx
parent743f24bac68010c0157dc0349958e09ed1784f5f (diff)
downloadCMake-c9349cc1b94a08b4f5ed86a397e72ceed50847dd.zip
CMake-c9349cc1b94a08b4f5ed86a397e72ceed50847dd.tar.gz
CMake-c9349cc1b94a08b4f5ed86a397e72ceed50847dd.tar.bz2
target_link_libraries: Allow use with targets in other directories
Previously the command did not allow naming targets on the LHS that were not created in the calling directory. Lift this restriction to enable more flexible use by projects. Fixes: #17943
Diffstat (limited to 'Source/cmTargetLinkLibrariesCommand.cxx')
-rw-r--r--Source/cmTargetLinkLibrariesCommand.cxx11
1 files changed, 9 insertions, 2 deletions
diff --git a/Source/cmTargetLinkLibrariesCommand.cxx b/Source/cmTargetLinkLibrariesCommand.cxx
index 699fff8..53f1213 100644
--- a/Source/cmTargetLinkLibrariesCommand.cxx
+++ b/Source/cmTargetLinkLibrariesCommand.cxx
@@ -364,7 +364,7 @@ bool cmTargetLinkLibrariesCommand::HandleLibrary(const std::string& lib,
if (this->CurrentProcessingState != ProcessingKeywordLinkInterface &&
this->CurrentProcessingState != ProcessingPlainLinkInterface) {
- // Assure that the target on the LHS was created in the current directory.
+ // Find target on the LHS locally
cmTarget* t =
this->Makefile->FindLocalNonAliasTarget(this->Target->GetName());
if (!t) {
@@ -377,11 +377,18 @@ bool cmTargetLinkLibrariesCommand::HandleLibrary(const std::string& lib,
}
}
}
+
+ // If no local target has been found, find it in the global scope
+ if (!t) {
+ t = this->Makefile->GetGlobalGenerator()->FindTarget(
+ this->Target->GetName(), true);
+ }
+
if (!t) {
std::ostringstream e;
e << "Attempt to add link library \"" << lib << "\" to target \""
<< this->Target->GetName()
- << "\" which is not built in this directory.";
+ << "\" which does not exist or is an alias target.";
this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str());
return false;
}