Hi,
I am trying to produce a project that is relocatable at install time with it’s own shared libraries. Such that someone could either install it system wide by just running the installer, or could install it in a user folder and have it pick up the correct library paths to it’s own version of it’s libraries.
From the Wiki https://gitlab.kitware.com/cmake/community/-/wikis/doc/cmake/RPATH-handling#always-full-rpath it reads as though you can configure the installer such that it will cleanly handle both build and install time rpath requirements. Using the sample at the link I get the expected behaviour when I set INSTALL_PREFIX at generation time, but if I specify the install path using the --prefix option to the installer, the filest get installed into the correct locations but the RPATH is setup to look in the standard install paths e.g. /usr/local/lib.
It looks to me like CMAKE_INSTALL_PREFIX is in effect hard coded at generate/build time, which makes sense, but that isn’t clear in the example in the wiki. Is that the expected behaviour, should I just change my applications RPATH to be a relative path e.g.
set(CMAKE_INSTALL_RPATH "../lib")
The cmake project based on the wiki looks like
cmake_minimum_required(VERSION 3.14)
Project(localtest)
# use, i.e. don't skip the full RPATH for the build tree
set(CMAKE_SKIP_BUILD_RPATH FALSE)
# when building, don't use the install RPATH already
# (but later on when installing)
set(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE)
set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib")
# 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)
# the 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(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib")
endif("${isSystemDir}" STREQUAL "-1")
add_library(test_lib SHARED mylib.cpp )
add_executable(helloapp app.cpp)
target_link_libraries(helloapp test_lib)
install(TARGETS helloapp test_lib RUNTIME DESTINATION bin LIBRARY DESTINATION lib)
Thanks,
Paul