From 2e9d234482bc84b564178a113bf145931087fff9 Mon Sep 17 00:00:00 2001 From: xiaoyisd Date: Fri, 18 Dec 2020 17:11:56 +0800 Subject: [PATCH] mac build fix rpath --- mindspore/ccsrc/CMakeLists.txt | 7 ++- .../ccsrc/minddata/dataset/CMakeLists.txt | 62 +++++++++++++++++++ setup.py | 1 + 3 files changed, 69 insertions(+), 1 deletion(-) diff --git a/mindspore/ccsrc/CMakeLists.txt b/mindspore/ccsrc/CMakeLists.txt index 120354a454e..1c1e7fff3cb 100644 --- a/mindspore/ccsrc/CMakeLists.txt +++ b/mindspore/ccsrc/CMakeLists.txt @@ -303,7 +303,6 @@ elseif (ENABLE_GPU) set(MINDSPORE_RPATH ${MINDSPORE_RPATH}:/usr/local/cuda/lib64) endif () set(MINDSPORE_RPATH ${ORIGIN_PATH}/lib:${MINDSPORE_RPATH}) - set_target_properties(_c_expression PROPERTIES INSTALL_RPATH ${MINDSPORE_RPATH}) if (CMAKE_SYSTEM_NAME MATCHES "Windows") @@ -350,6 +349,12 @@ if (ENABLE_GPU) endif () endif () +if (CMAKE_SYSTEM_NAME MATCHES "Darwin") + set(CMAKE_MACOSX_RPATH 1) + set(CMAKE_INSTALL_RPATH "@loader_path/lib;@loader_path") + set_target_properties(_c_expression PROPERTIES INSTALL_RPATH "${CMAKE_INSTALL_RPATH}") +endif () + if (ENABLE_CPU) target_link_libraries(_c_expression PRIVATE mindspore::dnnl mindspore::mkldnn) endif () diff --git a/mindspore/ccsrc/minddata/dataset/CMakeLists.txt b/mindspore/ccsrc/minddata/dataset/CMakeLists.txt index 9352e57ecb7..5e4c0700d9d 100644 --- a/mindspore/ccsrc/minddata/dataset/CMakeLists.txt +++ b/mindspore/ccsrc/minddata/dataset/CMakeLists.txt @@ -193,6 +193,68 @@ endif () ################# Link with external libraries ######################## target_link_libraries(_c_dataengine PRIVATE mindspore mindspore_gvar) + +if (CMAKE_SYSTEM_NAME MATCHES "Darwin") + set(CMAKE_MACOSX_RPATH 1) + set(CMAKE_INSTALL_RPATH "@loader_path/lib;@loader_path") + set_target_properties(_c_dataengine PROPERTIES INSTALL_RPATH "${CMAKE_INSTALL_RPATH}") +endif () + +set(targetso $) +set(target_tiny "libtinyxml") +set(target_icuuc "libicuuc") +set(target_icudata "libicudata") +set(target_icui18n "libicui18n") +function(changerpath targetso linkso) + set(some-file "${CMAKE_SOURCE_DIR}/mindspore/ccsrc/minddata/dataset/${linkso}.txt") + set(some-file1 "${CMAKE_SOURCE_DIR}/mindspore/ccsrc/minddata/dataset/${linkso}1.txt") + set(some-file2 "${CMAKE_SOURCE_DIR}/mindspore/ccsrc/minddata/dataset/${linkso}2.txt") + add_custom_command( + OUTPUT + ${some-file} + COMMAND + otool -L ${targetso} | grep ${linkso} > ${some-file} + WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}/mindspore/ccsrc/minddata/dataset" + VERBATIM + ) + add_custom_command( + OUTPUT + ${some-file1} + COMMAND + cat ${some-file} | cut -d " " -f 1 | sed -E "s/^.//g" > ${some-file1} + DEPENDS + ${some-file} + WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}/mindspore/ccsrc/minddata/dataset" + VERBATIM + ) + add_custom_command( + OUTPUT + ${some-file2} + COMMAND + awk -F "/" "{print $NF}" ${some-file1} > ${some-file2} + DEPENDS + ${some-file1} + WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}/mindspore/ccsrc/minddata/dataset" + VERBATIM + ) + add_custom_target( + link_${linkso} ALL + COMMAND install_name_tool -change `cat ${some-file1}` @rpath/`cat ${some-file2}` ${targetso} + WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}/mindspore/ccsrc/minddata/dataset" + DEPENDS ${targetso} ${some-file1} ${some-file2} + COMMENT "install tool name") +endfunction() + +if (CMAKE_SYSTEM_NAME MATCHES "Darwin") + changerpath(${targetso} ${target_tiny}) + changerpath(${targetso} ${target_icuuc}) + add_dependencies(link_${target_icuuc} link_${target_tiny}) + changerpath(${targetso} ${target_icudata}) + add_dependencies(link_${target_icudata} link_${target_icuuc}) + changerpath(${targetso} ${target_icui18n}) + add_dependencies(link_${target_icui18n} link_${target_icudata}) +endif() + if (${CMAKE_SYSTEM_NAME} MATCHES "Windows") if (ENABLE_PYTHON) target_link_libraries(_c_dataengine PRIVATE mindspore::pybind11_module ${PYTHON_LIBRARIES} ${SECUREC_LIBRARY}) diff --git a/setup.py b/setup.py index 4ecefd88b6e..47b691933a9 100644 --- a/setup.py +++ b/setup.py @@ -131,6 +131,7 @@ package_data = { '*.dll', 'lib/*.so*', 'lib/*.a', + 'lib/*.dylib*', '.commit_id', 'config/*' 'include/*',