summaryrefslogtreecommitdiffstats
path: root/Source
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2021-12-22 13:51:57 (GMT)
committerKitware Robot <kwrobot@kitware.com>2021-12-22 13:52:13 (GMT)
commit217f363cac32c59ee05ccc4856396a099150475b (patch)
treeafa9c6c9d5f6785b938040515a883f412a0b7b07 /Source
parent68b0c62a72a4d3352ed909c208400d02e65a4b61 (diff)
parent37af6c33116af75a9538861268edab0ddc202d79 (diff)
downloadCMake-217f363cac32c59ee05ccc4856396a099150475b.zip
CMake-217f363cac32c59ee05ccc4856396a099150475b.tar.gz
CMake-217f363cac32c59ee05ccc4856396a099150475b.tar.bz2
Merge topic 'link-only-targets'
37af6c3311 target_link_libraries: Optionally require only target names 5134f099a3 cmGeneratorTarget: Factor out message about reasons for a missing target 37a25072ea Tests: Rename RunCMake.{CMP0028 => LinkItemValidation} Acked-by: Kitware Robot <kwrobot@kitware.com> Tested-by: buildbot <buildbot@kitware.com> Merge-request: !6821
Diffstat (limited to 'Source')
-rw-r--r--Source/cmGeneratorTarget.cxx65
-rw-r--r--Source/cmGeneratorTarget.h1
-rw-r--r--Source/cmTarget.cxx3
3 files changed, 64 insertions, 5 deletions
diff --git a/Source/cmGeneratorTarget.cxx b/Source/cmGeneratorTarget.cxx
index e370472..b651104 100644
--- a/Source/cmGeneratorTarget.cxx
+++ b/Source/cmGeneratorTarget.cxx
@@ -6247,6 +6247,18 @@ cmComputeLinkInformation* cmGeneratorTarget::GetLinkInformation(
void cmGeneratorTarget::CheckLinkLibraries() const
{
+ bool linkLibrariesOnlyTargets =
+ this->GetPropertyAsBool("LINK_LIBRARIES_ONLY_TARGETS");
+
+ // Evaluate the link interface of this target if needed for extra checks.
+ if (linkLibrariesOnlyTargets) {
+ std::vector<std::string> const& configs =
+ this->Makefile->GetGeneratorConfigs(cmMakefile::IncludeEmptyConfig);
+ for (std::string const& config : configs) {
+ this->GetLinkInterfaceLibraries(config, this, LinkInterfaceFor::Link);
+ }
+ }
+
// Check link the implementation for each generated configuration.
for (auto const& hmp : this->LinkImplMap) {
HeadToLinkImplementationMap const& hm = hmp.second;
@@ -6260,6 +6272,10 @@ void cmGeneratorTarget::CheckLinkLibraries() const
if (!this->VerifyLinkItemColons(LinkItemRole::Implementation, item)) {
return;
}
+ if (linkLibrariesOnlyTargets &&
+ !this->VerifyLinkItemIsTarget(LinkItemRole::Implementation, item)) {
+ return;
+ }
}
}
@@ -6276,11 +6292,23 @@ void cmGeneratorTarget::CheckLinkLibraries() const
if (!this->VerifyLinkItemColons(LinkItemRole::Interface, item)) {
return;
}
+ if (linkLibrariesOnlyTargets &&
+ !this->VerifyLinkItemIsTarget(LinkItemRole::Interface, item)) {
+ return;
+ }
}
}
}
}
+namespace {
+cm::string_view missingTargetPossibleReasons =
+ "Possible reasons include:\n"
+ " * There is a typo in the target name.\n"
+ " * A find_package call is missing for an IMPORTED target.\n"
+ " * An ALIAS target is missing.\n"_s;
+}
+
bool cmGeneratorTarget::VerifyLinkItemColons(LinkItemRole role,
cmLinkItem const& item) const
{
@@ -6309,11 +6337,9 @@ bool cmGeneratorTarget::VerifyLinkItemColons(LinkItemRole role,
e = cmStrCat(e, "The link interface of target \"", this->GetName(),
"\" contains");
}
- e = cmStrCat(e, ":\n ", item.AsStr(), "\n",
- "but the target was not found. Possible reasons include:\n"
- " * There is a typo in the target name.\n"
- " * A find_package call is missing for an IMPORTED target.\n"
- " * An ALIAS target is missing.\n");
+ e =
+ cmStrCat(e, ":\n ", item.AsStr(), "\n", "but the target was not found. ",
+ missingTargetPossibleReasons);
cmListFileBacktrace backtrace = item.Backtrace;
if (backtrace.Empty()) {
backtrace = this->GetBacktrace();
@@ -6323,6 +6349,35 @@ bool cmGeneratorTarget::VerifyLinkItemColons(LinkItemRole role,
return false;
}
+bool cmGeneratorTarget::VerifyLinkItemIsTarget(LinkItemRole role,
+ cmLinkItem const& item) const
+{
+ if (item.Target) {
+ return true;
+ }
+ std::string const& str = item.AsStr();
+ if (!str.empty() &&
+ (str[0] == '-' || str[0] == '$' || str[0] == '`' ||
+ str.find_first_of("/\\") != std::string::npos)) {
+ return true;
+ }
+
+ std::string e = cmStrCat("Target \"", this->GetName(),
+ "\" has LINK_LIBRARIES_ONLY_TARGETS enabled, but ",
+ role == LinkItemRole::Implementation
+ ? "it links to"
+ : "its link interface contains",
+ ":\n ", item.AsStr(), "\nwhich is not a target. ",
+ missingTargetPossibleReasons);
+ cmListFileBacktrace backtrace = item.Backtrace;
+ if (backtrace.Empty()) {
+ backtrace = this->GetBacktrace();
+ }
+ this->LocalGenerator->GetCMakeInstance()->IssueMessage(
+ MessageType::FATAL_ERROR, e, backtrace);
+ return false;
+}
+
void cmGeneratorTarget::GetTargetVersion(int& major, int& minor) const
{
int patch;
diff --git a/Source/cmGeneratorTarget.h b/Source/cmGeneratorTarget.h
index 096e2ea..5f317c4 100644
--- a/Source/cmGeneratorTarget.h
+++ b/Source/cmGeneratorTarget.h
@@ -982,6 +982,7 @@ private:
Implementation,
Interface,
};
+ bool VerifyLinkItemIsTarget(LinkItemRole role, cmLinkItem const& item) const;
bool VerifyLinkItemColons(LinkItemRole role, cmLinkItem const& item) const;
// Cache import information from properties for each configuration.
diff --git a/Source/cmTarget.cxx b/Source/cmTarget.cxx
index 38361cc..c03a252 100644
--- a/Source/cmTarget.cxx
+++ b/Source/cmTarget.cxx
@@ -471,6 +471,9 @@ cmTarget::cmTarget(std::string const& name, cmStateEnums::TargetType type,
initProp(property);
}
}
+ if (!this->IsImported()) {
+ initProp("LINK_LIBRARIES_ONLY_TARGETS");
+ }
}
// Save the backtrace of target construction.