From 2bf6841b03cbcfac6c477f562ff9db82a29a0c60 Mon Sep 17 00:00:00 2001 From: Thorsten Liebig Date: Sun, 21 Sep 2014 22:44:51 +0200 Subject: [PATCH] cmake: improve RPATH handling Signed-off-by: Thorsten Liebig --- CMakeLists.txt | 39 +++++++++++++++++++-------------------- 1 file changed, 19 insertions(+), 20 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index e1ee0d7..ebe2e9c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -22,26 +22,25 @@ ENDIF() ADD_DEFINITIONS(-DGIT_VERSION=\"${VERSION}\") -##### RPATH settings, see: http://www.cmake.org/Wiki/CMake_RPATH_handling#Always_full_RPATH ####### -# 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") -#################################################################################################### +# +# Set up RPATH for the project +# +option(ENABLE_RPATH "Enable rpath support on Linux and Mac" ON) +if(NOT CMAKE_INSTALL_RPATH) + # 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") +endif() +if(APPLE AND NOT CMAKE_INSTALL_NAME_DIR) + set(CMAKE_INSTALL_NAME_DIR "${CMAKE_INSTALL_PREFIX}/lib") +endif() +if(UNIX AND ENABLE_RPATH) + set(CMAKE_SKIP_BUILD_RPATH FALSE) + set(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE) + set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE) +endif() # Set locations of extra CMake modules SET(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${openEMS_SOURCE_DIR}/cmake/Modules/")