Committed by
GitHub
add openfst.cmake file (#707)
1. When compiling locally, openfst is missing.so add this file to the sherpa-onnx/cmake folder
正在显示
1 个修改的文件
包含
89 行增加
和
0 行删除
cmake/openfst.cmake
0 → 100644
| 1 | +# Copyright (c) 2020 Xiaomi Corporation (author: Fangjun Kuang) | ||
| 2 | + | ||
| 3 | +function(download_openfst) | ||
| 4 | + include(FetchContent) | ||
| 5 | + | ||
| 6 | + set(openfst_URL "https://github.com/kkm000/openfst/archive/refs/tags/win/1.6.5.1.tar.gz") | ||
| 7 | + set(openfst_URL2 "https://huggingface.co/csukuangfj/kaldi-hmm-gmm-cmake-deps/resolve/main/openfst-win-1.6.5.1.tar.gz") | ||
| 8 | + set(openfst_HASH "SHA256=02c49b559c3976a536876063369efc0e41ab374be1035918036474343877046e") | ||
| 9 | + | ||
| 10 | + # If you don't have access to the Internet, | ||
| 11 | + # please pre-download it | ||
| 12 | + set(possible_file_locations | ||
| 13 | + $ENV{HOME}/Downloads/openfst-win-1.6.5.1.tar.gz | ||
| 14 | + ${CMAKE_SOURCE_DIR}/openfst-win-1.6.5.1.tar.gz | ||
| 15 | + ${CMAKE_BINARY_DIR}/openfst-win-1.6.5.1.tar.gz | ||
| 16 | + /tmp/openfst-win-1.6.5.1.tar.gz | ||
| 17 | + /star-fj/fangjun/download/github/openfst-win-1.6.5.1.tar.gz | ||
| 18 | + ) | ||
| 19 | + | ||
| 20 | + foreach(f IN LISTS possible_file_locations) | ||
| 21 | + if(EXISTS ${f}) | ||
| 22 | + set(openfst_URL "${f}") | ||
| 23 | + file(TO_CMAKE_PATH "${openfst_URL}" openfst_URL) | ||
| 24 | + set(openfst_URL2) | ||
| 25 | + break() | ||
| 26 | + endif() | ||
| 27 | + endforeach() | ||
| 28 | + | ||
| 29 | + set(HAVE_BIN OFF CACHE BOOL "" FORCE) | ||
| 30 | + set(HAVE_SCRIPT ON CACHE BOOL "" FORCE) | ||
| 31 | + set(HAVE_COMPACT OFF CACHE BOOL "" FORCE) | ||
| 32 | + set(HAVE_COMPRESS OFF CACHE BOOL "" FORCE) | ||
| 33 | + set(HAVE_CONST OFF CACHE BOOL "" FORCE) | ||
| 34 | + set(HAVE_FAR OFF CACHE BOOL "" FORCE) | ||
| 35 | + set(HAVE_GRM OFF CACHE BOOL "" FORCE) | ||
| 36 | + set(HAVE_PDT OFF CACHE BOOL "" FORCE) | ||
| 37 | + set(HAVE_MPDT OFF CACHE BOOL "" FORCE) | ||
| 38 | + set(HAVE_LINEAR OFF CACHE BOOL "" FORCE) | ||
| 39 | + set(HAVE_LOOKAHEAD OFF CACHE BOOL "" FORCE) | ||
| 40 | + set(HAVE_NGRAM OFF CACHE BOOL "" FORCE) | ||
| 41 | + set(HAVE_PYTHON OFF CACHE BOOL "" FORCE) | ||
| 42 | + set(HAVE_SPECIAL OFF CACHE BOOL "" FORCE) | ||
| 43 | + | ||
| 44 | + if(NOT WIN32) | ||
| 45 | + FetchContent_Declare(openfst | ||
| 46 | + URL | ||
| 47 | + ${openfst_URL} | ||
| 48 | + ${openfst_URL2} | ||
| 49 | + URL_HASH ${openfst_HASH} | ||
| 50 | + PATCH_COMMAND | ||
| 51 | + sed -i.bak s/enable_testing\(\)//g "src/CMakeLists.txt" && | ||
| 52 | + sed -i.bak s/add_subdirectory\(test\)//g "src/CMakeLists.txt" && | ||
| 53 | + sed -i.bak /message/d "src/script/CMakeLists.txt" | ||
| 54 | + # sed -i.bak s/add_subdirectory\(script\)//g "src/CMakeLists.txt" && | ||
| 55 | + # sed -i.bak s/add_subdirectory\(extensions\)//g "src/CMakeLists.txt" | ||
| 56 | + ) | ||
| 57 | + else() | ||
| 58 | + FetchContent_Declare(openfst | ||
| 59 | + URL ${openfst_URL} | ||
| 60 | + URL_HASH ${openfst_HASH} | ||
| 61 | + ) | ||
| 62 | + endif() | ||
| 63 | + | ||
| 64 | + FetchContent_GetProperties(openfst) | ||
| 65 | + if(NOT openfst_POPULATED) | ||
| 66 | + message(STATUS "Downloading openfst from ${openfst_URL}") | ||
| 67 | + FetchContent_Populate(openfst) | ||
| 68 | + endif() | ||
| 69 | + message(STATUS "openfst is downloaded to ${openfst_SOURCE_DIR}") | ||
| 70 | + add_subdirectory(${openfst_SOURCE_DIR} ${openfst_BINARY_DIR} EXCLUDE_FROM_ALL) | ||
| 71 | + set(openfst_SOURCE_DIR ${openfst_SOURCE_DIR} PARENT_SCOPE) | ||
| 72 | + | ||
| 73 | + # Rename libfst.so.6 to libkaldifst_fst.so.6 to avoid potential conflicts | ||
| 74 | + # when kaldifst is installed. | ||
| 75 | + set_target_properties(fst PROPERTIES OUTPUT_NAME "kaldifst_fst") | ||
| 76 | + | ||
| 77 | + install(TARGETS fst | ||
| 78 | + DESTINATION lib | ||
| 79 | + ) | ||
| 80 | + | ||
| 81 | + if(KALDIFST_BUILD_PYTHON) | ||
| 82 | + set_target_properties(fstscript PROPERTIES OUTPUT_NAME "kaldifst_fstscript") | ||
| 83 | + install(TARGETS fstscript | ||
| 84 | + DESTINATION lib | ||
| 85 | + ) | ||
| 86 | + endif() | ||
| 87 | +endfunction() | ||
| 88 | + | ||
| 89 | +download_openfst() |
-
请 注册 或 登录 后发表评论