From: DRC Date: Wed, 23 Nov 2016 23:12:57 +0000 (-0600) Subject: Build: Fix RPATH handling X-Git-Tag: 1.5.90~99 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=27d4c5ea2266fafbc6fecfbd4aa91d722d4d28fe;p=libjpeg-turbo Build: Fix RPATH handling CMAKE_INSTALL_RPATH has to be set before the targets are defined (oops.) This also explicitly turns on MACOSX_RPATH for the shared libraries (which is the default with newer versions of CMake but not with 2.8.x.) The old autotools/libtool build system hard-coded the install name directory of the OS X shared libraries to libdir, which meant that any executable that linked against those libraries would also be hard-coded to look for the libjpeg-turbo libraries in that directory. @rpath makes the OS X version of libjpeg-turbo behave like the Linux version, in the sense that the executables under /opt/libjpeg-turbo/bin will automatically pick up the libraries under /opt/libjpeg-turbo/lib* by default, but other executables won't unless they are linked with -rpath. --- diff --git a/CMakeLists.txt b/CMakeLists.txt index bfa1c50..95ff9cb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -124,6 +124,7 @@ else() endif() set(LIBDIR ${DEFAULT_LIBDIR} CACHE PATH "Directory into which libraries should be installed (default: ${DEFAULT_LIBDIR})") +set(CMAKE_INSTALL_RPATH ${LIBDIR}) foreach(var CMAKE_INSTALL_PREFIX BINDIR DATADIR DOCDIR INCLUDEDIR LIBDIR) message(STATUS "${var} = ${${var}}") @@ -573,6 +574,9 @@ if(WITH_TURBOJPEG) if(MINGW) set_target_properties(turbojpeg PROPERTIES LINK_FLAGS -Wl,--kill-at) endif() + if(APPLE) + set_target_properties(turbojpeg PROPERTIES MACOSX_RPATH 1) + endif() set_target_properties(turbojpeg PROPERTIES SOVERSION ${TURBOJPEG_SO_MAJOR_VERSION} VERSION ${TURBOJPEG_SO_VERSION}) if(TJMAPFLAG) @@ -1278,7 +1282,6 @@ endif() if(WIN32) set(EXE ".exe") endif() -SET(CMAKE_INSTALL_RPATH ${LIBDIR}) if(WITH_TURBOJPEG) if(ENABLE_SHARED) diff --git a/sharedlib/CMakeLists.txt b/sharedlib/CMakeLists.txt index ac0625c..6a65590 100755 --- a/sharedlib/CMakeLists.txt +++ b/sharedlib/CMakeLists.txt @@ -40,6 +40,9 @@ add_library(jpeg SHARED ${JPEG_SRCS} ${DEFFILE} $ set_target_properties(jpeg PROPERTIES SOVERSION ${SO_MAJOR_VERSION} VERSION ${SO_MAJOR_VERSION}.${SO_AGE}.${SO_MINOR_VERSION}) +if(APPLE) + set_target_properties(jpeg PROPERTIES MACOSX_RPATH 1) +endif() if(MAPFLAG) set_target_properties(jpeg PROPERTIES LINK_FLAGS "${MAPFLAG}${CMAKE_BINARY_DIR}/libjpeg.map")