Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set tools and tests rpath on Linux. #804

Merged
merged 2 commits into from
Nov 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,15 @@
# SPDX-License-Identifier: Apache-2.0

function(set_test_properties test_target)
# See comments in set_tools_properties() in ../tools/CMakeLists.txt.
if(APPLE)
set_target_properties(${test_target} PROPERTIES
INSTALL_RPATH "@executable_path;/usr/local/lib"
)
elseif(LINUX)
set_target_properties(${test_target} PROPERTIES
INSTALL_RPATH "$ORIGIN;$ORIGIN/../lib"
)
endif()
endfunction()

Expand Down
26 changes: 26 additions & 0 deletions tools/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,35 @@ function(set_tool_properties tool_target)
if(APPLE)
set_target_properties(${tool_target} PROPERTIES
XCODE_ATTRIBUTE_ENABLE_HARDENED_RUNTIME "YES"
# Creates an LC_RPATH entry in the Mac-O binary for each
# item in this list. When searching for libraries whose
# install name starts with @rpath, as libktx's does, dyld
# searches each LC_RPATH in the order given here.
#
# Check the LC_RPATH entries with
# - otool -l <file> | grep -A 3 LC_RPATH
#
# TODO: Consider adding @executable_path/../lib.
INSTALL_RPATH "@executable_path;/usr/local/lib"
CXX_VISIBILITY_PRESET ${STATIC_APP_LIB_SYMBOL_VISIBILITY}
)
elseif(LINUX)
set_target_properties(${tool_target} PROPERTIES
# With modern tools sets DT_RUNPATH not the deprecated
# DT_RPATH in ELF binaries. ld.so searches for libraries
# as follows:
# - LD_LIBRARY_PATH
# - RUNPATH
# - Directories given in /etc/ld.so.conf.
# /usr/local/lib is listed there.
# - Default path: /lib;/usr/lib.
# $ORIGIN is equivalent to @executable_path.
#
# Check DT_RUNPATH with one of
# - readelf -d <file> | head -20
# - objdump -x <file> | grep 'R.*PATH'
INSTALL_RPATH "$ORIGIN;$ORIGIN/../lib"
)
endif()
endfunction()

Expand Down