From afb2c0ce8660b7c79892f6532403753114bf34d0 Mon Sep 17 00:00:00 2001 From: Jesse Hellemn Date: Mon, 26 Nov 2018 15:55:40 -0800 Subject: [PATCH] changing some rpath stuff (#14304) Summary: See if anything breaks Pull Request resolved: https://github.com/pytorch/pytorch/pull/14304 Differential Revision: D13201418 Pulled By: pjh5 fbshipit-source-id: ac2101b61a23bda37329d4d923c3d9d120e718bf --- cmake/Dependencies.cmake | 15 +++++++++------ torch/CMakeLists.txt | 12 +++++------- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/cmake/Dependencies.cmake b/cmake/Dependencies.cmake index 01e3594..df6a6f6 100644 --- a/cmake/Dependencies.cmake +++ b/cmake/Dependencies.cmake @@ -1004,16 +1004,19 @@ if (NOT BUILD_ATEN_MOBILE) # see https://cmake.org/Wiki/CMake_RPATH_handling if (APPLE) set(CMAKE_MACOSX_RPATH ON) - endif() + set(_rpath_portable_origin "@loader_path") + else() + set(_rpath_portable_origin $ORIGIN) + endif(APPLE) + # Use separate rpaths during build and install phases set(CMAKE_SKIP_BUILD_RPATH FALSE) + # Don't use the install-rpath during the build phase set(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE) - set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib") + set(CMAKE_INSTALL_RPATH "${_rpath_portable_origin}") + # Automatically add all linked folders that are NOT in the build directory to + # the rpath (per library?) set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE) set(CMAKE_POSITION_INDEPENDENT_CODE TRUE) - 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() # Top-level build config ############################################ diff --git a/torch/CMakeLists.txt b/torch/CMakeLists.txt index 0683e9d..cce58b2 100644 --- a/torch/CMakeLists.txt +++ b/torch/CMakeLists.txt @@ -29,9 +29,12 @@ endif() # RPATH stuff # see https://cmake.org/Wiki/CMake_RPATH_handling -if(APPLE) +if (APPLE) set(CMAKE_MACOSX_RPATH ON) -endif() + set(_rpath_portable_origin "@loader_path") +else() + set(_rpath_portable_origin $ORIGIN) +endif(APPLE) # Use separate rpaths during build and install phases set(CMAKE_SKIP_BUILD_RPATH FALSE) # Don't use the install-rpath during the build phase @@ -40,11 +43,6 @@ set(CMAKE_POSITION_INDEPENDENT_CODE TRUE) # Automatically add all linked folders that are NOT in the build directory to # the rpath (per library?) set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE) -# Always ensure that CMAKE_INSTALL_PREFIX/lib is in the rpath -list(FIND CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES "${CMAKE_INSTALL_PREFIX}/lib" isSystemDir) -if("${isSystemDir}" STREQUAL "-1") - list(APPEND CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib") -endif() # Get the correct Python executable if (DEFINED ENV{PYTORCH_PYTHON}) -- 2.7.4