Skip to content

Commit 997b27f

Browse files
anthony-kolesovtkrasnukha
authored andcommitted
Allow cmake RPATH variables to be overridden from the command line
Current CMakeLists.txt forces a specific content into the final RPATH, in particular that it should contain an absolute path to the installation directory. This is not always optimal, as relocatable applications on Linux require there to be a path relative to $ORIGIN. It is possible to ensure that $ORIGIN will be in the RPATH by using a -Wl,rpath= with a desired value, but this is basically a hack that bypasses cmake mechanisms. Better approach would be to modify CMakeLists.txt to respect values that are passed from the command line via -D option. Default behavior is not changed by this commit.
1 parent 12ae118 commit 997b27f

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

CMakeLists.txt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,18 +45,18 @@ endif()
4545

4646
# https://gitlab.kitware.com/cmake/community/wikis/doc/cmake/RPATH-handling
4747
# use, i.e. don't skip, the full RPATH for the build tree
48-
SET(CMAKE_SKIP_BUILD_RPATH FALSE)
48+
SET(CMAKE_SKIP_BUILD_RPATH FALSE CACHE BOOL "")
4949
# when building, don't use the install RPATH already
5050
# (but later on when installing)
51-
SET(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE)
52-
SET(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib")
51+
SET(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE CACHE BOOL "")
52+
SET(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib" CACHE STRING "")
5353
# add the automatically determined parts of the RPATH
5454
# which point to directories outside the build tree to the install RPATH
55-
SET(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
55+
SET(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE CACHE BOOL "")
5656
# the RPATH to be used when installing, but only if it's not a system directory
5757
LIST(FIND CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES "${CMAKE_INSTALL_PREFIX}/lib" isSystemDir)
5858
IF("${isSystemDir}" STREQUAL "-1")
59-
SET(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib")
59+
SET(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib" CACHE STRING "")
6060
ENDIF("${isSystemDir}" STREQUAL "-1")
6161

6262
add_subdirectory(src)

0 commit comments

Comments
 (0)