I would like to automatically add the path of libraries at link time to RPATH. After reading a bit I thought CMAKE_INSTALL_RPATH_USE_LINK_PATH
should do the job. Unfortunatly, the following MWE does not do the job:
cmake_minimum_required(VERSION 3.9)
cmake_policy(SET CMP0060 NEW)
set(CMAKE_SKIP_BUILD_RPATH FALSE)
# set(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE)
# set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib")
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
find_package(Boost COMPONENTS serialization REQUIRED)
# Setting CMAKE_INSTALL_RPATH explicitly works
# set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_RPATH};${Boost_LIBRARY_DIRS}")
add_executable(app main.cxx)
target_include_directories( app
PUBLIC ${Boost_INCLUDE_DIR})
target_link_libraries( app
PUBLIC Boost::serialization)
install(TARGETS app DESTINATION bin)
The output of readelf -d install/bin/app
for the example above shows the dependencies but no RPATH:
0x0000000000000001 (NEEDED) Shared library: [libboost_serialization.so.1.65.1]
0x0000000000000001 (NEEDED) Shared library: [libstdc++.so.6]
0x0000000000000001 (NEEDED) Shared library: [libm.so.6]
0x0000000000000001 (NEEDED) Shared library: [libgcc_s.so.1]
0x0000000000000001 (NEEDED) Shared library: [libc.so.6]
The commented lines is some stuff that I tried so far. Setting CMAKE_INSTALL_RPATH
explicitly works. But setting CMAKE_INSTALL_RPATH_USE_LINK_PATH
seems to have no effect. This is the case for both binaries, the build and the installed one.
Do I misunderstand what CMAKE_INSTALL_RPATH_USE_LINK_PATH
is doing or can someone spot the mistake?
CMake 3.13, CentOS 7