From 96c0dc07a785fa5f2146038a8ac2f35c54fe15b9 Mon Sep 17 00:00:00 2001 From: Simon Hausmann Date: Mon, 11 Feb 2019 15:45:56 +0100 Subject: [PATCH] Use rpath by default not only for building but also installed binaries This makes it possible to use the binaries out of the box. This is particularly relevant for program binaries that link against QtCore dynamically, when trying to use these binaries during cross-compilation. Change-Id: I7dee93194be3fff5c6e3bbb9e202e4cf5e19b6d0 Reviewed-by: Volker Krause --- cmake/QtBuild.cmake | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/cmake/QtBuild.cmake b/cmake/QtBuild.cmake index d207252c299..db5b13a291e 100644 --- a/cmake/QtBuild.cmake +++ b/cmake/QtBuild.cmake @@ -40,6 +40,20 @@ set(INSTALL_CMAKE_NAMESPACE "Qt${PROJECT_VERSION_MAJOR}" CACHE STRING "CMake nam set(QT_CMAKE_EXPORT_NAMESPACE "Qt${PROJECT_VERSION_MAJOR}" CACHE STRING "CMake namespace used when exporting targets [Qt${PROJECT_VERSION_MAJOR}]") +# the default RPATH to be used when installing, but only if it's not a system directory +LIST(FIND CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES "${CMAKE_INSTALL_PREFIX}/lib" isSystemDir) +IF("${isSystemDir}" STREQUAL "-1") + SET(_default_install_rpath "${CMAKE_INSTALL_PREFIX}/lib") +ENDIF("${isSystemDir}" STREQUAL "-1") + +# Default rpath settings: Use rpath for build tree as well as a full path for the installed binaries. +# For origin builds, one needs to override CMAKE_INSTALL_RPATH for example with $ORIGIN/../lib +SET(CMAKE_INSTALL_RPATH "${_default_install_rpath}" CACHE PATH "RPATH for installed binaries") + +# 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) + # Platform define path, etc. if(WIN32) set(QT_DEFAULT_PLATFORM_DEFINITIONS UNICODE _UNICODE WIN32 _ENABLE_EXTENDED_ALIGNED_STORAGE)