diff options
author | Brad King <brad.king@kitware.com> | 2020-01-14 11:56:01 -0500 |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2020-01-14 12:03:06 -0500 |
commit | d92bf9e84f3ed28c5418dddb1cc281e67e2accce (patch) | |
tree | 5e2ccdf71ba5700bd8c14a58cc95998636311014 /CMakeLists.txt | |
parent | 710371ca2f5032462e8dc352da869834bb421261 (diff) | |
download | cmake-d92bf9e84f3ed28c5418dddb1cc281e67e2accce.tar.gz |
Enable RPATH for CMake's own binaries by default
Reconcile the changes made by:
* commit ae62f66033 (ENH: CMake does not need RPATHs at all for its own executables, 2006-03-01, v2.4.0~380)
* commit a056cffc5b (COMP: enable RPATH if any of the CMAKE_USE_SYSTEM_XXX variables is enabled, 2007-08-28, v2.6.0~1183)
* commit c0108d1e07 (COMP: use RPATH is building QtDialog and the Qt libs are not in /lib or /usr/lib, 2007-11-05, v2.6.0~915)
The overall goal of those changes was to get the RPATH set for external
libraries when needed and also to avoid re-linking or other RPATH
editing on installation. We can use a simpler approach to satisfy both
goals: always use RPATH entries for libraries found externally. If
there are no such libraries we will get no RPATH. If there are such
libraries that are not in standard paths we will get a RPATH that points
at them. This will work for running either from the build tree or the
install tree, so we can use the same for both to avoid editing on
installation.
Fixes: #20185
Diffstat (limited to 'CMakeLists.txt')
-rw-r--r-- | CMakeLists.txt | 44 |
1 files changed, 7 insertions, 37 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index da99a6ee8d..6f4c111203 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -671,10 +671,6 @@ if(NOT CMake_TEST_EXTERNAL_CMAKE) set(LIBRARY_OUTPUT_PATH "" CACHE INTERNAL "Where to put the libraries for CMake") - # The CMake executables usually do not need any rpath to run in the build or - # install tree. - set(CMAKE_SKIP_RPATH ON CACHE INTERNAL "CMake does not need RPATHs.") - # Load install destinations. include(Source/CMakeInstallDestinations.cmake) @@ -714,19 +710,6 @@ if(NOT CMake_TEST_EXTERNAL_CMAKE) # build the utilities (a macro defined in this file) CMAKE_BUILD_UTILITIES() - # On NetBSD ncurses is required, since curses doesn't have the wsyncup() - # function. ncurses is installed via pkgsrc, so the library is in /usr/pkg/lib, - # which isn't in the default linker search path. So without RPATH ccmake - # doesn't run and the build doesn't succeed since ccmake is executed for - # generating the documentation. - if(BUILD_CursesDialog) - get_filename_component(_CURSES_DIR "${CURSES_LIBRARY}" PATH) - set(CURSES_NEED_RPATH FALSE) - if(NOT "${_CURSES_DIR}" STREQUAL "/lib" AND NOT "${_CURSES_DIR}" STREQUAL "/usr/lib" AND NOT "${_CURSES_DIR}" STREQUAL "/lib64" AND NOT "${_CURSES_DIR}" STREQUAL "/usr/lib64") - set(CURSES_NEED_RPATH TRUE) - endif() - endif() - if(BUILD_QtDialog) if(APPLE) set(CMAKE_BUNDLE_VERSION @@ -739,28 +722,15 @@ if(NOT CMake_TEST_EXTERNAL_CMAKE) set(CMAKE_INSTALL_PREFIX "${CMAKE_INSTALL_PREFIX}CMake.app/Contents") endif() - - set(QT_NEED_RPATH FALSE) - if(NOT "${QT_LIBRARY_DIR}" STREQUAL "/lib" AND NOT "${QT_LIBRARY_DIR}" STREQUAL "/usr/lib" AND NOT "${QT_LIBRARY_DIR}" STREQUAL "/lib64" AND NOT "${QT_LIBRARY_DIR}" STREQUAL "/usr/lib64") - set(QT_NEED_RPATH TRUE) - endif() endif() - - # The same might be true on other systems for other libraries. - # Then only enable RPATH if we have are building at least with cmake 2.4, - # since this one has much better RPATH features than cmake 2.2. - # The executables are then built with the RPATH for the libraries outside - # the build tree, which is both the build and the install RPATH. - if (UNIX) - if( CMAKE_USE_SYSTEM_CURL OR CMAKE_USE_SYSTEM_ZLIB - OR CMAKE_USE_SYSTEM_EXPAT OR CURSES_NEED_RPATH OR QT_NEED_RPATH) - set(CMAKE_SKIP_RPATH OFF CACHE INTERNAL "CMake built with RPATH.") - set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE) - set(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE) - endif() - endif () - + if(UNIX) + # Install executables with the RPATH set for libraries outside the build tree. + # This is also suitable for binaries in the build tree. Avoid re-link on install. + set(CMAKE_INSTALL_RPATH_USE_LINK_PATH ON CACHE BOOL "Install with RPATH set to find custom-built libraries.") + set(CMAKE_BUILD_WITH_INSTALL_RPATH ON CACHE BOOL "Build with RPATH set to match install-tree RPATH.") + mark_as_advanced(CMAKE_INSTALL_RPATH_USE_LINK_PATH CMAKE_BUILD_WITH_INSTALL_RPATH) + endif() # add the uninstall support configure_file( |