|
| 1 | +function(download_simple_sentencepiece) |
| 2 | + include(FetchContent) |
| 3 | + |
| 4 | + set(simple-sentencepiece_URL "https://github.com/pkufool/simple-sentencepiece/archive/refs/tags/v0.7.tar.gz") |
| 5 | + set(simple-sentencepiece_URL2 "https://hub.nauu.cf/pkufool/simple-sentencepiece/archive/refs/tags/v0.7.tar.gz") |
| 6 | + set(simple-sentencepiece_HASH "SHA256=1748a822060a35baa9f6609f84efc8eb54dc0e74b9ece3d82367b7119fdc75af") |
| 7 | + |
| 8 | + # If you don't have access to the Internet, |
| 9 | + # please pre-download simple-sentencepiece |
| 10 | + set(possible_file_locations |
| 11 | + $ENV{HOME}/Downloads/simple-sentencepiece-0.7.tar.gz |
| 12 | + ${CMAKE_SOURCE_DIR}/simple-sentencepiece-0.7.tar.gz |
| 13 | + ${CMAKE_BINARY_DIR}/simple-sentencepiece-0.7.tar.gz |
| 14 | + /tmp/simple-sentencepiece-0.7.tar.gz |
| 15 | + /star-fj/fangjun/download/github/simple-sentencepiece-0.7.tar.gz |
| 16 | + ) |
| 17 | + |
| 18 | + foreach(f IN LISTS possible_file_locations) |
| 19 | + if(EXISTS ${f}) |
| 20 | + set(simple-sentencepiece_URL "${f}") |
| 21 | + file(TO_CMAKE_PATH "${simple-sentencepiece_URL}" simple-sentencepiece_URL) |
| 22 | + message(STATUS "Found local downloaded simple-sentencepiece: ${simple-sentencepiece_URL}") |
| 23 | + set(simple-sentencepiece_URL2) |
| 24 | + break() |
| 25 | + endif() |
| 26 | + endforeach() |
| 27 | + |
| 28 | + set(SBPE_ENABLE_TESTS OFF CACHE BOOL "" FORCE) |
| 29 | + set(SBPE_BUILD_PYTHON OFF CACHE BOOL "" FORCE) |
| 30 | + |
| 31 | + FetchContent_Declare(simple-sentencepiece |
| 32 | + URL |
| 33 | + ${simple-sentencepiece_URL} |
| 34 | + ${simple-sentencepiece_URL2} |
| 35 | + URL_HASH |
| 36 | + ${simple-sentencepiece_HASH} |
| 37 | + ) |
| 38 | + |
| 39 | + FetchContent_GetProperties(simple-sentencepiece) |
| 40 | + if(NOT simple-sentencepiece_POPULATED) |
| 41 | + message(STATUS "Downloading simple-sentencepiece ${simple-sentencepiece_URL}") |
| 42 | + FetchContent_Populate(simple-sentencepiece) |
| 43 | + endif() |
| 44 | + message(STATUS "simple-sentencepiece is downloaded to ${simple-sentencepiece_SOURCE_DIR}") |
| 45 | + add_subdirectory(${simple-sentencepiece_SOURCE_DIR} ${simple-sentencepiece_BINARY_DIR} EXCLUDE_FROM_ALL) |
| 46 | + |
| 47 | + target_include_directories(ssentencepiece_core |
| 48 | + PUBLIC |
| 49 | + ${simple-sentencepiece_SOURCE_DIR}/ |
| 50 | + ) |
| 51 | + |
| 52 | + if(SHERPA_ONNX_ENABLE_PYTHON AND WIN32) |
| 53 | + install(TARGETS ssentencepiece_core DESTINATION ..) |
| 54 | + else() |
| 55 | + install(TARGETS ssentencepiece_core DESTINATION lib) |
| 56 | + endif() |
| 57 | + |
| 58 | + if(WIN32 AND BUILD_SHARED_LIBS) |
| 59 | + install(TARGETS ssentencepiece_core DESTINATION bin) |
| 60 | + endif() |
| 61 | +endfunction() |
| 62 | + |
| 63 | +download_simple_sentencepiece() |
0 commit comments