Skip to content

Commit 928612a

Browse files
authored
Set tools and tests rpath on Linux. (#804)
Fixes #796.
1 parent 82a643a commit 928612a

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

tests/CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,15 @@
22
# SPDX-License-Identifier: Apache-2.0
33

44
function(set_test_properties test_target)
5+
# See comments in set_tools_properties() in ../tools/CMakeLists.txt.
56
if(APPLE)
67
set_target_properties(${test_target} PROPERTIES
78
INSTALL_RPATH "@executable_path;/usr/local/lib"
89
)
10+
elseif(LINUX)
11+
set_target_properties(${test_target} PROPERTIES
12+
INSTALL_RPATH "$ORIGIN;$ORIGIN/../lib"
13+
)
914
endif()
1015
endfunction()
1116

tools/CMakeLists.txt

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,35 @@ function(set_tool_properties tool_target)
1515
if(APPLE)
1616
set_target_properties(${tool_target} PROPERTIES
1717
XCODE_ATTRIBUTE_ENABLE_HARDENED_RUNTIME "YES"
18+
# Creates an LC_RPATH entry in the Mac-O binary for each
19+
# item in this list. When searching for libraries whose
20+
# install name starts with @rpath, as libktx's does, dyld
21+
# searches each LC_RPATH in the order given here.
22+
#
23+
# Check the LC_RPATH entries with
24+
# - otool -l <file> | grep -A 3 LC_RPATH
25+
#
26+
# TODO: Consider adding @executable_path/../lib.
1827
INSTALL_RPATH "@executable_path;/usr/local/lib"
1928
CXX_VISIBILITY_PRESET ${STATIC_APP_LIB_SYMBOL_VISIBILITY}
2029
)
30+
elseif(LINUX)
31+
set_target_properties(${tool_target} PROPERTIES
32+
# With modern tools sets DT_RUNPATH not the deprecated
33+
# DT_RPATH in ELF binaries. ld.so searches for libraries
34+
# as follows:
35+
# - LD_LIBRARY_PATH
36+
# - RUNPATH
37+
# - Directories given in /etc/ld.so.conf.
38+
# /usr/local/lib is listed there.
39+
# - Default path: /lib;/usr/lib.
40+
# $ORIGIN is equivalent to @executable_path.
41+
#
42+
# Check DT_RUNPATH with one of
43+
# - readelf -d <file> | head -20
44+
# - objdump -x <file> | grep 'R.*PATH'
45+
INSTALL_RPATH "$ORIGIN;$ORIGIN/../lib"
46+
)
2147
endif()
2248
endfunction()
2349

0 commit comments

Comments
 (0)