summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Source/cmComputeLinkDepends.cxx52
-rw-r--r--Source/cmComputeLinkDepends.h2
-rw-r--r--Source/cmPolicies.cxx16
-rw-r--r--Source/cmPolicies.h1
-rw-r--r--Source/cmTarget.cxx3
-rw-r--r--Source/cmTarget.h5
6 files changed, 68 insertions, 11 deletions
diff --git a/Source/cmComputeLinkDepends.cxx b/Source/cmComputeLinkDepends.cxx
index ecbb129..5005e96 100644
--- a/Source/cmComputeLinkDepends.cxx
+++ b/Source/cmComputeLinkDepends.cxx
@@ -21,6 +21,7 @@
#include "cmLocalGenerator.h"
#include "cmMakefile.h"
#include "cmTarget.h"
+#include "cmake.h"
#include <cmsys/stl/algorithm>
@@ -161,6 +162,7 @@ cmComputeLinkDepends
this->Makefile = this->Target->GetMakefile();
this->LocalGenerator = this->Makefile->GetLocalGenerator();
this->GlobalGenerator = this->LocalGenerator->GetGlobalGenerator();
+ this->CMakeInstance = this->GlobalGenerator->GetCMakeInstance();
// The configuration being linked.
this->Config = config;
@@ -568,17 +570,45 @@ std::string cmComputeLinkDepends::CleanItemName(std::string const& item)
{
lib = lib.substr(0, pos+1);
}
- if(lib != item && !this->Makefile->NeedBackwardsCompatibility(2,4))
- {
- cmOStringStream e;
- e << "Target \"" << this->Target->GetName() << "\" links to item \""
- << item << "\" which has leading or trailing whitespace. "
- << "CMake is stripping off the whitespace but this may not be "
- << "supported in the future. "
- << "Update the CMakeLists.txt files to avoid adding the whitespace. "
- << "Set CMAKE_BACKWARDS_COMPATIBILITY to 2.4 or lower to disable this "
- << "warning.";
- cmSystemTools::Message(e.str().c_str());
+ if(lib != item)
+ {
+ switch(this->Target->GetPolicyStatusCMP0004())
+ {
+ case cmPolicies::WARN:
+ {
+ cmOStringStream w;
+ w << (this->Makefile->GetPolicies()
+ ->GetPolicyWarning(cmPolicies::CMP0004)) << "\n"
+ << "Target \"" << this->Target->GetName() << "\" links to item \""
+ << item << "\" which has leading or trailing whitespace.";
+ this->CMakeInstance->IssueMessage(cmake::AUTHOR_WARNING, w.str(),
+ this->Target->GetBacktrace());
+ }
+ case cmPolicies::OLD:
+ break;
+ case cmPolicies::NEW:
+ {
+ cmOStringStream e;
+ e << "Target \"" << this->Target->GetName() << "\" links to item \""
+ << item << "\" which has leading or trailing whitespace. "
+ << "This is now an error according to policy CMP0004.";
+ this->CMakeInstance->IssueMessage(cmake::FATAL_ERROR, e.str(),
+ this->Target->GetBacktrace());
+ }
+ break;
+ case cmPolicies::REQUIRED_IF_USED:
+ case cmPolicies::REQUIRED_ALWAYS:
+ {
+ cmOStringStream e;
+ e << (this->Makefile->GetPolicies()
+ ->GetRequiredPolicyError(cmPolicies::CMP0004)) << "\n"
+ << "Target \"" << this->Target->GetName() << "\" links to item \""
+ << item << "\" which has leading or trailing whitespace.";
+ this->CMakeInstance->IssueMessage(cmake::FATAL_ERROR, e.str(),
+ this->Target->GetBacktrace());
+ }
+ break;
+ }
}
return lib;
}
diff --git a/Source/cmComputeLinkDepends.h b/Source/cmComputeLinkDepends.h
index c208909..de85fa0 100644
--- a/Source/cmComputeLinkDepends.h
+++ b/Source/cmComputeLinkDepends.h
@@ -29,6 +29,7 @@ class cmGlobalGenerator;
class cmLocalGenerator;
class cmMakefile;
class cmTarget;
+class cmake;
/** \class cmComputeLinkDepends
* \brief Compute link dependencies for targets.
@@ -60,6 +61,7 @@ private:
cmMakefile* Makefile;
cmLocalGenerator* LocalGenerator;
cmGlobalGenerator* GlobalGenerator;
+ cmake* CMakeInstance;
bool DebugMode;
// Configuration information.
diff --git a/Source/cmPolicies.cxx b/Source/cmPolicies.cxx
index 06133bc..ffe4554 100644
--- a/Source/cmPolicies.cxx
+++ b/Source/cmPolicies.cxx
@@ -200,6 +200,22 @@ cmPolicies::cmPolicies()
"When all items on the link line have known paths CMake does not check "
"this policy so it has no effect.",
2,6,0, cmPolicies::WARN);
+
+ this->DefinePolicy(
+ CMP0004, "CMP0004",
+ "Libraries linked may not have leading or trailing whitespace.",
+ "CMake versions 2.4 and below silently removed leading and trailing "
+ "whitespace from libraries linked with code like\n"
+ " target_link_libraries(myexe \" A \")\n"
+ "This could lead to subtle errors in user projects.\n"
+ "The OLD behavior for this policy is to silently remove leading and "
+ "trailing whitespace. "
+ "The NEW behavior for this policy is to diagnose the existence of "
+ "such whitespace as an error. "
+ "The setting for this policy used when checking the library names is "
+ "that in effect when the target is created by an add_executable or "
+ "add_library command.",
+ 2,6,0, cmPolicies::WARN);
}
cmPolicies::~cmPolicies()
diff --git a/Source/cmPolicies.h b/Source/cmPolicies.h
index 4ca6a6b..1a2a32c 100644
--- a/Source/cmPolicies.h
+++ b/Source/cmPolicies.h
@@ -44,6 +44,7 @@ public:
CMP0001, // Ignore old compatibility variable
CMP0002, // Target names must be unique
CMP0003, // Linking does not include extra -L paths
+ CMP0004, // Libraries linked may not have leading or trailing whitespace
// Always the last entry. Useful mostly to avoid adding a comma
// the last policy when adding a new one.
diff --git a/Source/cmTarget.cxx b/Source/cmTarget.cxx
index 5811285..2f695da 100644
--- a/Source/cmTarget.cxx
+++ b/Source/cmTarget.cxx
@@ -54,6 +54,7 @@ cmTarget::cmTarget()
{
this->Makefile = 0;
this->PolicyStatusCMP0003 = cmPolicies::WARN;
+ this->PolicyStatusCMP0004 = cmPolicies::WARN;
this->LinkLibrariesAnalyzed = false;
this->HaveInstallRule = false;
this->DLLPlatform = false;
@@ -731,6 +732,8 @@ void cmTarget::SetMakefile(cmMakefile* mf)
// Record current policies for later use.
this->PolicyStatusCMP0003 =
this->Makefile->GetPolicyStatus(cmPolicies::CMP0003);
+ this->PolicyStatusCMP0004 =
+ this->Makefile->GetPolicyStatus(cmPolicies::CMP0004);
}
//----------------------------------------------------------------------------
diff --git a/Source/cmTarget.h b/Source/cmTarget.h
index 82d9b67..f90a059 100644
--- a/Source/cmTarget.h
+++ b/Source/cmTarget.h
@@ -110,6 +110,10 @@ public:
cmPolicies::PolicyStatus GetPolicyStatusCMP0003() const
{ return this->PolicyStatusCMP0003; }
+ /** Get the status of policy CMP0004 when the target was created. */
+ cmPolicies::PolicyStatus GetPolicyStatusCMP0004() const
+ { return this->PolicyStatusCMP0004; }
+
/**
* Get the list of the custom commands for this target
*/
@@ -537,6 +541,7 @@ private:
// Policy status recorded when target was created.
cmPolicies::PolicyStatus PolicyStatusCMP0003;
+ cmPolicies::PolicyStatus PolicyStatusCMP0004;
// Internal representation details.
friend class cmTargetInternals;