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_<LANG>_IMPLICIT_LINK_LIBRARIES` so that our generators
do not suppress `RPATH` entries for dependencies in that directory.

Fixes: #26867
This commit is contained in:
Brad King
2025-04-15 13:43:03 -04:00
parent 430174e65d
commit 6e63080d39
2 changed files with 12 additions and 0 deletions

View File

@@ -256,6 +256,11 @@ function(CMAKE_DETERMINE_COMPILER_ABI lang src)
endif()
endif()
# Filter out implicit link directories excluded by our Platform/<os>* 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})

View File

@@ -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()