From 8010d273341843e6c8450e589525dd346913a7f6 Mon Sep 17 00:00:00 2001 From: Gabriel Dantas Date: Thu, 31 Oct 2024 10:44:18 -0300 Subject: [PATCH] fix copy onednnl 4 --- CMakeLists.txt | 48 ++++++++++++++++++------------------------------ 1 file changed, 18 insertions(+), 30 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 1b48364..036ce69 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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 $ - COMMAND ${CMAKE_COMMAND} -E copy ${ICU_LIBRARY_DIR}/libicuuc.dylib $ - COMMAND ${CMAKE_COMMAND} -E copy ${ICU_LIBRARY_DIR}/libicudata.dylib $ + ${CMAKE_COMMAND} -E copy ${ONEDNN_ROOT}/lib/libdnnl.3.dylib $ + ${CMAKE_COMMAND} -E copy ${ICU_LIBRARY_DIR}/libicuuc.dylib $ + ${CMAKE_COMMAND} -E copy ${ICU_LIBRARY_DIR}/libicudata.dylib $ + + " COMMENT "Adjusting LC_LOAD_DYLIB path for libdnnl" ) elseif(UNIX)