summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAditya Vidyadhar Kamath <Aditya.Kamath1@ibm.com>2024-09-30 15:02:46 (GMT)
committerBrad King <brad.king@kitware.com>2024-10-02 12:48:32 (GMT)
commit3e5b9229e0083081fa96422ab279f62012ca24a5 (patch)
tree8e75c2f3487bc6539c48f4ea1db30b1eb996599e
parent80d16018fa909ff5713f292fc8baba7510c2a3ee (diff)
downloadCMake-3e5b9229e0083081fa96422ab279f62012ca24a5.zip
CMake-3e5b9229e0083081fa96422ab279f62012ca24a5.tar.gz
CMake-3e5b9229e0083081fa96422ab279f62012ca24a5.tar.bz2
AIX: Fix XCOFF editor to avoid duplicating standard libpath entries
The `/usr/lib` and `/lib` entries need to be present, but do not need to be at the end. Avoid appending extra copies of the entries if they already exist. Closes: #26275
-rw-r--r--Source/cmXCOFF.cxx28
1 files changed, 16 insertions, 12 deletions
diff --git a/Source/cmXCOFF.cxx b/Source/cmXCOFF.cxx
index 6fd6fbf..e459103 100644
--- a/Source/cmXCOFF.cxx
+++ b/Source/cmXCOFF.cxx
@@ -6,6 +6,7 @@
#include <cstddef>
#include <cm/memory>
+#include <cm/string_view>
#include "cmsys/FStream.hxx"
@@ -283,19 +284,22 @@ cm::optional<cm::string_view> Impl<XCOFF>::GetLibPath()
template <typename XCOFF>
bool Impl<XCOFF>::SetLibPath(cm::string_view libPath)
{
- // The new LIBPATH must end in the standard AIX LIBPATH.
-#define CM_AIX_LIBPATH "/usr/lib:/lib"
+ // The new LIBPATH must contain standard AIX LIBPATH entries.
std::string libPathBuf;
- if (libPath != CM_AIX_LIBPATH &&
- !cmHasLiteralSuffix(libPath, ":" CM_AIX_LIBPATH)) {
- libPathBuf = std::string(libPath);
- if (!libPathBuf.empty() && libPathBuf.back() != ':') {
- libPathBuf.push_back(':');
- }
- libPathBuf += CM_AIX_LIBPATH;
- libPath = libPathBuf;
- }
-#undef CM_AIX_LIBPATH
+#define ENSURE_ENTRY(x) \
+ if (libPath != x && !cmHasLiteralPrefix(libPath, x ":") && \
+ !cmHasLiteralSuffix(libPath, ":" x) && \
+ libPath.find(":" x ":") == std::string::npos) { \
+ libPathBuf = std::string(libPath); \
+ if (!libPathBuf.empty() && libPathBuf.back() != ':') { \
+ libPathBuf.push_back(':'); \
+ } \
+ libPathBuf += x; \
+ libPath = libPathBuf; \
+ }
+ ENSURE_ENTRY("/usr/lib")
+ ENSURE_ENTRY("/lib")
+#undef ENSURE_ENTRY
auto oldEnd = std::find(this->LoaderImportFileTable.begin(),
this->LoaderImportFileTable.end(), '\0');