From ed19ebd789e92014a87917980700c0663c37fe30 Mon Sep 17 00:00:00 2001 From: Mark Callow Date: Sat, 25 Nov 2023 19:01:41 +0900 Subject: [PATCH 1/2] Set tools and tests rpath on Linux. --- tests/CMakeLists.txt | 4 ++++ tools/CMakeLists.txt | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 49910cec6f..400154ea70 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -6,6 +6,10 @@ function(set_test_properties test_target) 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() diff --git a/tools/CMakeLists.txt b/tools/CMakeLists.txt index ae3ef4f950..f1a1c52221 100644 --- a/tools/CMakeLists.txt +++ b/tools/CMakeLists.txt @@ -18,6 +18,10 @@ function(set_tool_properties tool_target) INSTALL_RPATH "@executable_path;/usr/local/lib" CXX_VISIBILITY_PRESET ${STATIC_APP_LIB_SYMBOL_VISIBILITY} ) + elseif(LINUX) + set_target_properties(${tool_target} PROPERTIES + INSTALL_RPATH "$ORIGIN;$ORIGIN/../lib" + ) endif() endfunction() From 71765d2c28b57c374cb560d9706e3e756ec151d3 Mon Sep 17 00:00:00 2001 From: Mark Callow Date: Sun, 26 Nov 2023 18:04:15 +0900 Subject: [PATCH 2/2] Add explanatory comments. --- tests/CMakeLists.txt | 1 + tools/CMakeLists.txt | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 400154ea70..e02a2b7aa0 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -2,6 +2,7 @@ # 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" diff --git a/tools/CMakeLists.txt b/tools/CMakeLists.txt index f1a1c52221..ffc1e365dd 100644 --- a/tools/CMakeLists.txt +++ b/tools/CMakeLists.txt @@ -15,11 +15,33 @@ 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 | 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 | head -20 + # - objdump -x | grep 'R.*PATH' INSTALL_RPATH "$ORIGIN;$ORIGIN/../lib" ) endif()