Repository navigation
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
225 lines (200 loc) · 9.33 KB
/
Copy pathCMakeLists.txt
File metadata and controls
225 lines (200 loc) · 9.33 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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
cmake_minimum_required(VERSION 3.14...3.28)
project(s2s-ggml LANGUAGES C CXX)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
# version.h: embed git commit hash into all binaries.
# runs on every build, only rewrites if the hash changed.
set(VERSION_OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/version.h")
add_custom_target(version ALL
COMMAND "${CMAKE_COMMAND}" "-DSRC_DIR=${CMAKE_CURRENT_SOURCE_DIR}" "-DOUTPUT=${VERSION_OUTPUT}"
-P "${CMAKE_CURRENT_SOURCE_DIR}/tools/version.cmake"
BYPRODUCTS "${VERSION_OUTPUT}"
COMMENT "Checking git version"
)
# pthread: required explicitly on older glibc (< 2.34) where libpthread
# is not merged into libc.
find_package(Threads REQUIRED)
# Force UTF-8 source and execution charsets so non-ASCII string literals
# (SentencePiece pieces, transcripts in 25 languages) survive the MSVC
# compile without a BOM. Restricted to C and C++ since nvcc treats a bare
# /utf-8 as an input filename.
if(MSVC)
add_compile_definitions(_CRT_SECURE_NO_WARNINGS)
add_compile_options($<$<COMPILE_LANGUAGE:C,CXX>:/utf-8>)
endif()
# Executables and backend .so share the build root so ggml_backend_load_all()
# finds the backends at runtime.
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
# FastConformer GGUF tensor names can exceed the default GGML_MAX_NAME of 64.
add_compile_definitions(GGML_MAX_NAME=128)
# Harden: mark fread/fwrite with warn_unused_result. SYCL excluded since
# _FORTIFY_SOURCE swaps memcpy for __memcpy_chk, unresolved in device code.
if(NOT MSVC AND NOT GGML_SYCL)
add_compile_definitions(_FORTIFY_SOURCE=2)
endif()
# CUDA architectures: Turing to Blackwell for distributed binaries.
# Override with -DCMAKE_CUDA_ARCHITECTURES=native for local builds.
if(NOT DEFINED CMAKE_CUDA_ARCHITECTURES)
find_package(CUDAToolkit QUIET)
if(CUDAToolkit_FOUND AND CUDAToolkit_VERSION VERSION_GREATER_EQUAL "12.8")
set(CMAKE_CUDA_ARCHITECTURES "75-virtual;80-virtual;86-real;89-real;120a-real;121a-real")
else()
set(CMAKE_CUDA_ARCHITECTURES "75-virtual;80-virtual;86-real;89-real")
endif()
endif()
# ggml from GGML_SOURCE_DIR (the submodule by default), inherits GGML_CUDA,
# GGML_METAL, etc. from the cmake flags.
# CUDA graphs default on: standalone ggml ships them off. Overridable with
# -DGGML_CUDA_GRAPHS=OFF or at runtime with GGML_CUDA_DISABLE_GRAPHS=1.
if(NOT DEFINED GGML_CUDA_GRAPHS)
set(GGML_CUDA_GRAPHS_DEFAULT ON)
endif()
set(GGML_SOURCE_DIR "${CMAKE_SOURCE_DIR}/ggml" CACHE PATH "ggml source tree")
add_subdirectory(${GGML_SOURCE_DIR} ggml)
# qwentts.cpp as a submodule: the TTS runs in process through its C ABI.
# Its own CMakeLists builds a standalone project with its own ggml, its own
# vendored httplib and its own tool targets, so the sources are compiled here
# instead: one ggml, one device context, no target name collision. The
# submodule keeps its include directory to itself, ahead of src/, since both
# trees carry a backend.h and a gguf-weights.h of their own.
set(QWENTTS_VERSION_OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/qwentts/version.h")
add_custom_target(qwentts-version ALL
COMMAND "${CMAKE_COMMAND}" "-DSRC_DIR=${CMAKE_CURRENT_SOURCE_DIR}/qwentts.cpp"
"-DOUTPUT=${QWENTTS_VERSION_OUTPUT}" -DMACRO=QWEN_VERSION
-P "${CMAKE_CURRENT_SOURCE_DIR}/tools/version.cmake"
BYPRODUCTS "${QWENTTS_VERSION_OUTPUT}"
COMMENT "Checking qwentts version"
)
add_library(qwen-core STATIC
qwentts.cpp/src/qwen.cpp
qwentts.cpp/src/pipeline-tts.cpp
qwentts.cpp/src/pipeline-codec.cpp
)
target_compile_definitions(qwen-core PUBLIC QWEN_STATIC)
target_include_directories(qwen-core PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/qwentts.cpp/src)
target_include_directories(qwen-core PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/qwentts)
target_include_directories(qwen-core SYSTEM PRIVATE ${GGML_SOURCE_DIR}/include)
target_link_libraries(qwen-core PUBLIC ggml Threads::Threads)
if(TARGET ggml-base)
target_link_libraries(qwen-core PUBLIC ggml-base)
endif()
add_dependencies(qwen-core qwentts-version)
# cpp-httplib: the HTTP and WebSocket server, and the HTTP client of the
# endpoint and the MCP servers.
add_subdirectory(vendor/cpp-httplib)
# yyjson (MIT, fast JSON parser and writer): every JSON the server reads or
# writes.
add_library(yyjson STATIC vendor/yyjson/yyjson.c)
target_include_directories(yyjson PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/vendor/yyjson)
if(MSVC)
target_compile_options(yyjson PRIVATE /W0)
else()
target_compile_options(yyjson PRIVATE -w)
endif()
# Shared compile options and ggml linkage
macro(link_ggml_backends target)
target_include_directories(${target} PRIVATE
${CMAKE_SOURCE_DIR}/src
${CMAKE_SOURCE_DIR}
${CMAKE_BINARY_DIR}
)
target_include_directories(${target} SYSTEM PRIVATE
${GGML_SOURCE_DIR}/include
)
if(MSVC)
target_compile_options(${target} PRIVATE /W4 /wd4100 /wd4505)
else()
target_compile_options(${target} PRIVATE -Wall -Wextra -Wshadow -Wconversion
-Wno-unused-parameter -Wno-unused-function -Wno-sign-conversion)
endif()
target_link_libraries(${target} PRIVATE ggml Threads::Threads)
if(TARGET ggml-base)
target_link_libraries(${target} PRIVATE ggml-base)
endif()
foreach(backend cpu blas cuda metal vulkan sycl)
if(TARGET ggml-${backend})
get_target_property(CURRENT_BACKEND_TYPE ggml-${backend} TYPE)
if (CURRENT_BACKEND_TYPE STREQUAL "MODULE_LIBRARY")
# DL mode: backend is loaded at runtime via dlopen,
# skip all link-time deps.
continue()
endif()
target_link_libraries(${target} PRIVATE ggml-${backend})
endif()
endforeach()
# SYCL links its runtime PRIVATE, consumers need -fsycl to resolve libsycl.so
if(TARGET ggml-sycl AND GGML_SYCL)
target_link_options(${target} PRIVATE -fsycl)
endif()
add_dependencies(${target} version)
endmacro()
# parakeet-core: the recognizer compiled once for every target that
# transcribes. PARAKEET_STATIC keeps the C ABI free of dllimport on Windows,
# the symbols live in the same binary as their callers.
add_library(parakeet-core STATIC src/parakeet.cpp src/pipeline-asr.cpp)
target_compile_definitions(parakeet-core PUBLIC PARAKEET_STATIC)
link_ggml_backends(parakeet-core)
# parakeet-transcribe: audio file to text, plus the stage dump debug path
add_executable(parakeet-transcribe tools/parakeet-transcribe.cpp)
link_ggml_backends(parakeet-transcribe)
target_link_libraries(parakeet-transcribe PRIVATE parakeet-core)
# webui: tools/public/index.html.gz and s2s.js.gz embedded as C headers. The
# .gz are committed so the C++ build works without npm; ./buildwebui.sh
# rebuilds them.
set(WEBUI_INPUT "${CMAKE_CURRENT_SOURCE_DIR}/tools/public/index.html.gz")
set(WEBUI_OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/index.html.gz.hpp")
add_custom_command(
OUTPUT "${WEBUI_OUTPUT}"
COMMAND "${CMAKE_COMMAND}" "-DINPUT=${WEBUI_INPUT}" "-DOUTPUT=${WEBUI_OUTPUT}" -P "${CMAKE_CURRENT_SOURCE_DIR}/tools/xxd.cmake"
DEPENDS "${WEBUI_INPUT}"
COMMENT "Embedding webui into index.html.gz.hpp"
)
set_source_files_properties(${WEBUI_OUTPUT} PROPERTIES GENERATED TRUE)
# s2s.js: the same client as a standalone ES module, embedded next to the page
# and served on /s2s.js for integrators who host their own front end.
set(WEBUI_LIB_INPUT "${CMAKE_CURRENT_SOURCE_DIR}/tools/public/s2s.js.gz")
set(WEBUI_LIB_OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/s2s.js.gz.hpp")
add_custom_command(
OUTPUT "${WEBUI_LIB_OUTPUT}"
COMMAND "${CMAKE_COMMAND}" "-DINPUT=${WEBUI_LIB_INPUT}" "-DOUTPUT=${WEBUI_LIB_OUTPUT}" -P "${CMAKE_CURRENT_SOURCE_DIR}/tools/xxd.cmake"
DEPENDS "${WEBUI_LIB_INPUT}"
COMMENT "Embedding s2s.js into s2s.js.gz.hpp"
)
set_source_files_properties(${WEBUI_LIB_OUTPUT} PROPERTIES GENERATED TRUE)
# s2s-core: the conversation engine and its models, compiled once for every
# host that runs the voice loop.
add_library(s2s-core STATIC
src/s2s-conversation.cpp
src/s2s-session.cpp
src/s2s-models.cpp
src/silero.cpp
src/smart-turn.cpp
src/llm-client.cpp
src/llm-agent.cpp
src/mcp-client.cpp
src/tts-bridge.cpp
src/localvqe.cpp
src/jarvis-fx.cpp)
link_ggml_backends(s2s-core)
target_link_libraries(s2s-core PUBLIC parakeet-core qwen-core httplib yyjson)
# s2s-server: the product, WebSocket voice loop plus the embedded webui
add_executable(s2s-server tools/s2s-server.cpp ${WEBUI_OUTPUT} ${WEBUI_LIB_OUTPUT})
target_include_directories(s2s-server PRIVATE ${CMAKE_CURRENT_BINARY_DIR})
link_ggml_backends(s2s-server)
target_link_libraries(s2s-server PRIVATE s2s-core)
# s2s-cli: the voice loop on the microphone and the loudspeaker of this
# machine. miniaudio (public domain or MIT-0) is header only and loads the
# audio backend of the system at runtime, hence the dl library on Linux.
add_executable(s2s-cli tools/s2s-cli.cpp)
link_ggml_backends(s2s-cli)
target_include_directories(s2s-cli SYSTEM PRIVATE ${CMAKE_SOURCE_DIR}/vendor)
target_link_libraries(s2s-cli PRIVATE s2s-core ${CMAKE_DL_LIBS})
if (APPLE)
# the preferred languages of the system, for the voice under auto
target_link_libraries(s2s-cli PRIVATE "-framework CoreFoundation")
endif()
# quantize: GGUF requantizer (F32 -> K-quants)
add_executable(quantize tools/quantize.cpp)
link_ggml_backends(quantize)
add_subdirectory(tests)