From f08dcbffecd45889d8aeabdfa504ee76ef54e351 Mon Sep 17 00:00:00 2001 From: Jiang Yue Date: Fri, 12 Jul 2019 11:33:36 +0800 Subject: Property: Add INSTALL_REMOVE_ENVIROMENT_RPATH property --- Source/cmFileCommand.cxx | 7 ++++++- Source/cmInstallTargetGenerator.cxx | 10 ++++++++-- Source/cmSystemTools.cxx | 8 ++++++-- Source/cmSystemTools.h | 1 + Source/cmTarget.cxx | 1 + Tests/CMakeTests/ELFTest.cmake.in | 29 +++++++++++++++++++++++++++-- 6 files changed, 49 insertions(+), 7 deletions(-) diff --git a/Source/cmFileCommand.cxx b/Source/cmFileCommand.cxx index 9871f49..807b5b3 100644 --- a/Source/cmFileCommand.cxx +++ b/Source/cmFileCommand.cxx @@ -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" diff --git a/Source/cmInstallTargetGenerator.cxx b/Source/cmInstallTargetGenerator.cxx index d891ad8..a61239e 100644 --- a/Source/cmInstallTargetGenerator.cxx +++ b/Source/cmInstallTargetGenerator.cxx @@ -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"; + } } } diff --git a/Source/cmSystemTools.cxx b/Source/cmSystemTools.cxx index 723f280..a7e0398 100644 --- a/Source/cmSystemTools.cxx +++ b/Source/cmSystemTools.cxx @@ -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; diff --git a/Source/cmSystemTools.h b/Source/cmSystemTools.h index a9c03bd..087eca7 100644 --- a/Source/cmSystemTools.h +++ b/Source/cmSystemTools.h @@ -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); diff --git a/Source/cmTarget.cxx b/Source/cmTarget.cxx index b1a0127..beccfce 100644 --- a/Source/cmTarget.cxx +++ b/Source/cmTarget.cxx @@ -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"); diff --git a/Tests/CMakeTests/ELFTest.cmake.in b/Tests/CMakeTests/ELFTest.cmake.in index 4635778..85c2360 100644 --- a/Tests/CMakeTests/ELFTest.cmake.in +++ b/Tests/CMakeTests/ELFTest.cmake.in @@ -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) -- cgit v0.12 From bd2793b6e90c9c990a3cd4db260503e19e9a8ae0 Mon Sep 17 00:00:00 2001 From: Jiang Yue Date: Wed, 24 Jul 2019 10:38:07 +0800 Subject: Help: Add documentation for INSTALL_REMOVE_ENVIROMENT_RPATH --- Help/manual/cmake-properties.7.rst | 1 + Help/manual/cmake-variables.7.rst | 1 + Help/prop_tgt/INSTALL_REMOVE_ENVIRONMENT_RPATH.rst | 10 ++++++++++ Help/release/dev/add-install-remove-environment-rpath.rst | 6 ++++++ Help/variable/CMAKE_INSTALL_REMOVE_ENVIRONMENT_RPATH.rst | 9 +++++++++ 5 files changed, 27 insertions(+) create mode 100644 Help/prop_tgt/INSTALL_REMOVE_ENVIRONMENT_RPATH.rst create mode 100644 Help/release/dev/add-install-remove-environment-rpath.rst create mode 100644 Help/variable/CMAKE_INSTALL_REMOVE_ENVIRONMENT_RPATH.rst diff --git a/Help/manual/cmake-properties.7.rst b/Help/manual/cmake-properties.7.rst index ae4be3e..62d23c7 100644 --- a/Help/manual/cmake-properties.7.rst +++ b/Help/manual/cmake-properties.7.rst @@ -228,6 +228,7 @@ Properties on Targets /prop_tgt/IMPORT_SUFFIX /prop_tgt/INCLUDE_DIRECTORIES /prop_tgt/INSTALL_NAME_DIR + /prop_tgt/INSTALL_REMOVE_ENVIRONMENT_RPATH /prop_tgt/INSTALL_RPATH /prop_tgt/INSTALL_RPATH_USE_LINK_PATH /prop_tgt/INTERFACE_AUTOUIC_OPTIONS diff --git a/Help/manual/cmake-variables.7.rst b/Help/manual/cmake-variables.7.rst index c3f6f8a..432d7fc 100644 --- a/Help/manual/cmake-variables.7.rst +++ b/Help/manual/cmake-variables.7.rst @@ -372,6 +372,7 @@ Variables that Control the Build /variable/CMAKE_INCLUDE_CURRENT_DIR /variable/CMAKE_INCLUDE_CURRENT_DIR_IN_INTERFACE /variable/CMAKE_INSTALL_NAME_DIR + /variable/CMAKE_INSTALL_REMOVE_ENVIRONMENT_RPATH /variable/CMAKE_INSTALL_RPATH /variable/CMAKE_INSTALL_RPATH_USE_LINK_PATH /variable/CMAKE_INTERPROCEDURAL_OPTIMIZATION diff --git a/Help/prop_tgt/INSTALL_REMOVE_ENVIRONMENT_RPATH.rst b/Help/prop_tgt/INSTALL_REMOVE_ENVIRONMENT_RPATH.rst new file mode 100644 index 0000000..a474fc6 --- /dev/null +++ b/Help/prop_tgt/INSTALL_REMOVE_ENVIRONMENT_RPATH.rst @@ -0,0 +1,10 @@ +INSTALL_REMOVE_ENVIRONMENT_RPATH +-------------------------------- + +Removes compiler defined rpaths durimg installation. + +``INSTALL_REMOVE_ENVIRONMENT_RPATH`` is a boolean that if set to ``True`` will +remove compiler defined rpaths from the project if the user also defines rpath +with :prop_tgt:`INSTALL_RPATH`. This property is initialized by whether the +value of :variable:`CMAKE_INSTALL_REMOVE_ENVIRONMENT_RPATH` is set when a +target is created. diff --git a/Help/release/dev/add-install-remove-environment-rpath.rst b/Help/release/dev/add-install-remove-environment-rpath.rst new file mode 100644 index 0000000..156106c --- /dev/null +++ b/Help/release/dev/add-install-remove-environment-rpath.rst @@ -0,0 +1,6 @@ +add-install-remove-environment-rpath +------------------------------------ + +* A new target property, :prop_tgt:`INSTALL_REMOVE_ENVIRONMENT_RPATH`, was + added which removes compiler-defined rpaths from a target. This property is + initialized by :variable:`CMAKE_INSTALL_REMOVE_ENVIRONMENT_RPATH`. diff --git a/Help/variable/CMAKE_INSTALL_REMOVE_ENVIRONMENT_RPATH.rst b/Help/variable/CMAKE_INSTALL_REMOVE_ENVIRONMENT_RPATH.rst new file mode 100644 index 0000000..19ae5f3 --- /dev/null +++ b/Help/variable/CMAKE_INSTALL_REMOVE_ENVIRONMENT_RPATH.rst @@ -0,0 +1,9 @@ +CMAKE_INSTALL_REMOVE_ENVIRONMENT_RPATH +-------------------------------------- + +Removes compiler defined rpaths durimg installation. + +``CMAKE_INSTALL_REMOVE_ENVIRONMENT_RPATH`` is a boolean that if set to ``true`` +removes compiler defined rpaths from the project if the user also defines rpath +with :prop_tgt:`INSTALL_RPATH`. This is used to initialize the target property +:prop_tgt:`INSTALL_REMOVE_ENVIRONMENT_RPATH` for all targets. -- cgit v0.12