summaryrefslogtreecommitdiffstats
path: root/Source
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2015-04-07 14:43:47 (GMT)
committerBrad King <brad.king@kitware.com>2015-04-09 15:29:18 (GMT)
commit882f48e5ba335a1dbc1750c23e6dea5fa92a3adc (patch)
tree7783686bed3456d95538a4770dff27f0e24963bc /Source
parent318cd37097c724fac13a364fe3beb21055575ae7 (diff)
downloadCMake-882f48e5ba335a1dbc1750c23e6dea5fa92a3adc.zip
CMake-882f48e5ba335a1dbc1750c23e6dea5fa92a3adc.tar.gz
CMake-882f48e5ba335a1dbc1750c23e6dea5fa92a3adc.tar.bz2
Link libraries by full path even in implicit directories
When CMP0003 was first introduced we wanted to link all libraries by full path. However, some projects had problems on platforms where find_library would find /usr/lib/libfoo.so when the project really wanted to link to /usr/lib/<arch>/libfoo.so and had been working by accident because pre-CMP0003 behavior used -lfoo to link. We first tried to address that in commit v2.6.0~440 (Teach find_library to avoid returning library paths in system directories, 2008-01-23) by returning just "foo" for libraries in implicit link directories. This caused problems for projects expecting find_library to always return a full path. We ended up using the solution in commit v2.6.0~366 (... switch library paths found in implicit link directories to use -l, 2008-01-31). However, the special case for libraries in implicit link directories has also proven problematic and confusing. Introduce policy CMP0060 to switch to linking all libraries by full path even if they are in implicit link directories. Explain in the policy documentation the factors that led to the original approach and now to this approach.
Diffstat (limited to 'Source')
-rw-r--r--Source/cmComputeLinkInformation.cxx42
-rw-r--r--Source/cmComputeLinkInformation.h4
-rw-r--r--Source/cmPolicies.cxx5
-rw-r--r--Source/cmPolicies.h1
-rw-r--r--Source/cmTarget.h3
5 files changed, 54 insertions, 1 deletions
diff --git a/Source/cmComputeLinkInformation.cxx b/Source/cmComputeLinkInformation.cxx
index b0e0f36..8880667 100644
--- a/Source/cmComputeLinkInformation.cxx
+++ b/Source/cmComputeLinkInformation.cxx
@@ -411,6 +411,10 @@ cmComputeLinkInformation
std::vector<std::string> const& dirs = this->Target->GetLinkDirectories();
this->OldLinkDirMask.insert(dirs.begin(), dirs.end());
}
+
+ this->CMP0060Warn =
+ this->Makefile->PolicyOptionalWarningEnabled(
+ "CMAKE_POLICY_WARNING_CMP0060");
}
//----------------------------------------------------------------------------
@@ -548,6 +552,22 @@ bool cmComputeLinkInformation::Compute()
// Add implicit language runtime libraries and directories.
this->AddImplicitLinkInfo();
+ if (!this->CMP0060WarnItems.empty())
+ {
+ std::ostringstream w;
+ w << (this->Makefile->GetCMakeInstance()->GetPolicies()
+ ->GetPolicyWarning(cmPolicies::CMP0060)) << "\n"
+ "Some library files are in directories implicitly searched by "
+ "the linker when invoked for " << this->LinkLanguage << ":\n"
+ " " << cmJoin(this->CMP0060WarnItems, "\n ") << "\n"
+ "For compatibility with older versions of CMake, the generated "
+ "link line will ask the linker to search for these by library "
+ "name."
+ ;
+ this->CMakeInstance->IssueMessage(cmake::AUTHOR_WARNING, w.str(),
+ this->Target->GetBacktrace());
+ }
+
return true;
}
@@ -1190,6 +1210,28 @@ bool cmComputeLinkInformation::CheckImplicitDirItem(std::string const& item)
return false;
}
+ // Check the policy for whether we should use the approach below.
+ switch (this->Target->GetPolicyStatusCMP0060())
+ {
+ case cmPolicies::WARN:
+ if (this->CMP0060Warn)
+ {
+ // Print the warning at most once for this item.
+ std::string const& wid = "CMP0060-WARNING-GIVEN-" + item;
+ if (!this->CMakeInstance->GetPropertyAsBool(wid))
+ {
+ this->CMakeInstance->SetProperty(wid, "1");
+ this->CMP0060WarnItems.insert(item);
+ }
+ }
+ case cmPolicies::OLD:
+ break;
+ case cmPolicies::REQUIRED_ALWAYS:
+ case cmPolicies::REQUIRED_IF_USED:
+ case cmPolicies::NEW:
+ return false;
+ }
+
// Many system linkers support multiple architectures by
// automatically selecting the implicit linker search path for the
// current architecture. If the library appears in an implicit link
diff --git a/Source/cmComputeLinkInformation.h b/Source/cmComputeLinkInformation.h
index e5d674a..8847141 100644
--- a/Source/cmComputeLinkInformation.h
+++ b/Source/cmComputeLinkInformation.h
@@ -175,6 +175,10 @@ private:
std::vector<std::string> OldUserFlagItems;
bool OldLinkDirMode;
+ // CMP0060 warnings.
+ bool CMP0060Warn;
+ std::set<std::string> CMP0060WarnItems;
+
// Runtime path computation.
cmOrderDirectories* OrderRuntimeSearchPath;
void AddLibraryRuntimeInfo(std::string const& fullPath,
diff --git a/Source/cmPolicies.cxx b/Source/cmPolicies.cxx
index 0a61bca..e7678cb 100644
--- a/Source/cmPolicies.cxx
+++ b/Source/cmPolicies.cxx
@@ -390,6 +390,11 @@ cmPolicies::cmPolicies()
CMP0059, "CMP0059",
"Do no treat DEFINITIONS as a built-in directory property.",
3,3,0, cmPolicies::WARN);
+
+ this->DefinePolicy(
+ CMP0060, "CMP0060",
+ "Link libraries by full path even in implicit directories.",
+ 3,3,0, cmPolicies::WARN);
}
cmPolicies::~cmPolicies()
diff --git a/Source/cmPolicies.h b/Source/cmPolicies.h
index ced9d8c..1d108c1 100644
--- a/Source/cmPolicies.h
+++ b/Source/cmPolicies.h
@@ -118,6 +118,7 @@ public:
CMP0058, ///< Ninja requires custom command byproducts to be explicit
CMP0059, ///< Do not treat ``DEFINITIONS`` as a built-in directory
/// property.
+ CMP0060, ///< Link libraries by full path even in implicit directories.
/** \brief Always the last entry.
*
diff --git a/Source/cmTarget.h b/Source/cmTarget.h
index a4ef977..55bf234 100644
--- a/Source/cmTarget.h
+++ b/Source/cmTarget.h
@@ -34,7 +34,8 @@
F(CMP0041) \
F(CMP0042) \
F(CMP0046) \
- F(CMP0052)
+ F(CMP0052) \
+ F(CMP0060)
class cmake;
class cmMakefile;