Skip to content

Commit

Permalink
Avoid hard-coded '../lib' in ApplicationContextBase
Browse files Browse the repository at this point in the history
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 bf5eaaa,
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.
  • Loading branch information
Matthew Mott committed Dec 21, 2020
1 parent 5ae45ca commit 737a8ae
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
6 changes: 4 additions & 2 deletions CMakeLists.txt
Expand Up @@ -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()
Expand Down
4 changes: 4 additions & 0 deletions config.h.in
Expand Up @@ -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@"

Expand Down
4 changes: 2 additions & 2 deletions libs/module/ApplicationContextBase.cpp
Expand Up @@ -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
Expand Down

0 comments on commit 737a8ae

Please sign in to comment.