mac build fix rpath

This commit is contained in:
xiaoyisd 2020-12-18 17:11:56 +08:00
parent 3111529d5c
commit 2e9d234482
3 changed files with 69 additions and 1 deletions

View File

@ -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 ()

View File

@ -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 $<TARGET_FILE:_c_dataengine>)
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})

View File

@ -131,6 +131,7 @@ package_data = {
'*.dll',
'lib/*.so*',
'lib/*.a',
'lib/*.dylib*',
'.commit_id',
'config/*'
'include/*',