Skip to content

Commit

Permalink
fix copy onednnl 4
Browse files Browse the repository at this point in the history
  • Loading branch information
GabrielNSD committed Oct 31, 2024
1 parent eb5b214 commit 8010d27
Showing 1 changed file with 18 additions and 30 deletions.
48 changes: 18 additions & 30 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -148,41 +148,29 @@ endif()

# TODO: find a better way to get these libraries version number (they can change between builds)
if(APPLE)
execute_process(
COMMAND otool -L ${EXTERNAL_INSTALL_LOCATION}/lib/libOpenNMTTokenizer.dylib | grep "libicuuc" | sed -E "s|.*(libicuuc[^ ]*).*|\\1|"
OUTPUT_VARIABLE ICU_UC_LIB_NAME
OUTPUT_STRIP_TRAILING_WHITESPACE
)

message(STATUS "Extracted ICU UC library name: ${ICU_UC_LIB_NAME}")

execute_process(
COMMAND otool -L ${EXTERNAL_INSTALL_LOCATION}/lib/libOpenNMTTokenizer.dylib | grep "libicudata" | sed -E "s|.*(libicudata[^ ]*).*|\\1|"
OUTPUT_VARIABLE ICU_DATA_LIB_NAME
OUTPUT_STRIP_TRAILING_WHITESPACE
)

message(STATUS "Extracted ICU DATA library name: ${ICU_DATA_LIB_NAME}")
# Copy required dylibs to the build directory and adjust LC_LOAD_DYLIB path
add_custom_command(TARGET metaltranslate POST_BUILD
COMMAND bash -c "
ICU_UC_LIB_NAME=$(otool -L ${EXTERNAL_INSTALL_LOCATION}/lib/libOpenNMTTokenizer.dylib | grep 'libicuuc' | sed -E 's|.*(libicuuc[^ ]*).*|\\1|');
ICU_DATA_LIB_NAME=$(otool -L ${EXTERNAL_INSTALL_LOCATION}/lib/libOpenNMTTokenizer.dylib | grep 'libicudata' | sed -E 's|.*(libicudata[^ ]*).*|\\1|');
DNNL_LIB_NAME=$(otool -L ${EXTERNAL_INSTALL_LOCATION}/lib/libctranslate2.4.3.1.dylib | grep 'libdnnl' | sed -E 's|.*(libdnnl[^ ]*).*|\\1|');
execute_process(
COMMAND otool -L ${EXTERNAL_INSTALL_LOCATION}/lib/libctranslate2.4.3.1.dylib | grep "libicudata" | sed -E "s|.*(libdnnl[^ ]*).*|\\1|"
OUTPUT_VARIABLE DNNL_LIB_NAME
OUTPUT_STRIP_TRAILING_WHITESPACE
)
echo 'Extracted ICU UC library name: ${ICU_UC_LIB_NAME}';
echo 'Extracted ICU DATA library name: ${ICU_DATA_LIB_NAME}';
echo 'Extracted DNNL library name: ${DNNL_LIB_NAME}';
message(STATUS "Extracted DNNL library name: ${DNNL_LIB_NAME}")
# Copy required dylibs to the build directory and adjust LC_LOAD_DYLIB path
add_custom_command(TARGET metaltranslate POST_BUILD
COMMAND install_name_tool -change ${ONEDNN_ROOT}/lib/${DNNL_LIB_NAME} @rpath/libdnnl.3.dylib ${EXTERNAL_INSTALL_LOCATION}/lib/libctranslate2.4.3.1.dylib # change lib path of ctranslate2 lib
COMMAND install_name_tool -change ${ICU_LIBRARY_DIR}/${ICU_UC_LIB_NAME} @rpath/libicuuc.dylib ${EXTERNAL_INSTALL_LOCATION}/lib/libctranslate2.4.3.1.dylib
COMMAND install_name_tool -change ${ICU_LIBRARY_DIR}/${ICU_DATA_LIB_NAME} @rpath/libicudata.dylib ${EXTERNAL_INSTALL_LOCATION}/lib/libOpenNMTTokenizer.dylib
COMMAND install_name_tool -change ${ICU_LIBRARY_DIR}/${ICU_UC_LIB_NAME} @rpath/libicuuc.dylib ${EXTERNAL_INSTALL_LOCATION}/lib/libOpenNMTTokenizer.dylib
install_name_tool -change ${ONEDNN_ROOT}/lib/${DNNL_LIB_NAME} @rpath/libdnnl.3.dylib ${EXTERNAL_INSTALL_LOCATION}/lib/libctranslate2.4.3.1.dylib # change lib path of ctranslate2 lib
install_name_tool -change ${ICU_LIBRARY_DIR}/${ICU_UC_LIB_NAME} @rpath/libicuuc.dylib ${EXTERNAL_INSTALL_LOCATION}/lib/libctranslate2.4.3.1.dylib
install_name_tool -change ${ICU_LIBRARY_DIR}/${ICU_DATA_LIB_NAME} @rpath/libicudata.dylib ${EXTERNAL_INSTALL_LOCATION}/lib/libOpenNMTTokenizer.dylib
install_name_tool -change ${ICU_LIBRARY_DIR}/${ICU_UC_LIB_NAME} @rpath/libicuuc.dylib ${EXTERNAL_INSTALL_LOCATION}/lib/libOpenNMTTokenizer.dylib
# copy files to build directory
COMMAND ${CMAKE_COMMAND} -E copy ${ONEDNN_ROOT}/lib/libdnnl.3.dylib $<TARGET_FILE_DIR:metaltranslate>
COMMAND ${CMAKE_COMMAND} -E copy ${ICU_LIBRARY_DIR}/libicuuc.dylib $<TARGET_FILE_DIR:metaltranslate>
COMMAND ${CMAKE_COMMAND} -E copy ${ICU_LIBRARY_DIR}/libicudata.dylib $<TARGET_FILE_DIR:metaltranslate>
${CMAKE_COMMAND} -E copy ${ONEDNN_ROOT}/lib/libdnnl.3.dylib $<TARGET_FILE_DIR:metaltranslate>
${CMAKE_COMMAND} -E copy ${ICU_LIBRARY_DIR}/libicuuc.dylib $<TARGET_FILE_DIR:metaltranslate>
${CMAKE_COMMAND} -E copy ${ICU_LIBRARY_DIR}/libicudata.dylib $<TARGET_FILE_DIR:metaltranslate>
"
COMMENT "Adjusting LC_LOAD_DYLIB path for libdnnl"
)
elseif(UNIX)
Expand Down

0 comments on commit 8010d27

Please sign in to comment.