Commit c816a2bc authored by Friedrich W. H. Kossebau's avatar Friedrich W. H. Kossebau
Browse files

Set RPATH to custom dirs of own and foreign libs; no linking to build dir

Summary:
When installing marble to a non-standard system directory
the executable loader needs to be informed about the location of the
marble libraries. Until now for marble executables this needs to be done
via the env var LD_LIBRARY_PATH, which has the disadvantage of needing
to be done as explicit separate step and also affects other executables
which see this env var.
Instead the custom locations of linked libraries can be tagged within
the executable, via the RPATH (or RUNPATH) entries, which then is
automatically available and also only valid for the given executable.

Libmarblewidget only works with data & plugins in installation folders.
So when running executables from the build dir (apps, tools, tests)
linked to libraries from the build dir, for one things might not work
due to not yet installed data/plugins. Or there are API/ABI-related
changes done but without reinstallation, so installed plugins and
libraries in the build dir are incompatible and will fail with
strange behaviour.
To protect against that some more when linking the executables
in the build dir the RPATH can be set already to the installation
location only, so the versions of the libraries in the build dir
will not be seen and at least libraries and plugins are consistent.

More info e.g. here:
https://cmake.org/Wiki/CMake_RPATH_handling
http://tldp.org/HOWTO/Program-Library-HOWTO/shared-libraries.html

Reviewers: rahn, shentey, nienhueser, #marble

Reviewed By: nienhueser, #marble

Differential Revision: https://phabricator.kde.org/D3358
parent 68d303e2
......@@ -35,6 +35,24 @@ if (POLICY CMP0063)
cmake_policy(SET CMP0063 NEW)
endif()
# RPATH/RUNPATH settings
if (UNIX)
# Add CMAKE_INSTALL_FULL_LIBDIR to the RPATH to be used when installing,
# but only if it isn't a standard system directory.
list(FIND CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES "${CMAKE_INSTALL_FULL_LIBDIR}" isSystemLibDir)
list(FIND CMAKE_CXX_IMPLICIT_LINK_DIRECTORIES "${CMAKE_INSTALL_FULL_LIBDIR}" isSystemCxxLibDir)
list(FIND CMAKE_C_IMPLICIT_LINK_DIRECTORIES "${CMAKE_INSTALL_FULL_LIBDIR}" isSystemCLibDir)
if("${isSystemLibDir}" STREQUAL "-1" AND "${isSystemCxxLibDir}" STREQUAL "-1" AND "${isSystemCLibDir}" STREQUAL "-1")
set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_FULL_LIBDIR}")
endif()
# Add directories which are in the linker search path (but outside the project)
# to the RPATH to be used when installing
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
# no libs or plugins are designed to be used from the build dir, so directly link with install rpath
set(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE)
endif (UNIX)
####################################################
# Where to look first for cmake modules,
# before ${CMAKE_ROOT}/Modules/ is checked
......
......@@ -40,12 +40,6 @@ target_link_libraries( ${_target_name} ${${_target_name}_LIBS}
marblewidget )
install( TARGETS ${_target_name} DESTINATION ${MARBLE_PLUGIN_INSTALL_PATH} )
set_target_properties( ${_target_name} PROPERTIES
INSTALL_RPATH_USE_LINK_PATH TRUE
SKIP_BUILD_RPATH TRUE
BUILD_WITH_INSTALL_RPATH TRUE
)
endmacro( marble_add_plugin _target_name )
# these plugins are slightly different
......@@ -60,12 +54,6 @@ target_link_libraries( ${_target_name} ${${_target_name}_LIBS}
marblewidget )
install( TARGETS ${_target_name} DESTINATION ${QT_PLUGINS_DIR}/designer )
set_target_properties( ${_target_name} PROPERTIES
INSTALL_RPATH_USE_LINK_PATH TRUE
SKIP_BUILD_RPATH TRUE
BUILD_WITH_INSTALL_RPATH TRUE
)
endmacro( marble_add_designer_plugin _target_name )
if( WIN32 )
......
......@@ -52,12 +52,6 @@ if(Qt5Positioning_FOUND)
)
endif()
set_target_properties( marbledeclarative PROPERTIES
INSTALL_RPATH_USE_LINK_PATH TRUE
SKIP_BUILD_RPATH TRUE
BUILD_WITH_INSTALL_RPATH TRUE
)
if(WIN32)
install(TARGETS marbledeclarative RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX} ARCHIVE DESTINATION lib)
else()
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment