From b46441085a5340b4108aec7c206f7f17f4ef8a1b Mon Sep 17 00:00:00 2001 From: Roland Kaufmann Date: Thu, 1 Aug 2013 14:29:04 +0200 Subject: [PATCH 1/2] Use RUNPATH in installed library by default When checking out from source code, the paths that were used to configure the project should be carried on to the installed binary, so the same libraries are used without much effort. By using RUNPATH instead of (just) RPATH, it can be overridden with LD_LIBRARY_PATH if the user so desires. --- cmake/Modules/OpmDefaults.cmake | 16 ++++++++++++++++ cmake/Scripts/configure | 13 ++++++++++++- 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/cmake/Modules/OpmDefaults.cmake b/cmake/Modules/OpmDefaults.cmake index 2e130363..b34c4206 100644 --- a/cmake/Modules/OpmDefaults.cmake +++ b/cmake/Modules/OpmDefaults.cmake @@ -1,8 +1,24 @@ # - Default settings for the build include (UseCompVer) +include(TestCXXAcceptsFlag) macro (opm_defaults opm) + # if we are installing a development version (default when checking out of + # VCS), then remember which directories were used when configuring. package + # distribution should disable this option. + option (USE_RUNPATH "Embed original dependency paths in installed library" ON) + if (USE_RUNPATH) + if (CMAKE_COMPILER_IS_GNUCXX) + check_cxx_accepts_flag ("-Wl,--enable-new-dtags" HAVE_RUNPATH) + if (HAVE_RUNPATH) + list (APPEND ${opm}_LINKER_FLAGS "-Wl,--enable-new-dtags") + endif (HAVE_RUNPATH) + endif (CMAKE_COMPILER_IS_GNUCXX) + # set this to avoid CMake stripping it off again + set (CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE) + endif (USE_RUNPATH) + # build release by default if (NOT CMAKE_CONFIGURATION_TYPES AND NOT CMAKE_BUILD_TYPE) set (CMAKE_BUILD_TYPE "Release") diff --git a/cmake/Scripts/configure b/cmake/Scripts/configure index c9b13f8a..04a9c804 100755 --- a/cmake/Scripts/configure +++ b/cmake/Scripts/configure @@ -19,6 +19,7 @@ Optional Features: of the options shared and static may be built. --enable-debug build a non-optimized version of the library [default=no] + --disable-runpath do not use RUNPATH in installed library [default=yes] --enable-lto use whole program optimization [default=no] --disable-tests do not compile and enable unit tests [default=yes] --disable-examples do not compile example programs [default=yes] @@ -108,6 +109,8 @@ silent_rules= debug_loc= #use_lto=" -DWHOLE_PROG_OPTIM=OFF" use_lto= +#use_runpath=" -DUSE_RUNPATH=OFF" +use_runpath= #use_tests=" -DBUILD_TESTING=ON" use_tests= #use_samples=" -DBUILD_EXAMPLES=ON" @@ -235,6 +238,10 @@ for OPT in "$@"; do pch_use=" -DPRECOMPILE_HEADERS:BOOL=OFF" pkgname="" ;; + runpath) + use_runpath=" -DUSE_RUNPATH=OFF" + pkgname="" + ;; silent-rules) silent_rules=" -DCMAKE_VERBOSE_MAKEFILE=ON" pkgname="" @@ -313,6 +320,10 @@ for OPT in "$@"; do pch_use=" -DPRECOMPILE_HEADERS:BOOL=ON" shared="" ;; + runpath) + use_runpath=" -DUSE_RUNPATH=ON" + shared="" + ;; lto) use_lto=" -DWHOLE_PROG_OPTIM=ON" shared="" @@ -373,7 +384,7 @@ for a in "${VARS[@]}"; do done # pass everything on to CMake -CMDLINE="env ${ENVVARS} ${CMAKE_COMMAND} \"${srcdir}\" \"-DCMAKE_INSTALL_PREFIX=$prefix\"${buildtype}${pch_use}${silent_rules}${debug_loc}${use_openmp}${use_mpi}${use_lto}${use_tests}${use_samples} ${FEATURES}" +CMDLINE="env ${ENVVARS} ${CMAKE_COMMAND} \"${srcdir}\" \"-DCMAKE_INSTALL_PREFIX=$prefix\"${buildtype}${pch_use}${silent_rules}${debug_loc}${use_openmp}${use_mpi}${use_lto}${use_runpath}${use_tests}${use_samples} ${FEATURES}" echo --- calling CMake --- echo ${CMDLINE} eval exec ${CMDLINE} From e5fc56ee831e3ca8402d4181ff857fa98790ad9d Mon Sep 17 00:00:00 2001 From: Roland Kaufmann Date: Thu, 1 Aug 2013 14:32:59 +0200 Subject: [PATCH 2/2] Exempt distribution packages from having RUNPATH Files that are distributed as packages should always assume that all the other libraries it depends on is as packages too, in the system directories, so there is no need to have a RUNPATH embedded in them. --- debian/rules | 2 +- redhat/opm-core.spec | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/debian/rules b/debian/rules index d6fcf5f4..5e8d7c71 100755 --- a/debian/rules +++ b/debian/rules @@ -19,7 +19,7 @@ override_dh_auto_build: dh_auto_build --buildsystem=cmake override_dh_auto_configure: - dh_auto_configure --buildsystem=cmake -- -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=1 -DCMAKE_INSTALL_DOCDIR=share/doc/libopm-core1 -DWHOLE_PROG_OPTIM=ON + dh_auto_configure --buildsystem=cmake -- -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=1 -DCMAKE_INSTALL_DOCDIR=share/doc/libopm-core1 -DWHOLE_PROG_OPTIM=ON -DUSE_RUNPATH=OFF override_dh_auto_install: dh_auto_install -- install-html diff --git a/redhat/opm-core.spec b/redhat/opm-core.spec index 4a9622ba..0b1f85e4 100644 --- a/redhat/opm-core.spec +++ b/redhat/opm-core.spec @@ -59,7 +59,7 @@ This package contains the applications for opm-core %setup -q %build -cmake28 -DBUILD_SHARED_LIBS=1 -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=%{_prefix} -DCMAKE_INSTALL_DOCDIR=share/doc/%{name}-%{version} -DWHOLE_PROG_OPTIM=ON +cmake28 -DBUILD_SHARED_LIBS=1 -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=%{_prefix} -DCMAKE_INSTALL_DOCDIR=share/doc/%{name}-%{version} -DWHOLE_PROG_OPTIM=ON -DUSE_RUNPATH=OFF make %install