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.
This commit is contained in:
parent
82a8c6b0c7
commit
26df00f83a
|
@ -553,7 +553,7 @@ cmComputeLinkDepends::AddLinkEntries(int depender_index,
|
|||
{
|
||||
// Skip entries that will resolve to the target getting linked or
|
||||
// are empty.
|
||||
std::string item = this->CleanItemName(*li);
|
||||
std::string item = this->Target->CheckCMP0004(*li);
|
||||
if(item == this->Target->GetName() || item.empty())
|
||||
{
|
||||
continue;
|
||||
|
@ -605,66 +605,6 @@ cmComputeLinkDepends::AddLinkEntries(int depender_index,
|
|||
}
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
std::string cmComputeLinkDepends::CleanItemName(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)
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
cmTarget* cmComputeLinkDepends::FindTargetToLink(int depender_index,
|
||||
const char* name)
|
||||
|
|
|
@ -87,7 +87,6 @@ private:
|
|||
LinkLibraryVectorType const& libs);
|
||||
void AddLinkEntries(int depender_index,
|
||||
std::vector<std::string> const& libs);
|
||||
std::string CleanItemName(std::string const& item);
|
||||
cmTarget* FindTargetToLink(int depender_index, const char* name);
|
||||
|
||||
// One entry for each unique item.
|
||||
|
|
|
@ -3814,6 +3814,65 @@ cmTarget::ComputeLinkInterface(const char* config)
|
|||
return iface;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
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)
|
||||
|
|
|
@ -260,6 +260,10 @@ public:
|
|||
such dependencies or for static libraries. */
|
||||
cmTargetLinkInterface const* GetLinkInterface(const char* config);
|
||||
|
||||
/** Strip off leading and trailing whitespace from an item named in
|
||||
the link dependencies of this target. */
|
||||
std::string CheckCMP0004(std::string const& item);
|
||||
|
||||
/** Get the directory in which this target will be built. If the
|
||||
configuration name is given then the generator will add its
|
||||
subdirectory for that configuration. Otherwise just the canonical
|
||||
|
|
Loading…
Reference in New Issue