Fangjun Kuang
Committed by GitHub

Test using sherpa-onnx as a cmake subproject (#1961)

  1 +cmake_minimum_required(VERSION 3.13 FATAL_ERROR)
  2 +
  3 +project(use-of-sherpa-onnx-as-a-sub-project)
  4 +
  5 +if(NOT EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/sherpa-onnx/setup.py")
  6 + message(FATAL_ERROR "Please download the source code of sherpa-onnx and put it inside this directory")
  7 +endif()
  8 +
  9 +set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib")
  10 +set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib")
  11 +set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")
  12 +
  13 +include_directories(./sherpa-onnx)
  14 +add_subdirectory(./sherpa-onnx)
  15 +
  16 +add_executable(main main.cc)
  17 +target_link_libraries(main sherpa-onnx-core)
  1 +#include "sherpa-onnx/csrc/offline-recognizer.h"
  2 +#include "sherpa-onnx/csrc/parse-options.h"
  3 +
  4 +int main(int32_t argc, char *argv[]) {
  5 + sherpa_onnx::ParseOptions po("help info");
  6 + sherpa_onnx::OfflineRecognizerConfig config;
  7 + config.Register(&po);
  8 + po.PrintUsage();
  9 + return 0;
  10 +}
  1 +name: as_cmake_sub_project
  2 +
  3 +on:
  4 + push:
  5 + branches:
  6 + - master
  7 + pull_request:
  8 + branches:
  9 + - master
  10 +
  11 + workflow_dispatch:
  12 +
  13 +concurrency:
  14 + group: as-cmake-sub-project-${{ github.ref }}
  15 + cancel-in-progress: true
  16 +
  17 +jobs:
  18 + as_cmake_sub_project:
  19 + name: ${{ matrix.os }} shared ${{ matrix.shared_lib }}
  20 + runs-on: ${{ matrix.os }}
  21 + strategy:
  22 + fail-fast: false
  23 + matrix:
  24 + os: [ubuntu-latest]
  25 + shared_lib: [ON, OFF]
  26 +
  27 + steps:
  28 + - uses: actions/checkout@v4
  29 + with:
  30 + fetch-depth: 0
  31 +
  32 + - name: ccache
  33 + uses: hendrikmuhs/ccache-action@v1.2
  34 + with:
  35 + key: ${{ matrix.os }}-${{ matrix.shared_lib }}-cmake-sub-project
  36 +
  37 + - name: Display PWD
  38 + shell: bash
  39 + run: |
  40 + echo "pwd: $PWD"
  41 + ls -lh
  42 + du -h -d1 .
  43 +
  44 + - name: Build
  45 + shell: bash
  46 + run: |
  47 + mv .github/scripts/as-cmake-sub-project ..
  48 + cd ../as-cmake-sub-project
  49 + ln -s $PWD/../sherpa-onnx .
  50 + mkdir build
  51 + cd build
  52 + cmake -DBUILD_SHARED_LIBS=${{ matrix.shared_lib }} ..
  53 + make -j2 main
  54 +
  55 + - name: Test
  56 + shell: bash
  57 + run: |
  58 + cd ../as-cmake-sub-project
  59 +
  60 + cd build
  61 + ls -lh lib
  62 + echo "----"
  63 + ls -lh bin
  64 +
  65 + readelf -d ./bin/main
  66 + ./bin/main
@@ -322,8 +322,8 @@ if(WIN32 AND MSVC) @@ -322,8 +322,8 @@ if(WIN32 AND MSVC)
322 add_compile_options("$<$<CXX_COMPILER_ID:MSVC>:/utf-8>") 322 add_compile_options("$<$<CXX_COMPILER_ID:MSVC>:/utf-8>")
323 endif() 323 endif()
324 324
325 -list(APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake/Modules)  
326 -list(APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake) 325 +list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules)
  326 +list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
327 327
328 if(SHERPA_ONNX_ENABLE_WASM) 328 if(SHERPA_ONNX_ENABLE_WASM)
329 # Enable it for debugging in case there is something wrong. 329 # Enable it for debugging in case there is something wrong.