Commit f08dcbff authored by Jiang Yue's avatar Jiang Yue Committed by Kyle Edwards

Property: Add INSTALL_REMOVE_ENVIROMENT_RPATH property

parent 579e27ec
......@@ -1071,6 +1071,7 @@ bool cmFileCommand::HandleRPathChangeCommand(
std::string file;
const char* oldRPath = nullptr;
const char* newRPath = nullptr;
bool removeEnvironmentRPath = false;
enum Doing
{
DoingNone,
......@@ -1086,6 +1087,8 @@ bool cmFileCommand::HandleRPathChangeCommand(
doing = DoingNew;
} else if (args[i] == "FILE") {
doing = DoingFile;
} else if (args[i] == "INSTALL_REMOVE_ENVIRONMENT_RPATH") {
removeEnvironmentRPath = true;
} else if (doing == DoingFile) {
file = args[i];
doing = DoingNone;
......@@ -1124,7 +1127,9 @@ bool cmFileCommand::HandleRPathChangeCommand(
cmFileTimes const ft(file);
std::string emsg;
bool changed;
if (!cmSystemTools::ChangeRPath(file, oldRPath, newRPath, &emsg, &changed)) {
if (!cmSystemTools::ChangeRPath(file, oldRPath, newRPath,
removeEnvironmentRPath, &emsg, &changed)) {
std::ostringstream e;
/* clang-format off */
e << "RPATH_CHANGE could not write new RPATH:\n"
......
......@@ -767,12 +767,18 @@ void cmInstallTargetGenerator::AddChrpathPatchRule(
this->IssueCMP0095Warning(newRpath);
CM_FALLTHROUGH;
case cmPolicies::OLD:
os << indent << " NEW_RPATH \"" << newRpath << "\")\n";
os << indent << " NEW_RPATH \"" << newRpath << "\"";
break;
default:
os << indent << " NEW_RPATH " << escapedNewRpath << ")\n";
os << indent << " NEW_RPATH " << escapedNewRpath;
break;
}
if (this->Target->GetPropertyAsBool("INSTALL_REMOVE_ENVIRONMENT_RPATH")) {
os << "\n" << indent << " INSTALL_REMOVE_ENVIRONMENT_RPATH)\n";
} else {
os << indent << ")\n";
}
}
}
......
......@@ -2397,7 +2397,8 @@ struct cmSystemToolsRPathInfo
#if defined(CMAKE_USE_ELF_PARSER)
bool cmSystemTools::ChangeRPath(std::string const& file,
std::string const& oldRPath,
std::string const& newRPath, std::string* emsg,
std::string const& newRPath,
bool removeEnvironmentRPath, std::string* emsg,
bool* changed)
{
if (changed) {
......@@ -2484,7 +2485,9 @@ bool cmSystemTools::ChangeRPath(std::string const& file,
// Construct the new value which preserves the part of the path
// not being changed.
rp[rp_count].Value = se[i]->Value.substr(0, prefix_len);
if (!removeEnvironmentRPath) {
rp[rp_count].Value = se[i]->Value.substr(0, prefix_len);
}
rp[rp_count].Value += newRPath;
rp[rp_count].Value += se[i]->Value.substr(pos + oldRPath.length());
......@@ -2570,6 +2573,7 @@ bool cmSystemTools::ChangeRPath(std::string const& file,
bool cmSystemTools::ChangeRPath(std::string const& /*file*/,
std::string const& /*oldRPath*/,
std::string const& /*newRPath*/,
bool /*removeEnvironmentRPath*/,
std::string* /*emsg*/, bool* /*changed*/)
{
return false;
......
......@@ -473,6 +473,7 @@ public:
/** Try to set the RPATH in an ELF binary. */
static bool ChangeRPath(std::string const& file, std::string const& oldRPath,
std::string const& newRPath,
bool removeEnvironmentRPath,
std::string* emsg = nullptr,
bool* changed = nullptr);
......
......@@ -282,6 +282,7 @@ cmTarget::cmTarget(std::string const& name, cmStateEnums::TargetType type,
initProp("BUILD_RPATH");
initProp("BUILD_RPATH_USE_ORIGIN");
initProp("INSTALL_NAME_DIR");
initProp("INSTALL_REMOVE_ENVIRONMENT_RPATH");
initPropValue("INSTALL_RPATH", "");
initPropValue("INSTALL_RPATH_USE_LINK_PATH", "OFF");
initProp("INTERPROCEDURAL_OPTIMIZATION");
......
......@@ -25,13 +25,38 @@ foreach(f ${files})
# Change the RPATH.
file(RPATH_CHANGE FILE "${f}"
OLD_RPATH "/sample/rpath"
NEW_RPATH "/rpath/sample")
NEW_RPATH "/path1:/path2")
set(rpath)
file(STRINGS "${f}" rpath REGEX "/rpath/sample" LIMIT_COUNT 1)
file(STRINGS "${f}" rpath REGEX "/path1:/path2" LIMIT_COUNT 1)
if(NOT rpath)
message(FATAL_ERROR "RPATH not changed in ${f}")
endif()
# Change the RPATH without compiler defined rpath removed
file(RPATH_CHANGE FILE "${f}"
OLD_RPATH "/path2"
NEW_RPATH "/path3")
set(rpath)
file(STRINGS "${f}" rpath REGEX "/path1:/path3" LIMIT_COUNT 1)
if(NOT rpath)
message(FATAL_ERROR "RPATH not updated in ${f}")
endif()
# Change the RPATH with compiler defined rpath removed
file(RPATH_CHANGE FILE "${f}"
OLD_RPATH "/path3"
NEW_RPATH "/rpath/sample"
INSTALL_REMOVE_ENVIRONMENT_RPATH)
set(rpath)
file(STRINGS "${f}" rpath REGEX "/rpath/sample" LIMIT_COUNT 1)
if(NOT rpath)
message(FATAL_ERROR "RPATH not updated in ${f}")
endif()
file(STRINGS "${f}" rpath REGEX "/path1" LIMIT_COUNT 1)
if(rpath)
message(FATAL_ERROR "RPATH not removed in ${f}")
endif()
# Remove the RPATH.
file(RPATH_REMOVE FILE "${f}")
set(rpath)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment