Teach link_directories to recognize relative paths
We create CMake Policy CMP0015 to make link_directories() treat relative paths with respect to the source tree while retaining compatibility. This makes it consistent with include_directories() and other commands. Changes based on patch from Alex. See issue #9697.
This commit is contained in:
parent
e1548142fb
commit
02db43239b
|
@ -23,10 +23,48 @@ bool cmLinkDirectoriesCommand
|
||||||
for(std::vector<std::string>::const_iterator i = args.begin();
|
for(std::vector<std::string>::const_iterator i = args.begin();
|
||||||
i != args.end(); ++i)
|
i != args.end(); ++i)
|
||||||
{
|
{
|
||||||
std::string unixPath = *i;
|
this->AddLinkDir(*i);
|
||||||
cmSystemTools::ConvertToUnixSlashes(unixPath);
|
|
||||||
this->Makefile->AddLinkDirectory(unixPath.c_str());
|
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//----------------------------------------------------------------------------
|
||||||
|
void cmLinkDirectoriesCommand::AddLinkDir(std::string const& dir)
|
||||||
|
{
|
||||||
|
std::string unixPath = dir;
|
||||||
|
cmSystemTools::ConvertToUnixSlashes(unixPath);
|
||||||
|
if(!cmSystemTools::FileIsFullPath(unixPath.c_str()))
|
||||||
|
{
|
||||||
|
bool convertToAbsolute = false;
|
||||||
|
cmOStringStream e;
|
||||||
|
e << "This command specifies the relative path\n"
|
||||||
|
<< " " << unixPath << "\n"
|
||||||
|
<< "as a link directory.\n";
|
||||||
|
cmPolicies* policies = this->Makefile->GetPolicies();
|
||||||
|
switch (this->Makefile->GetPolicyStatus(cmPolicies::CMP0015))
|
||||||
|
{
|
||||||
|
case cmPolicies::WARN:
|
||||||
|
e << policies->GetPolicyWarning(cmPolicies::CMP0015);
|
||||||
|
this->Makefile->IssueMessage(cmake::AUTHOR_WARNING, e.str());
|
||||||
|
case cmPolicies::OLD:
|
||||||
|
// OLD behavior does not convert
|
||||||
|
break;
|
||||||
|
case cmPolicies::REQUIRED_IF_USED:
|
||||||
|
case cmPolicies::REQUIRED_ALWAYS:
|
||||||
|
e << policies->GetRequiredPolicyError(cmPolicies::CMP0015);
|
||||||
|
this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str());
|
||||||
|
case cmPolicies::NEW:
|
||||||
|
// NEW behavior converts
|
||||||
|
convertToAbsolute = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (convertToAbsolute)
|
||||||
|
{
|
||||||
|
std::string tmp = this->Makefile->GetStartDirectory();
|
||||||
|
tmp += "/";
|
||||||
|
tmp += unixPath;
|
||||||
|
unixPath = tmp;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
this->Makefile->AddLinkDirectory(unixPath.c_str());
|
||||||
|
}
|
||||||
|
|
|
@ -70,6 +70,8 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
cmTypeMacro(cmLinkDirectoriesCommand, cmCommand);
|
cmTypeMacro(cmLinkDirectoriesCommand, cmCommand);
|
||||||
|
private:
|
||||||
|
void AddLinkDir(std::string const& dir);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -406,6 +406,21 @@ cmPolicies::cmPolicies()
|
||||||
"The OLD behavior for this policy is to silently ignore the problem. "
|
"The OLD behavior for this policy is to silently ignore the problem. "
|
||||||
"The NEW behavior for this policy is to report an error.",
|
"The NEW behavior for this policy is to report an error.",
|
||||||
2,8,0, cmPolicies::WARN);
|
2,8,0, cmPolicies::WARN);
|
||||||
|
|
||||||
|
this->DefinePolicy(
|
||||||
|
CMP0015, "CMP0015",
|
||||||
|
"link_directories() treats paths relative to the source dir.",
|
||||||
|
"In CMake 2.6.4 and lower the link_directories() command passed relative "
|
||||||
|
"paths unchanged to the linker. "
|
||||||
|
"In CMake 2.8.1 and above the link_directories() command prefers to "
|
||||||
|
"interpret relative paths with respect to CMAKE_CURRENT_SOURCE_DIR, "
|
||||||
|
"which is consistent with include_directories() and other commands. "
|
||||||
|
"The OLD behavior for this policy is to use relative paths verbatim in "
|
||||||
|
"the linker command. "
|
||||||
|
"The NEW behavior for this policy is to convert relative paths to "
|
||||||
|
"absolute paths by appending the relative path to "
|
||||||
|
"CMAKE_CURRENT_SOURCE_DIR.",
|
||||||
|
2,8,1, cmPolicies::WARN);
|
||||||
}
|
}
|
||||||
|
|
||||||
cmPolicies::~cmPolicies()
|
cmPolicies::~cmPolicies()
|
||||||
|
|
|
@ -50,6 +50,7 @@ public:
|
||||||
CMP0012, // Recognize numbers and boolean constants in if()
|
CMP0012, // Recognize numbers and boolean constants in if()
|
||||||
CMP0013, // Duplicate binary directories not allowed
|
CMP0013, // Duplicate binary directories not allowed
|
||||||
CMP0014, // Input directories must have CMakeLists.txt
|
CMP0014, // Input directories must have CMakeLists.txt
|
||||||
|
CMP0015, // link_directories() treats paths relative to source dir
|
||||||
|
|
||||||
// Always the last entry. Useful mostly to avoid adding a comma
|
// Always the last entry. Useful mostly to avoid adding a comma
|
||||||
// the last policy when adding a new one.
|
// the last policy when adding a new one.
|
||||||
|
|
Loading…
Reference in New Issue