aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoão Valverde <joao.valverde@tecnico.ulisboa.pt>2018-12-03 05:32:17 +0000
committerPeter Wu <peter@lekensteyn.nl>2018-12-03 23:54:15 +0000
commit697623411c876a00060c1fa4cd86ace6ce41285c (patch)
tree7333fbdcee2892c4202dd5339575f82873388270
parentc3741a653b945be556bd606f5c8d3bc46f615d5f (diff)
CMake: Use $ORIGIN with RPATH
Make our package relocatable on Unix systems. Linux, Solaris and FreeBSD are known to support $ORIGIN. Change-Id: Ibcdda33d62c075bfa867d006cb6aaf5824609011 Reviewed-on: https://code.wireshark.org/review/30896 Petri-Dish: João Valverde <j@v6e.pt> Reviewed-by: João Valverde <j@v6e.pt> Tested-by: Petri Dish Buildbot Reviewed-by: Peter Wu <peter@lekensteyn.nl>
-rw-r--r--CMakeLists.txt30
-rw-r--r--extcap/CMakeLists.txt5
2 files changed, 31 insertions, 4 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 7190b4256e..352de03696 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -202,10 +202,30 @@ include(GNUInstallDirs)
# a non-default directory on Unix-like systems other than macOS.
# https://cmake.org/Wiki/CMake_RPATH_handling
if(NOT CMAKE_INSTALL_RPATH AND NOT (WIN32 OR APPLE))
- LIST(FIND CMAKE_C_IMPLICIT_LINK_DIRECTORIES "${CMAKE_INSTALL_FULL_LIBDIR}" IS_SYSTEM_DIR)
- if(IS_SYSTEM_DIR STREQUAL "-1")
- SET(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_FULL_LIBDIR}")
- SET(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
+ # Some systems may have limited or non-existent support for $ORIGIN.
+ # https://www.lekensteyn.nl/rpath.html
+ set(_enable_rpath_origin 0)
+ if(CMAKE_SYSTEM_NAME MATCHES "^(Linux|SunOS|FreeBSD)$")
+ set(_enable_rpath_origin 1)
+ endif()
+ set(ENABLE_RPATH_ORIGIN ${_enable_rpath_origin} CACHE BOOL "Use \$ORIGIN with RPATH")
+ mark_as_advanced(ENABLE_RPATH_ORIGIN)
+
+ if(ENABLE_RPATH_ORIGIN)
+ # Set an install RPATH relative to the location of the binary, to
+ # provide a fully relocatable package.
+ set(CMAKE_INSTALL_RPATH "\$ORIGIN/../${CMAKE_INSTALL_LIBDIR}")
+ # Add the automatically determined parts of the RPATH
+ # which point to directories outside the build tree to the install RPATH.
+ set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
+ else()
+ # Add an absolute RPATH if it is not already included in the
+ # default search list.
+ list(FIND CMAKE_C_IMPLICIT_LINK_DIRECTORIES "${CMAKE_INSTALL_FULL_LIBDIR}" IS_SYSTEM_DIR)
+ if(IS_SYSTEM_DIR STREQUAL "-1")
+ set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_FULL_LIBDIR}")
+ set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
+ endif()
endif()
endif()
@@ -1346,6 +1366,8 @@ include( UseCheckAPI )
# $DESTDIR/lib/wireshark/extcap
# Windows: $DESTDIR/extcap
# macOS app bundle: Wireshark.app/Contents/Resources/share/wireshark/extcap
+# If you change the nesting level be sure to check also the INSTALL_RPATH
+# target property.
if (WIN32)
set(EXTCAP_INSTALL_LIBDIR "extcap" CACHE INTERNAL "The extcap dir")
else ()
diff --git a/extcap/CMakeLists.txt b/extcap/CMakeLists.txt
index 3035b53206..8475a39598 100644
--- a/extcap/CMakeLists.txt
+++ b/extcap/CMakeLists.txt
@@ -46,6 +46,11 @@ macro(set_extcap_executable_properties _executable)
LINK_FLAGS "${WS_LINK_FLAGS}"
RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/run/extcap
)
+ if(ENABLE_RPATH_ORIGIN)
+ set_target_properties(${_executable} PROPERTIES
+ INSTALL_RPATH "\$ORIGIN/../.."
+ )
+ endif()
if(ENABLE_APPLICATION_BUNDLE)
if(NOT CMAKE_CFG_INTDIR STREQUAL ".")
# Xcode