From 6e63080d39c04bbc1fdff12d7cb6a7a299cf08b2 Mon Sep 17 00:00:00 2001 From: Brad King Date: Tue, 15 Apr 2025 13:43:03 -0400 Subject: [PATCH] macOS: Restore RPATH entry for libraries linked from /usr/local/lib Since commit 7b19531291 (macOS: Do not pass any SDK/-isysroot to compilers by default, 2024-11-06, v4.0.0-rc1~511^2) our default invocation of compilers targeting macOS no longer passes `-isysroot`. Without that, Xcode's compilers search `-L/usr/local/lib` by default even though the macOS dynamic loader does not. Since `/usr/local/lib` is not a fully-implemented implicit link directory, exclude it from our detected `CMAKE__IMPLICIT_LINK_LIBRARIES` so that our generators do not suppress `RPATH` entries for dependencies in that directory. Fixes: #26867 --- Modules/CMakeDetermineCompilerABI.cmake | 5 +++++ Modules/Platform/Darwin-Initialize.cmake | 7 +++++++ 2 files changed, 12 insertions(+) diff --git a/Modules/CMakeDetermineCompilerABI.cmake b/Modules/CMakeDetermineCompilerABI.cmake index 53eaf58c0b..acd372eed6 100644 --- a/Modules/CMakeDetermineCompilerABI.cmake +++ b/Modules/CMakeDetermineCompilerABI.cmake @@ -256,6 +256,11 @@ function(CMAKE_DETERMINE_COMPILER_ABI lang src) endif() endif() + # Filter out implicit link directories excluded by our Platform/* modules. + if(DEFINED CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES_EXCLUDE) + list(REMOVE_ITEM implicit_dirs ${CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES_EXCLUDE}) + endif() + # Filter out implicit link directories excluded by the environment. if(DEFINED ENV{CMAKE_${lang}_IMPLICIT_LINK_DIRECTORIES_EXCLUDE}) list(REMOVE_ITEM implicit_dirs $ENV{CMAKE_${lang}_IMPLICIT_LINK_DIRECTORIES_EXCLUDE}) diff --git a/Modules/Platform/Darwin-Initialize.cmake b/Modules/Platform/Darwin-Initialize.cmake index 1a47d9abd8..245170c390 100644 --- a/Modules/Platform/Darwin-Initialize.cmake +++ b/Modules/Platform/Darwin-Initialize.cmake @@ -292,4 +292,11 @@ if(NOT CMAKE_OSX_SYSROOT) RESULT_VARIABLE _result ) unset(_sdk_macosx) + + list(APPEND CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES_EXCLUDE + # Without -isysroot, some compiler drivers implicitly pass -L/usr/local/lib + # to the linker. Since the macOS dynamic loader does not search it by + # default, it is not a fully-implemented implicit link directory. + /usr/local/lib + ) endif()