From 737a8ae0dd67a463109fb4c8b73062a2f1fbd1fb Mon Sep 17 00:00:00 2001 From: Matthew Mott Date: Mon, 21 Dec 2020 13:43:56 +0000 Subject: [PATCH] Avoid hard-coded '../lib' in ApplicationContextBase Another hard-coded library directory lurking in ApplicationContextBase was continuing to break relocatable builds on systems which default to 'lib64' as their library directory name. Although the RPATH was fixed in bf5eaaa9264d1763, the relative path is also needed when we dynamically load the modules. The CMake script now writes a RELATIVE_LIBDIR variable into config.h which contains the relative part of the library directory (i.e. starting with ".."), and this RELATIVE_LIBDIR is now used both to set the RPATH in CMakeLists.txt and in ApplicationContextBase to load the modules. --- CMakeLists.txt | 6 ++++-- config.h.in | 4 ++++ libs/module/ApplicationContextBase.cpp | 4 ++-- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 746437a90c..caa4fd2881 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -20,14 +20,16 @@ include(GNUInstallDirs) set(CORE_MODULE_LIBRARY "libradiantcore") set(PKGDATADIR "${CMAKE_INSTALL_FULL_DATADIR}/darkradiant") set(PKGLIBDIR "${CMAKE_INSTALL_FULL_LIBDIR}/darkradiant") -if (NOT ${ENABLE_RELOCATION}) +if (${ENABLE_RELOCATION}) + set(RELATIVE_LIBDIR "../${CMAKE_INSTALL_LIBDIR}/darkradiant") +else() set(HTMLDIR "${CMAKE_INSTALL_FULL_DATADIR}/doc/darkradiant") endif() # Build shared libraries by default option(BUILD_SHARED_LIBS "Build shared libraries" ON) if (${ENABLE_RELOCATION}) - set(CMAKE_INSTALL_RPATH "$ORIGIN/../${CMAKE_INSTALL_LIBDIR}/darkradiant") + set(CMAKE_INSTALL_RPATH "$ORIGIN/${RELATIVE_LIBDIR}") else() set(CMAKE_INSTALL_RPATH "${PKGLIBDIR}") endif() diff --git a/config.h.in b/config.h.in index 3397aa36c9..a09ea95c92 100644 --- a/config.h.in +++ b/config.h.in @@ -14,6 +14,10 @@ /* Package library directory (e.g. /usr/lib/darkradiant) */ #cmakedefine PKGLIBDIR "@PKGLIBDIR@" +/* Relative library directory from binary (e.g. ../lib/darkradiant). Only + * defined if ENABLE_RELOCATION is defined. */ +#cmakedefine RELATIVE_LIBDIR "@RELATIVE_LIBDIR@" + /* Package data directory (e.g. /usr/share/darkradiant) */ #cmakedefine PKGDATADIR "@PKGDATADIR@" diff --git a/libs/module/ApplicationContextBase.cpp b/libs/module/ApplicationContextBase.cpp index 120e358213..9586d01103 100644 --- a/libs/module/ApplicationContextBase.cpp +++ b/libs/module/ApplicationContextBase.cpp @@ -50,8 +50,8 @@ std::string ApplicationContextBase::getLibraryBasePath() const #if defined(__APPLE__) return _appPath; #elif defined(POSIX) -# if defined(ENABLE_RELOCATION) - return _appPath + "../lib/darkradiant/"; +# if defined(ENABLE_RELOCATION) && defined(RELATIVE_LIBDIR) + return _appPath + RELATIVE_LIBDIR; # elif defined(PKGLIBDIR) return PKGLIBDIR; # else