From f73027b182710dd00524b2a4007838f9080c3ea1 Mon Sep 17 00:00:00 2001 From: Kyle Edwards Date: Tue, 4 May 2021 16:31:05 -0400 Subject: cmSystemTools: Add SetRPath() method --- Source/cmSystemTools.cxx | 32 ++++++++++++++++++++++++++++++++ Source/cmSystemTools.h | 6 +++++- 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/Source/cmSystemTools.cxx b/Source/cmSystemTools.cxx index b45228e..10d2e50 100644 --- a/Source/cmSystemTools.cxx +++ b/Source/cmSystemTools.cxx @@ -2744,6 +2744,24 @@ bool cmSystemTools::ChangeRPath(std::string const& file, return AdjustRPath(file, MakeEmptyCallback(newRPath), adjustCallback, emsg, changed); } + +bool cmSystemTools::SetRPath(std::string const& file, + std::string const& newRPath, std::string* emsg, + bool* changed) +{ + auto adjustCallback = [newRPath](cm::optional& outRPath, + const std::string& inRPath, + const char* /*se_name*/, std::string * + /*emsg*/) -> bool { + if (inRPath != newRPath) { + outRPath = newRPath; + } + return true; + }; + + return AdjustRPath(file, MakeEmptyCallback(newRPath), adjustCallback, emsg, + changed); +} #elif defined(CMake_USE_XCOFF_PARSER) bool cmSystemTools::ChangeRPath(std::string const& file, std::string const& oldRPath, @@ -2813,6 +2831,13 @@ bool cmSystemTools::ChangeRPath(std::string const& file, } return true; } + +bool cmSystemTools::SetRPath(std::string const& /*file*/, + std::string const& /*newRPath*/, + std::string* /*emsg*/, bool* /*changed*/) +{ + return false; +} #else bool cmSystemTools::ChangeRPath(std::string const& /*file*/, std::string const& /*oldRPath*/, @@ -2822,6 +2847,13 @@ bool cmSystemTools::ChangeRPath(std::string const& /*file*/, { return false; } + +bool cmSystemTools::SetRPath(std::string const& /*file*/, + std::string const& /*newRPath*/, + std::string* /*emsg*/, bool* /*changed*/) +{ + return false; +} #endif bool cmSystemTools::VersionCompare(cmSystemTools::CompareOp op, diff --git a/Source/cmSystemTools.h b/Source/cmSystemTools.h index 5c3b5a9..44ccbf7 100644 --- a/Source/cmSystemTools.h +++ b/Source/cmSystemTools.h @@ -456,13 +456,17 @@ public: static bool GuessLibraryInstallName(std::string const& fullPath, std::string& soname); - /** Try to set the RPATH in an ELF binary. */ + /** Try to change 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); + /** Try to set the RPATH in an ELF binary. */ + static bool SetRPath(std::string const& file, std::string const& newRPath, + std::string* emsg = nullptr, bool* changed = nullptr); + /** Try to remove the RPATH from an ELF binary. */ static bool RemoveRPath(std::string const& file, std::string* emsg = nullptr, bool* removed = nullptr); -- cgit v0.12