Skip to content

Commit

Permalink
Add MFC example (#249)
Browse files Browse the repository at this point in the history
  • Loading branch information
csukuangfj authored Aug 4, 2023
1 parent 77c34f3 commit 80888d8
Show file tree
Hide file tree
Showing 20 changed files with 1,689 additions and 1 deletion.
138 changes: 138 additions & 0 deletions .github/workflows/mfc.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
name: mfc

on:
push:
branches:
- master
tags:
- '*'
paths:
- '.github/workflows/mfc.yaml'
- 'CMakeLists.txt'
- 'cmake/**'
- 'mfc-examples/**'
- 'sherpa-ncnn/csrc/*'
- 'sherpa-ncnn/c-api/*'
pull_request:
branches:
- master
paths:
- '.github/workflows/mfc.yaml'
- 'CMakeLists.txt'
- 'cmake/**'
- 'mfc-examples/**'
- 'sherpa-ncnn/csrc/*'
- 'sherpa-ncnn/c-api/*'
release:
types:
- published

workflow_dispatch:
inputs:
release:
description: "Whether to release"
type: boolean

env:
RELEASE:
|- # Release if there is a release tag name or a release flag in workflow_dispatch
${{ github.event.release.tag_name != '' || github.event.inputs.release == 'true' }}

concurrency:
group: mfc-${{ github.ref }}
cancel-in-progress: true

jobs:
mfc:
name: MFC for ${{ matrix.arch }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [windows-latest]
arch: [x64, Win32]

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

- name: Display MSBuild info
shell: cmd
run: |
set path="C:\Program Files\Microsoft Visual Studio\2022\Enterprise\MSBuild\Current\Bin"
msbuild -help
- name: Configure CMake
shell: bash
run: |
mkdir build
cd build
cmake -A ${{ matrix.arch }} -D CMAKE_BUILD_TYPE=Release -D BUILD_SHARED_LIBS=OFF -DCMAKE_INSTALL_PREFIX=./install ..
- name: Build sherpa-ncnn for windows ${{ matrix.arch }}
shell: bash
run: |
cd build
cmake --build . --config Release -- -m:2
cmake --build . --config Release --target install -- -m:2
ls -lh install/*
ls -lh install/lib
ls -lh install/bin
- name: Build MFC
if: matrix.arch == 'x64'
shell: cmd
run: |
set path="C:\Program Files\Microsoft Visual Studio\2022\Enterprise\MSBuild\Current\Bin"
cd mfc-examples
msbuild .\mfc-examples.sln /property:Configuration=Release /property:Platform=x64
- name: Build MFC
if: matrix.arch == 'Win32'
shell: cmd
run: |
set path="C:\Program Files\Microsoft Visual Studio\2022\Enterprise\MSBuild\Current\Bin"
cd mfc-examples
msbuild .\mfc-examples.sln /property:Configuration=Release /property:Platform=x86
- name: Copy files
shell: bash
run: |
SHERPA_NCNN_VERSION=v$(grep "SHERPA_NCNN_VERSION" ./CMakeLists.txt | cut -d " " -f 2 | cut -d '"' -f 2)
arch=${{ matrix.arch }}
d=$PWD
ls -lh mfc-examples
ls -lh mfc-examples/*
if [[ $arch == 'x64' ]]; then
cd mfc-examples/$arch/Release
cp RealtimeSpeechRecognition.exe $d/sherpa-ncnn-x64-${SHERPA_NCNN_VERSION}.exe
else
cd mfc-examples/Release
cp RealtimeSpeechRecognition.exe $d/sherpa-ncnn-x86-${SHERPA_NCNN_VERSION}.exe
fi
ls -lh
ls -lh $d/
- name: Upload artifact
uses: actions/upload-artifact@v2
with:
name: sherpa-ncnn-${{ matrix.arch }}
path: ./sherpa-ncnn*.exe

- name: Release pre-compiled binaries for Windows ${{ matrix.arch }}
if: env.RELEASE == 'true'
uses: svenstaro/upload-release-action@v2
with:
file_glob: true
overwrite: true
file: ./sherpa-ncnn*.exe
15 changes: 14 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
cmake_minimum_required(VERSION 3.13 FATAL_ERROR)
project(sherpa-ncnn)

set(SHERPA_NCNN_VERSION "2.0.4")
set(SHERPA_NCNN_VERSION "2.0.5")

# Disable warning about
#
Expand Down Expand Up @@ -53,6 +53,19 @@ endif()
if(BUILD_SHARED_LIBS AND MSVC)
set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON)
endif()

if(NOT BUILD_SHARED_LIBS AND MSVC)
# see https://cmake.org/cmake/help/latest/prop_tgt/MSVC_RUNTIME_LIBRARY.html
# https://stackoverflow.com/questions/14172856/compile-with-mt-instead-of-md-using-cmake
if(MSVC)
add_compile_options(
$<$<CONFIG:>:/MT> #---------|
$<$<CONFIG:Debug>:/MTd> #---|-- Statically link the runtime libraries
$<$<CONFIG:Release>:/MT> #--|
)
endif()
endif()

message(STATUS "CMAKE_EXPORT_COMPILE_COMMANDS: ${CMAKE_EXPORT_COMPILE_COMMANDS}")
message(STATUS "BUILD_SHARED_LIBS ${BUILD_SHARED_LIBS}")
message(STATUS "SHERPA_NCNN_ENABLE_PYTHON ${SHERPA_NCNN_ENABLE_PYTHON}")
Expand Down
17 changes: 17 additions & 0 deletions cmake/portaudio.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,23 @@ function(download_portaudio)
endif()

add_subdirectory(${portaudio_SOURCE_DIR} ${portaudio_BINARY_DIR} EXCLUDE_FROM_ALL)

if(BUILD_SHARED_LIBS)
set_target_properties(portaudio PROPERTIES OUTPUT_NAME "sherpa-ncnn-portaudio")

if(SHERPA_NCNN_ENABLE_PYTHON AND WIN32)
install(TARGETS portaudio DESTINATION ..)
else()
install(TARGETS portaudio DESTINATION lib)
endif()
else()
set_target_properties(portaudio_static PROPERTIES OUTPUT_NAME "sherpa-ncnn-portaudio_static")
if(SHERPA_NCNN_ENABLE_PYTHON AND WIN32)
install(TARGETS portaudio_static DESTINATION ..)
else()
install(TARGETS portaudio_static DESTINATION lib)
endif()
endif()
endfunction()

download_portaudio()
Expand Down
Loading

0 comments on commit 80888d8

Please sign in to comment.