-
Notifications
You must be signed in to change notification settings - Fork 74
/
CMakeLists.txt
235 lines (189 loc) · 6.62 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
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
cmake_minimum_required(VERSION 3.14)
set(CMAKE_VERBOSE_MAKEFILE off)
project(
piper_phonemize
VERSION 1.2.0
DESCRIPTION "Phonemization library for Piper text to speech system"
HOMEPAGE_URL "https://github.com/rhasspy/piper-phonemize"
LANGUAGES CXX
)
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_library(
piper_phonemize SHARED
src/phonemize.cpp
src/phoneme_ids.cpp
src/tashkeel.cpp
src/shared.cpp
)
set_target_properties(piper_phonemize PROPERTIES
VERSION ${PROJECT_VERSION}
SOVERSION ${PROJECT_VERSION_MAJOR}
)
# ---- onnxruntime ---
# Look for onnxruntime files in <root>/lib
if(NOT DEFINED ONNXRUNTIME_DIR)
if(NOT DEFINED ONNXRUNTIME_VERSION)
set(ONNXRUNTIME_VERSION "1.14.1")
endif()
if(WIN32)
# Windows x86-64
set(ONNXRUNTIME_PREFIX "onnxruntime-win-x64-${ONNXRUNTIME_VERSION}")
set(ONNXRUNTIME_EXT "zip")
elseif (APPLE)
if(CMAKE_SYSTEM_PROCESSOR STREQUAL x86_64)
# MacOS x86-64
set(ONNXRUNTIME_PREFIX "onnxruntime-osx-x86_64-${ONNXRUNTIME_VERSION}")
elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL arm64)
# MacOS Apple Silicon
set(ONNXRUNTIME_PREFIX "onnxruntime-osx-arm64-${ONNXRUNTIME_VERSION}")
else()
message(FATAL_ERROR "Unsupported architecture for onnxruntime")
endif()
set(ONNXRUNTIME_EXT "tgz")
else()
if(CMAKE_SYSTEM_PROCESSOR STREQUAL x86_64)
# Linux x86-64
set(ONNXRUNTIME_PREFIX "onnxruntime-linux-x64-${ONNXRUNTIME_VERSION}")
elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL aarch64)
# Linux ARM 64-bit
set(ONNXRUNTIME_PREFIX "onnxruntime-linux-aarch64-${ONNXRUNTIME_VERSION}")
elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL armv7l)
# Linux ARM 32-bit
set(ONNXRUNTIME_PREFIX "onnxruntime-linux-arm32-${ONNXRUNTIME_VERSION}")
set(ONNXRUNTIME_URL "https://github.com/synesthesiam/prebuilt-apps/releases/download/v1.0/onnxruntime-linux-arm32-${ONNXRUNTIME_VERSION}.tgz")
else()
message(FATAL_ERROR "Unsupported architecture for onnxruntime")
endif()
set(ONNXRUNTIME_EXT "tgz")
endif()
if(NOT DEFINED ONNXRUNTIME_URL)
set(ONNXRUNTIME_URL "https://github.com/microsoft/onnxruntime/releases/download/v${ONNXRUNTIME_VERSION}/${ONNXRUNTIME_PREFIX}.${ONNXRUNTIME_EXT}")
endif()
set(ONNXRUNTIME_FILENAME "${ONNXRUNTIME_PREFIX}.${ONNXRUNTIME_EXT}")
set(ONNXRUNTIME_DIR "${CMAKE_CURRENT_LIST_DIR}/lib/${ONNXRUNTIME_PREFIX}")
if(NOT EXISTS "${ONNXRUNTIME_DIR}")
if(NOT EXISTS "download/${ONNXRUNTIME_FILENAME}")
# Download onnxruntime release
message("Downloading ${ONNXRUNTIME_URL}")
file(DOWNLOAD "${ONNXRUNTIME_URL}" "download/${ONNXRUNTIME_FILENAME}")
endif()
# Extract .zip or .tgz to a directory like lib/onnxruntime-linux-x64-1.14.1/
file(ARCHIVE_EXTRACT INPUT "download/${ONNXRUNTIME_FILENAME}" DESTINATION "${CMAKE_CURRENT_LIST_DIR}/lib")
endif()
endif()
# ---- espeak-ng ---
if(NOT DEFINED ESPEAK_NG_DIR)
set(ESPEAK_NG_DIR "${CMAKE_CURRENT_BINARY_DIR}/ei")
include(ExternalProject)
ExternalProject_Add(
espeak_ng_external
PREFIX "${CMAKE_CURRENT_BINARY_DIR}/e"
URL "https://github.com/rhasspy/espeak-ng/archive/0f65aa301e0d6bae5e172cc74197d32a6182200f.zip"
CMAKE_ARGS -DCMAKE_INSTALL_PREFIX:PATH=${ESPEAK_NG_DIR}
CMAKE_ARGS -DUSE_ASYNC:BOOL=OFF
CMAKE_ARGS -DBUILD_SHARED_LIBS:BOOL=ON
CMAKE_ARGS -DUSE_MBROLA:BOOL=OFF
CMAKE_ARGS -DUSE_LIBSONIC:BOOL=OFF
CMAKE_ARGS -DUSE_LIBPCAUDIO:BOOL=OFF
CMAKE_ARGS -DUSE_KLATT:BOOL=OFF
CMAKE_ARGS -DUSE_SPEECHPLAYER:BOOL=OFF
CMAKE_ARGS -DEXTRA_cmn:BOOL=ON
CMAKE_ARGS -DEXTRA_ru:BOOL=ON
CMAKE_ARGS -DCMAKE_C_FLAGS="-D_FILE_OFFSET_BITS=64"
)
add_dependencies(piper_phonemize espeak_ng_external)
endif()
# ---- Declare library ----
target_include_directories(
piper_phonemize PUBLIC
"$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/src>"
${ESPEAK_NG_DIR}/include
${ONNXRUNTIME_DIR}/include
)
target_link_directories(
piper_phonemize PUBLIC
${ESPEAK_NG_DIR}/lib
${ONNXRUNTIME_DIR}/lib
)
target_link_libraries(
piper_phonemize
espeak-ng
onnxruntime
)
target_compile_features(piper_phonemize PUBLIC cxx_std_17)
# ---- Declare executable ----
add_executable(piper_phonemize_exe src/main.cpp src/phoneme_ids.cpp)
if(NOT WIN32)
set_property(TARGET piper_phonemize_exe PROPERTY OUTPUT_NAME piper_phonemize)
endif()
target_compile_features(piper_phonemize_exe PUBLIC cxx_std_17)
target_include_directories(
piper_phonemize_exe PUBLIC
"$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/src>"
${ESPEAK_NG_DIR}/include
)
target_link_directories(
piper_phonemize_exe PUBLIC
${ESPEAK_NG_DIR}/lib
)
target_link_libraries(piper_phonemize_exe PUBLIC
piper_phonemize
espeak-ng
)
# ---- Declare test ----
include(CTest)
enable_testing()
add_executable(test_piper_phonemize src/test.cpp src/phoneme_ids.cpp)
add_test(
NAME test_piper_phonemize
COMMAND test_piper_phonemize "${ESPEAK_NG_DIR}/share/espeak-ng-data" "${CMAKE_SOURCE_DIR}/etc/libtashkeel_model.ort"
)
target_compile_features(test_piper_phonemize PUBLIC cxx_std_17)
target_include_directories(
test_piper_phonemize PUBLIC
"$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/src>"
${ESPEAK_NG_DIR}/include
)
target_link_directories(
test_piper_phonemize PUBLIC
${ESPEAK_NG_DIR}/lib
)
target_link_libraries(test_piper_phonemize PUBLIC
piper_phonemize
espeak-ng
)
# ---- Declare install targets ----
include(GNUInstallDirs)
install(
TARGETS piper_phonemize
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR})
install(
DIRECTORY ${CMAKE_SOURCE_DIR}/src/
DESTINATION include/piper-phonemize
FILES_MATCHING
PATTERN "*.h"
PATTERN "*.hpp")
install(
TARGETS piper_phonemize_exe
ARCHIVE DESTINATION ${CMAKE_INSTALL_BINDIR})
install(
FILES ${CMAKE_SOURCE_DIR}/etc/libtashkeel_model.ort
TYPE DATA)
# Dependencies
install(
DIRECTORY ${ESPEAK_NG_DIR}/
DESTINATION ${CMAKE_INSTALL_PREFIX})
install(
DIRECTORY ${ONNXRUNTIME_DIR}/include/
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
install(
DIRECTORY ${ONNXRUNTIME_DIR}/lib/
DESTINATION ${CMAKE_INSTALL_LIBDIR})