diff options
author | Brad King <brad.king@kitware.com> | 2009-07-06 20:24:45 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2009-07-06 20:24:45 (GMT) |
commit | 26df00f83a73821e39e20624d3ca7f66fdd4db97 (patch) | |
tree | b5d2787918079731daa55e3793aa12ed057d3765 /Source/cmTarget.cxx | |
parent | 82a8c6b0c725496315e45e11ce8bcfb970c82bcf (diff) | |
download | CMake-26df00f83a73821e39e20624d3ca7f66fdd4db97.zip CMake-26df00f83a73821e39e20624d3ca7f66fdd4db97.tar.gz CMake-26df00f83a73821e39e20624d3ca7f66fdd4db97.tar.bz2 |
ENH: Move CMP0004 check into cmTarget
This moves code implementing policy CMP0004 into cmTarget::CheckCMP0004.
The implementation is slightly simpler and can be re-used outside of
cmComputeLinkDepends.
Diffstat (limited to 'Source/cmTarget.cxx')
-rw-r--r-- | Source/cmTarget.cxx | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/Source/cmTarget.cxx b/Source/cmTarget.cxx index 3d6e1b7..6cddbe3 100644 --- a/Source/cmTarget.cxx +++ b/Source/cmTarget.cxx @@ -3815,6 +3815,65 @@ cmTarget::ComputeLinkInterface(const char* config) } //---------------------------------------------------------------------------- +std::string cmTarget::CheckCMP0004(std::string const& item) +{ + // Strip whitespace off the library names because we used to do this + // in case variables were expanded at generate time. We no longer + // do the expansion but users link to libraries like " ${VAR} ". + std::string lib = item; + std::string::size_type pos = lib.find_first_not_of(" \t\r\n"); + if(pos != lib.npos) + { + lib = lib.substr(pos, lib.npos); + } + pos = lib.find_last_not_of(" \t\r\n"); + if(pos != lib.npos) + { + lib = lib.substr(0, pos+1); + } + if(lib != item) + { + cmake* cm = this->Makefile->GetCMakeInstance(); + switch(this->PolicyStatusCMP0004) + { + case cmPolicies::WARN: + { + cmOStringStream w; + w << (this->Makefile->GetPolicies() + ->GetPolicyWarning(cmPolicies::CMP0004)) << "\n" + << "Target \"" << this->GetName() << "\" links to item \"" + << item << "\" which has leading or trailing whitespace."; + cm->IssueMessage(cmake::AUTHOR_WARNING, w.str(), + this->GetBacktrace()); + } + case cmPolicies::OLD: + break; + case cmPolicies::NEW: + { + cmOStringStream e; + e << "Target \"" << this->GetName() << "\" links to item \"" + << item << "\" which has leading or trailing whitespace. " + << "This is now an error according to policy CMP0004."; + cm->IssueMessage(cmake::FATAL_ERROR, e.str(), this->GetBacktrace()); + } + break; + case cmPolicies::REQUIRED_IF_USED: + case cmPolicies::REQUIRED_ALWAYS: + { + cmOStringStream e; + e << (this->Makefile->GetPolicies() + ->GetRequiredPolicyError(cmPolicies::CMP0004)) << "\n" + << "Target \"" << this->GetName() << "\" links to item \"" + << item << "\" which has leading or trailing whitespace."; + cm->IssueMessage(cmake::FATAL_ERROR, e.str(), this->GetBacktrace()); + } + break; + } + } + return lib; +} + +//---------------------------------------------------------------------------- cmComputeLinkInformation* cmTarget::GetLinkInformation(const char* config) { |