From e7f78309e761af3c4c929388bba0cb967f670b35 Mon Sep 17 00:00:00 2001 From: Nemanja Ivanovic Date: Tue, 15 Nov 2022 20:25:55 -0600 Subject: find_library: Construct paths by removing 'unknown' from library arch The compiler used for a build sometimes disagrees with the remainder of the toolchain wrt. to the architecture triple. Specifically, Clang will typically put its libraries in `-unknown--` but it uses the GCC toolchain on many targets (which often has its libraries in `--`). In such cases CMake will acquire the triple from Clang and use it in library search paths for libraries that are provided by the GCC toolchain. This of course fails due to the mismatch. This patch augments the list of search paths with ones that include the architecture triple with any occurrences of 'unknown' removed. Fixes: #24175 --- Source/cmSearchPath.cxx | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/Source/cmSearchPath.cxx b/Source/cmSearchPath.cxx index 6c53b85..44f37cb 100644 --- a/Source/cmSearchPath.cxx +++ b/Source/cmSearchPath.cxx @@ -179,12 +179,27 @@ void cmSearchPath::AddPrefixPaths(const std::vector& paths, cmValue arch = this->FC->Makefile->GetDefinition("CMAKE_LIBRARY_ARCHITECTURE"); if (cmNonempty(arch)) { + std::string archNoUnknown = arch; + auto unknownAtPos = archNoUnknown.find("-unknown-"); + bool foundUnknown = unknownAtPos != std::string::npos; + if (foundUnknown) { + // Replace "-unknown-" with "-". + archNoUnknown.replace(unknownAtPos, 9, "-"); + } if (this->FC->Makefile->IsDefinitionSet("CMAKE_SYSROOT") && this->FC->Makefile->IsDefinitionSet( "CMAKE_PREFIX_LIBRARY_ARCHITECTURE")) { + if (foundUnknown) { + this->AddPathInternal(cmStrCat('/', archNoUnknown, dir, subdir), + cmStrCat('/', archNoUnknown, prefix), base); + } this->AddPathInternal(cmStrCat('/', *arch, dir, subdir), cmStrCat('/', *arch, prefix), base); } else { + if (foundUnknown) { + this->AddPathInternal(cmStrCat(dir, subdir, '/', archNoUnknown), + prefix, base); + } this->AddPathInternal(cmStrCat(dir, subdir, '/', *arch), prefix, base); } -- cgit v0.12