From 3ed18cee9681fb22736b93f17783b4d3470c2169 Mon Sep 17 00:00:00 2001 From: Adam Wegrzynek Date: Fri, 14 Feb 2020 14:06:23 +0100 Subject: [PATCH] RPATH settings should be defined before first target (#34) --- CMakeLists.txt | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index b65ce8d..0b99f67 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -51,6 +51,24 @@ set(CMAKE_THREAD_PREFER_PTHREAD TRUE) set(THREADS_PREFER_PTHREAD_FLAG TRUE) find_package(Threads REQUIRED) +#################################### +# RPATH +#################################### + +include(GNUInstallDirs) + +# Build targets with install rpath on Mac to dramatically speed up installation +set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE) +list(FIND CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}" isSystemDir) +if(CMAKE_SYSTEM_NAME STREQUAL "Darwin") + if("${isSystemDir}" STREQUAL "-1") + set(CMAKE_INSTALL_RPATH "@loader_path/../${CMAKE_INSTALL_LIBDIR}") + endif() + set(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE) +endif() +unset(isSystemDir) + + #################################### # Library #################################### @@ -137,20 +155,6 @@ endforeach() # Install #################################### -include(GNUInstallDirs) - -# Build targets with install rpath on Mac to dramatically speed up installation -# https://gitlab.kitware.com/cmake/community/wikis/doc/cmake/RPATH-handling -set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE) -list(FIND CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}" isSystemDir) -if(CMAKE_SYSTEM_NAME STREQUAL "Darwin") - if("${isSystemDir}" STREQUAL "-1") - set(CMAKE_INSTALL_RPATH "@loader_path/../${CMAKE_INSTALL_LIBDIR}") - endif() - set(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE) -endif() -unset(isSystemDir) - # Install library install(TARGETS Common EXPORT CommonTargets