From f6bbde00c0887f78dad887b4782f30d12864ff8e Mon Sep 17 00:00:00 2001 From: Yangqing Jia Date: Tue, 18 Apr 2017 01:14:47 -0700 Subject: [PATCH] Update mac build to ease the rpath issues Summary: TSIA - for rationale, see comments. Closes https://github.com/caffe2/caffe2/pull/272 Differential Revision: D4905583 Pulled By: Yangqing fbshipit-source-id: f6cdbc6b51512da03a4aec3f53de720d35c948b6 --- CMakeLists.txt | 1 + caffe2/CMakeLists.txt | 17 +++++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index a40d54286b0..4205569e5a5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -33,6 +33,7 @@ endfunction(prepend) # ---[ CMake scripts + modules list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake/Modules) +set(CMAKE_MACOSX_RPATH 1) enable_testing() diff --git a/caffe2/CMakeLists.txt b/caffe2/CMakeLists.txt index 0deee97e869..e6986086b1a 100644 --- a/caffe2/CMakeLists.txt +++ b/caffe2/CMakeLists.txt @@ -161,6 +161,17 @@ if (BUILD_PYTHON) target_link_libraries( caffe2_pybind11_state ${Caffe2_MAIN_LIBS} ${Caffe2_DEPENDENCY_LIBS} ${Caffe2_PYTHON_DEPENDENCY_LIBS}) + # Add rpath to the python target, so that we will be able to load it. This + # is in order to ease the problem of anaconda's ipython DYLD bug, detailed + # here: + # https://github.com/BVLC/caffe/issues/2720 + # https://github.com/ipython/ipython/issues/8878 + if (APPLE) + add_custom_command( + TARGET caffe2_pybind11_state POST_BUILD + COMMAND install_name_tool -add_rpath ${CMAKE_INSTALL_PREFIX}/lib + $) + endif() install( TARGETS caffe2_pybind11_state DESTINATION ${CMAKE_INSTALL_PREFIX}/caffe2/python) @@ -180,6 +191,12 @@ if (BUILD_PYTHON) target_link_libraries( caffe2_pybind11_state_gpu ${Caffe2_MAIN_LIBS} ${Caffe2_DEPENDENCY_LIBS} ${Caffe2_PYTHON_DEPENDENCY_LIBS}) + if (APPLE) + add_custom_command( + TARGET caffe2_pybind11_state_gpu POST_BUILD + COMMAND install_name_tool -add_rpath ${CMAKE_INSTALL_PREFIX}/lib + $) + endif() install( TARGETS caffe2_pybind11_state_gpu DESTINATION ${CMAKE_INSTALL_PREFIX}/caffe2/python)