-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
105 lines (85 loc) · 2.78 KB
/
Copy pathCMakeLists.txt
File metadata and controls
105 lines (85 loc) · 2.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
cmake_minimum_required(VERSION 3.16)
project(asr_cpp VERSION 1.0.0)
# Use GCC-14 for better RISC-V support (commented out for macOS compatibility)
# set(CMAKE_C_COMPILER gcc-14)
# set(CMAKE_CXX_COMPILER g++-14)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
# Set default build type to Release if not specified
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release CACHE STRING "Choose the type of build (Debug/Release/RelWithDebInfo/MinSizeRel)" FORCE)
endif()
# Ensure Release mode has proper optimization flags
if(CMAKE_BUILD_TYPE STREQUAL "Release")
set(CMAKE_CXX_FLAGS_RELEASE "-O3 -DNDEBUG" CACHE STRING "" FORCE)
endif()
# Find required packages
find_package(PkgConfig REQUIRED)
# Find PortAudio
pkg_check_modules(PORTAUDIO REQUIRED portaudio-2.0)
# Find libsndfile
pkg_check_modules(SNDFILE REQUIRED sndfile)
# Find ONNX Runtime
find_path(ONNXRUNTIME_INCLUDE_DIR
NAMES onnxruntime_cxx_api.h
PATHS
/usr/local/include/onnxruntime
/usr/include/onnxruntime
/opt/homebrew/include/onnxruntime
)
find_library(ONNXRUNTIME_LIB
NAMES onnxruntime
PATHS
/usr/local/lib
/usr/lib
/opt/homebrew/lib
)
if(NOT ONNXRUNTIME_INCLUDE_DIR OR NOT ONNXRUNTIME_LIB)
message(FATAL_ERROR "ONNX Runtime not found. Please install ONNX Runtime C++ library.")
endif()
# Find cURL for downloading models
find_package(CURL REQUIRED)
# Find FFTW3
pkg_check_modules(FFTW3 REQUIRED fftw3f)
# Include directories
include_directories(${CMAKE_SOURCE_DIR}/include)
include_directories(${ONNXRUNTIME_INCLUDE_DIR})
include_directories(${PORTAUDIO_INCLUDE_DIRS})
include_directories(${SNDFILE_INCLUDE_DIRS})
include_directories(${FFTW3_INCLUDE_DIRS})
# Source files
set(SOURCES
src/audio_recorder.cpp
src/vad_detector.cpp
src/asr_model.cpp
src/audio_processor.cpp
src/tokenizer.cpp
src/model_downloader.cpp
src/main.cpp
)
# Create executable
add_executable(${PROJECT_NAME} ${SOURCES})
# Link libraries
target_link_libraries(${PROJECT_NAME}
${ONNXRUNTIME_LIB}
${PORTAUDIO_LIBRARIES}
${SNDFILE_LIBRARIES}
${CURL_LIBRARIES}
${FFTW3_LIBRARIES}
pthread
)
# Add library search paths
target_link_directories(${PROJECT_NAME} PRIVATE ${PORTAUDIO_LIBRARY_DIRS})
target_link_directories(${PROJECT_NAME} PRIVATE ${SNDFILE_LIBRARY_DIRS})
target_link_directories(${PROJECT_NAME} PRIVATE ${FFTW3_LIBRARY_DIRS})
# Compiler flags
target_compile_options(${PROJECT_NAME} PRIVATE ${PORTAUDIO_CFLAGS_OTHER})
target_compile_options(${PROJECT_NAME} PRIVATE ${SNDFILE_CFLAGS_OTHER})
# Set output directory
set_target_properties(${PROJECT_NAME} PROPERTIES
RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin
)
# Copy models directory if it exists
if(EXISTS ${CMAKE_SOURCE_DIR}/models)
file(COPY ${CMAKE_SOURCE_DIR}/models DESTINATION ${CMAKE_BINARY_DIR})
endif()