Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test using sherpa-onnx as a cmake subproject #1961

Merged
merged 1 commit into from
Mar 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions .github/scripts/as-cmake-sub-project/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
cmake_minimum_required(VERSION 3.13 FATAL_ERROR)

project(use-of-sherpa-onnx-as-a-sub-project)

if(NOT EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/sherpa-onnx/setup.py")
message(FATAL_ERROR "Please download the source code of sherpa-onnx and put it inside this directory")
endif()

set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib")
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib")
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")

include_directories(./sherpa-onnx)
add_subdirectory(./sherpa-onnx)

add_executable(main main.cc)
target_link_libraries(main sherpa-onnx-core)
10 changes: 10 additions & 0 deletions .github/scripts/as-cmake-sub-project/main.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#include "sherpa-onnx/csrc/offline-recognizer.h"
#include "sherpa-onnx/csrc/parse-options.h"

int main(int32_t argc, char *argv[]) {
sherpa_onnx::ParseOptions po("help info");
sherpa_onnx::OfflineRecognizerConfig config;
config.Register(&po);
po.PrintUsage();
return 0;
}
66 changes: 66 additions & 0 deletions .github/workflows/as_cmake_sub_project.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
name: as_cmake_sub_project

on:
push:
branches:
- master
pull_request:
branches:
- master

workflow_dispatch:

concurrency:
group: as-cmake-sub-project-${{ github.ref }}
cancel-in-progress: true

jobs:
as_cmake_sub_project:
name: ${{ matrix.os }} shared ${{ matrix.shared_lib }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest]
shared_lib: [ON, OFF]

steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0

- name: ccache
uses: hendrikmuhs/ccache-action@v1.2
with:
key: ${{ matrix.os }}-${{ matrix.shared_lib }}-cmake-sub-project

- name: Display PWD
shell: bash
run: |
echo "pwd: $PWD"
ls -lh
du -h -d1 .

- name: Build
shell: bash
run: |
mv .github/scripts/as-cmake-sub-project ..
cd ../as-cmake-sub-project
ln -s $PWD/../sherpa-onnx .
mkdir build
cd build
cmake -DBUILD_SHARED_LIBS=${{ matrix.shared_lib }} ..
make -j2 main

- name: Test
shell: bash
run: |
cd ../as-cmake-sub-project

cd build
ls -lh lib
echo "----"
ls -lh bin

readelf -d ./bin/main
./bin/main
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -322,8 +322,8 @@ if(WIN32 AND MSVC)
add_compile_options("$<$<CXX_COMPILER_ID:MSVC>:/utf-8>")
endif()

list(APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake/Modules)
list(APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake)
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules)
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake)

if(SHERPA_ONNX_ENABLE_WASM)
# Enable it for debugging in case there is something wrong.
Expand Down
Loading