forked from mrtrizer/piper
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
214 lines (175 loc) · 5.16 KB
/
CMakeLists.txt
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
cmake_minimum_required(VERSION 3.13)
project(piper C CXX)
file(READ "${CMAKE_CURRENT_LIST_DIR}/VERSION" piper_version)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
if(MSVC)
# Force compiler to use UTF-8 for IPA constants
add_compile_options("$<$<C_COMPILER_ID:MSVC>:/utf-8>")
add_compile_options("$<$<CXX_COMPILER_ID:MSVC>:/utf-8>")
elseif(NOT APPLE)
# Linux flags
string(APPEND CMAKE_CXX_FLAGS " -Wall -Wextra -Wl,-rpath,'$ORIGIN'")
string(APPEND CMAKE_C_FLAGS " -Wall -Wextra")
endif()
add_executable(piper src/cpp/main.cpp src/cpp/piper.cpp)
add_executable(test_piper src/cpp/test.cpp src/cpp/piper.cpp)
add_library(piperlib SHARED src/cpp/piperlib.cpp src/cpp/piper.cpp)
# NOTE: external project prefix are shortened because of path length restrictions on Windows
# NOTE: onnxruntime is pulled from piper-phonemize
# ---- fmt ---
if(NOT DEFINED FMT_DIR)
set(FMT_VERSION "10.0.0")
set(FMT_DIR "${CMAKE_CURRENT_BINARY_DIR}/fi")
include(ExternalProject)
ExternalProject_Add(
fmt_external
PREFIX "${CMAKE_CURRENT_BINARY_DIR}/f"
URL "https://github.com/fmtlib/fmt/archive/refs/tags/${FMT_VERSION}.zip"
CMAKE_ARGS -DCMAKE_INSTALL_PREFIX:PATH=${FMT_DIR}
CMAKE_ARGS -DFMT_TEST:BOOL=OFF # Don't build all the tests
)
add_dependencies(piper fmt_external)
add_dependencies(test_piper fmt_external)
add_dependencies(piperlib fmt_external)
endif()
# ---- spdlog ---
if(NOT DEFINED SPDLOG_DIR)
set(SPDLOG_DIR "${CMAKE_CURRENT_BINARY_DIR}/si")
set(SPDLOG_VERSION "1.12.0")
ExternalProject_Add(
spdlog_external
PREFIX "${CMAKE_CURRENT_BINARY_DIR}/s"
URL "https://github.com/gabime/spdlog/archive/refs/tags/v${SPDLOG_VERSION}.zip"
CMAKE_ARGS -DCMAKE_INSTALL_PREFIX:PATH=${SPDLOG_DIR} -DCMAKE_BUILD_TYPE=Release
)
add_dependencies(piper spdlog_external)
add_dependencies(test_piper spdlog_external)
add_dependencies(piperlib spdlog_external)
endif()
# ---- piper-phonemize ---
if(NOT DEFINED PIPER_PHONEMIZE_DIR)
set(PIPER_PHONEMIZE_DIR "${CMAKE_CURRENT_BINARY_DIR}/pi")
ExternalProject_Add(
piper_phonemize_external
PREFIX "${CMAKE_CURRENT_BINARY_DIR}/p"
URL "https://github.com/rhasspy/piper-phonemize/archive/refs/heads/master.zip"
CMAKE_ARGS -DCMAKE_INSTALL_PREFIX:PATH=${PIPER_PHONEMIZE_DIR}
)
add_dependencies(piper piper_phonemize_external)
add_dependencies(test_piper piper_phonemize_external)
add_dependencies(piperlib piper_phonemize_external)
endif()
# ---- Declare executable ----
if((NOT MSVC) AND (NOT APPLE))
# Linux flags
string(APPEND CMAKE_CXX_FLAGS " -Wall -Wextra -Wl,-rpath,'$ORIGIN'")
string(APPEND CMAKE_C_FLAGS " -Wall -Wextra")
target_link_libraries(piper -static-libgcc -static-libstdc++)
set(PIPER_EXTRA_LIBRARIES "pthread")
endif()
target_link_libraries(piper
fmt
spdlog
espeak-ng
piper_phonemize
onnxruntime
${PIPER_EXTRA_LIBRARIES}
)
target_link_directories(piper PUBLIC
${FMT_DIR}/lib
${SPDLOG_DIR}/lib
${PIPER_PHONEMIZE_DIR}/lib
)
target_include_directories(piper PUBLIC
${FMT_DIR}/include
${SPDLOG_DIR}/include
${PIPER_PHONEMIZE_DIR}/include
)
target_compile_definitions(piper PUBLIC _PIPER_VERSION=${piper_version})
# ---- Declare library ----
if((NOT MSVC) AND (NOT APPLE))
# Linux flags
string(APPEND CMAKE_CXX_FLAGS " -Wall -Wextra -Wl,-rpath,'$ORIGIN'")
string(APPEND CMAKE_C_FLAGS " -Wall -Wextra")
target_link_libraries(piperlib -static-libgcc -static-libstdc++)
set(PIPER_EXTRA_LIBRARIES "pthread")
endif()
target_link_libraries(piperlib
fmt
spdlog
espeak-ng
piper_phonemize
onnxruntime
${PIPER_EXTRA_LIBRARIES}
)
target_link_directories(piperlib PUBLIC
${FMT_DIR}/lib
${SPDLOG_DIR}/lib
${PIPER_PHONEMIZE_DIR}/lib
)
target_include_directories(piperlib PUBLIC
${FMT_DIR}/include
${SPDLOG_DIR}/include
${PIPER_PHONEMIZE_DIR}/include
)
# ---- Declare test ----
include(CTest)
enable_testing()
add_test(
NAME test_piper
COMMAND test_piper "${CMAKE_SOURCE_DIR}/etc/test_voice.onnx" "${PIPER_PHONEMIZE_DIR}/share/espeak-ng-data" "${CMAKE_CURRENT_BINARY_DIR}/test.wav"
)
target_compile_features(test_piper PUBLIC cxx_std_17)
target_include_directories(
test_piper PUBLIC
${FMT_DIR}/include
${SPDLOG_DIR}/include
${PIPER_PHONEMIZE_DIR}/include
)
target_link_directories(
test_piper PUBLIC
${FMT_DIR}/lib
${SPDLOG_DIR}/lib
${PIPER_PHONEMIZE_DIR}/lib
)
target_link_libraries(test_piper PUBLIC
fmt
spdlog
espeak-ng
piper_phonemize
onnxruntime
)
# ---- Declare install targets ----
install(
TARGETS piper
DESTINATION ${CMAKE_INSTALL_PREFIX})
# Dependencies
install(
DIRECTORY ${PIPER_PHONEMIZE_DIR}/bin/
DESTINATION ${CMAKE_INSTALL_PREFIX}
USE_SOURCE_PERMISSIONS # keep +x
FILES_MATCHING
PATTERN "piper_phonemize"
PATTERN "espeak-ng"
PATTERN "*.dll"
)
install(
DIRECTORY ${PIPER_PHONEMIZE_DIR}/lib/
DESTINATION ${CMAKE_INSTALL_PREFIX}
FILES_MATCHING
PATTERN "*.dll"
PATTERN "*.so*"
)
install(
DIRECTORY ${PIPER_PHONEMIZE_DIR}/share/espeak-ng-data
DESTINATION ${CMAKE_INSTALL_PREFIX}
)
install(
FILES ${PIPER_PHONEMIZE_DIR}/share/libtashkeel_model.ort
DESTINATION ${CMAKE_INSTALL_PREFIX}
)
install(
TARGETS piperlib
LIBRARY DESTINATION ${CMAKE_INSTALL_PREFIX}
)