Skip to content

Commit

Permalink
chore: Update cmake script to install shared library to project relea…
Browse files Browse the repository at this point in the history
…se directory
  • Loading branch information
royshil committed Jun 24, 2024
1 parent 051f9e2 commit fa90450
Showing 1 changed file with 19 additions and 10 deletions.
29 changes: 19 additions & 10 deletions cmake/BuildSherpaOnnx.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,16 @@ set(SHERPA_LIBS
espeak-ng
kaldi-decoder-core
kaldi-native-fbank-core
piper_phonemize
sherpa-onnx-c-api
sherpa-onnx-core
sherpa-onnx-fst
sherpa-onnx-fstfar
sherpa-onnx-kaldifst-core
ssentencepiece_core
ucd)
if(NOT APPLE)
list(APPEND SHERPA_LIBS piper_phonemize)
endif()

if(WIN32)
set(SHARED_LIBRARY_DESTINATION ${CMAKE_SOURCE_DIR}/release/$<CONFIG>/obs-plugins/64bit)
Expand Down Expand Up @@ -68,16 +70,8 @@ foreach(lib ${SHERPA_LIBS})
endforeach()

# install the onnxruntime shared libs to the project release directory
install(FILES ${INSTALL_DIR}/lib/${CMAKE_SHARED_LIBRARY_PREFIX}onnxruntime${CMAKE_SHARED_LIBRARY_SUFFIX}
DESTINATION ${SHARED_LIBRARY_DESTINATION})
if(WIN32)
install(
FILES ${INSTALL_DIR}/lib/${CMAKE_SHARED_LIBRARY_PREFIX}onnxruntime_providers_shared${CMAKE_SHARED_LIBRARY_SUFFIX}
DESTINATION ${SHARED_LIBRARY_DESTINATION})
endif()
if(APPLE)
foreach(SHARED_LIBRARY_FILE_NAME libpiper_phonemize.1.dylib libpiper_phonemize.1.2.0.dylib
libonnxruntime.1.17.1.dylib)
foreach(SHARED_LIBRARY_FILE_NAME libpiper_phonemize.1.2.0.dylib libonnxruntime.1.17.1.dylib)
set(SHARED_LIBRARY_FILE_LOCATION ${INSTALL_DIR}/lib/${SHARED_LIBRARY_FILE_NAME})
target_sources(${CMAKE_PROJECT_NAME} PRIVATE "${SHARED_LIBRARY_FILE_LOCATION}")
set_property(SOURCE "${SHARED_LIBRARY_FILE_LOCATION}" PROPERTY MACOSX_PACKAGE_LOCATION Frameworks)
Expand All @@ -88,6 +82,21 @@ if(APPLE)
COMMAND ${CMAKE_INSTALL_NAME_TOOL} -change "@rpath/${SHARED_LIBRARY_FILE_NAME}"
"@loader_path/../Frameworks/${SHARED_LIBRARY_FILE_NAME}" $<TARGET_FILE:${CMAKE_PROJECT_NAME}>)
endforeach()
# fix libsherpa-onnx-core.dylib to point to the correct location of libonnxruntime.1.17.1.dylib
foreach(SHARED_LIBRARY_FILE_NAME libsherpa-onnx-core.dylib libsherpa-onnx-c-api.dylib)
add_custom_command(
TARGET "${CMAKE_PROJECT_NAME}"
POST_BUILD
COMMAND
${CMAKE_INSTALL_NAME_TOOL} -change "@rpath/libpiper_phonemize.1.dylib" "@rpath/libpiper_phonemize.1.2.0.dylib"
${CMAKE_BINARY_DIR}/$<CONFIG>/${PROJECT_NAME}.plugin/Contents/Frameworks/${SHARED_LIBRARY_FILE_NAME})
endforeach()
else()
install(FILES ${INSTALL_DIR}/lib/${CMAKE_SHARED_LIBRARY_PREFIX}onnxruntime${CMAKE_SHARED_LIBRARY_SUFFIX}
DESTINATION ${SHARED_LIBRARY_DESTINATION})
install(
FILES ${INSTALL_DIR}/lib/${CMAKE_SHARED_LIBRARY_PREFIX}onnxruntime_providers_shared${CMAKE_SHARED_LIBRARY_SUFFIX}
DESTINATION ${SHARED_LIBRARY_DESTINATION})
endif()

# Add the sherpa-onnx target with all the dependencies
Expand Down

0 comments on commit fa90450

Please sign in to comment.