-
Notifications
You must be signed in to change notification settings - Fork 4
/
CMakeLists.txt
204 lines (177 loc) · 8.09 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
cmake_minimum_required(VERSION 3.25)
project(MeloTTS)
# Set C++ Standard
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED True)
# for env witout setting utf-8 for Chinese
if(WIN32)
add_compile_options("$<$<CXX_COMPILER_ID:MSVC>:/utf-8>") #https://learn.microsoft.com/en-us/cpp/build/reference/utf-8-set-source-and-executable-character-sets-to-utf-8?view=msvc-170
#add_compile_options("$<$<CXX_COMPILER_ID:MSVC>:/source-charset:utf-8>")
add_compile_options("$<$<CXX_COMPILER_ID:MSVC>:/bigobj>")
endif()
if(WIN32) #default compiler on win is msvc. I've not verifed it with clang-cl yet.
add_definitions(-DNOMINMAX) # Otherwise, std::max() and std::min() won't work
add_compile_options(/Zc:__cplusplus) # Add /Zc:__cplusplus flag for Visual Studio to properly set the __cplusplus macro
set(CMAKE_CONFIGURATION_TYPES "Debug;Release" CACHE STRING "Choose the configuration types" FORCE)
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>DLL") # refer to https://developercommunity.visualstudio.com/t/debug-build-works-but-release-build-failsas-well-a/428160
endif()
# Workaround for an MSVC compiler issue in some versions of Visual Studio 2022.
# The issue involves a null dereference to a mutex. For details, refer to link https://github.com/microsoft/STL/wiki/Changelog#vs-2022-1710
if(MSVC AND MSVC_VERSION GREATER_EQUAL 1930 AND MSVC_VERSION LESS 1941)
add_compile_definitions(_DISABLE_CONSTEXPR_MUTEX_CONSTRUCTOR)
endif()
find_package(OpenVINO REQUIRED COMPONENTS Runtime)
# Include directories
include_directories(${CMAKE_SOURCE_DIR}/src)
# Source files
set(SOURCE_FILES
melo.cpp
src/openvino_model_base.cpp
src/tokenizer.cpp
src/utils.cpp
src/bert.cpp
src/openvoice_tts.cpp
src/tts.cpp
src/language_modules/cmudict.cpp
src/language_modules/chinese_mix.cpp
src/language_modules/tone_sandhi.cpp
src/text_normalization/text_normalization.cpp
src/text_normalization/char_convert.cpp
src/text_normalization/chronology.cpp
src/text_normalization/constants.cpp
src/text_normalization/num.cpp
src/text_normalization/phonecode.cpp
src/text_normalization/quantifier.cpp
${CMAKE_SOURCE_DIR}/thirdParty/cppinyin/csrc/cppinyin.cc
${CMAKE_SOURCE_DIR}/thirdParty/cppinyin/csrc/cppinyin_csrc_utils.cc
src/text_normalization/text_normalization.cpp
src/text_normalization/char_convert.cpp
src/text_normalization/chronology.cpp
src/text_normalization/constants.cpp
src/text_normalization/num.cpp
src/text_normalization/phonecode.cpp
src/text_normalization/quantifier.cpp
src/deepfilternet/noisefilter.cpp
src/deepfilternet/deepfilter.cpp
src/deepfilternet/dfnet_model.cpp
src/deepfilternet/multiframe.cpp
${CMAKE_CURRENT_SOURCE_DIR}/thirdParty/cppinyin/csrc/cppinyin.cc
${CMAKE_CURRENT_SOURCE_DIR}/thirdParty/cppinyin/csrc/cppinyin_csrc_utils.cc
)
# Header files
set(HEADER_FILES
src/parse_args.h
src/openvino_model_base.h
src/info_data.h
src/tokenizer.h
src/utils.h
src/bert.h
src/openvoice_tts.h
src/tts.h
src/language_modules/cmudict.h
src/language_modules/chinese_mix.h
src/language_modules/tone_sandhi.h
src/text_normalization/text_normalization.h
src/text_normalization/char_convert.h
src/text_normalization/chronology.h
src/text_normalization/constant.h
src/text_normalization/number.h
src/text_normalization/phonecode.h
src/text_normalization/quantifier.h
${CMAKE_SOURCE_DIR}/thirdParty/cppinyin/csrc/cppinyin.h
${CMAKE_SOURCE_DIR}/thirdParty/cppinyin/csrc/cppinyin_csrc_utils.h
src/deepfilternet/noisefilter.h
src/deepfilternet/deepfilter.h
src/deepfilternet/multiframe.h
src/deepfilternet/dfnet_model.h
${CMAKE_CURRENT_SOURCE_DIR}/thirdParty/cppinyin/csrc/cppinyin.h
${CMAKE_CURRENT_SOURCE_DIR}/thirdParty/cppinyin/csrc/cppinyin_csrc_utils.h
)
include_directories(${CMAKE_SOURCE_DIR}/thirdParty/eigen)
# Define the executable
add_executable(meloTTS_ov ${SOURCE_FILES} ${HEADER_FILES})
# Whether use deep filter net; We do not support this feature on Linux now.
if(NOT DEFINED USE_DEEPFILTERNET AND WIN32)
set(USE_DEEPFILTERNET ON)
message(STATUS "DeepFilterNet is enabled")
elseif(UNIX OR NOT USE_DEEPFILTERNET)
set(USE_DEEPFILTERNET OFF)
message(STATUS "DeepFilterNet is disabled")
endif()
if(USE_DEEPFILTERNET)
add_compile_definitions(USE_DEEPFILTERNET)
# unzip libtorch
set(LIBTORCH_DIR ${CMAKE_SOURCE_DIR}/thirdParty/libtorch)
if(NOT EXISTS ${LIBTORCH_DIR})
message(STATUS "libtorch directory does not exist, will perform unzip.")
add_custom_target(unZip ALL)
execute_process(
COMMAND ${CMAKE_COMMAND} -E tar xzf libtorch.tar.gz
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/thirdParty
)
else()
message(STATUS "libtorch folder already exists, skipping unzip.")
endif()
# COPY torch runtime to exe folder
set(RELEASE_DIR ${CMAKE_BINARY_DIR}/Release)
#set(DEBUG_DIR ${CMAKE_BINARY_DIR}/Debug)
file(MAKE_DIRECTORY ${RELEASE_DIR})
set(DLLS torch.dll torch_cpu.dll asmjit.dll fbgemm.dll c10.dll uv.dll libiomp5md.dll)
foreach(dll ${DLLS})
message("Copying ${dll} from ${LIBTORCH_DIR}/lib to ${RELEASE_DIR} and ${DEBUG_DIR}")
execute_process(
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${LIBTORCH_DIR}/lib/${dll} ${RELEASE_DIR}
#COMMAND ${CMAKE_COMMAND} -E copy_if_different ${LIBTORCH_DIR}/lib/${dll} ${DEBUG_DIR}
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
)
endforeach()
# Find libraries
find_library(TORCH_LIB torch PATHS ${LIBTORCH_DIR}/lib)
if (NOT TORCH_LIB)
message(FATAL_ERROR "torch.lib not found")
endif()
find_library(C10_LIB c10 PATHS ${LIBTORCH_DIR}/lib)
if (NOT C10_LIB)
message(FATAL_ERROR "c10.lib not found")
endif()
find_library(TORCH_CPU_LIB torch_cpu PATHS ${LIBTORCH_DIR}/lib)
if (NOT TORCH_CPU_LIB)
message(FATAL_ERROR "torch_cpu.lib not found")
endif()
target_link_directories(meloTTS_ov PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/thirdParty/libtorch/lib")
target_include_directories(meloTTS_ov PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/thirdParty/libtorch/include)
target_include_directories(meloTTS_ov PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/thirdParty/libtorch/include/torch/csrc/api/include)
if("${CMAKE_VS_PLATFORM_NAME}" STREQUAL "x64")
set(ADDITIONAL_LIBRARY_DEPENDENCIES "torch.lib" "c10.lib" "torch_cpu.lib")
target_link_libraries(meloTTS_ov PRIVATE ${ADDITIONAL_LIBRARY_DEPENDENCIES})
endif()
endif() # end USE_DEEPFILTERNET
# Define DEBUG macro for Debug configuration
target_compile_definitions(meloTTS_ov PRIVATE "$<$<CONFIG:DEBUG>:DEBUG>")
target_include_directories(meloTTS_ov PRIVATE ${CMAKE_SOURCE_DIR}/thirdParty/cppjieba)
target_include_directories(meloTTS_ov PRIVATE ${CMAKE_SOURCE_DIR}/thirdParty/cppjieba/include)
target_include_directories(meloTTS_ov PRIVATE ${CMAKE_SOURCE_DIR}/thirdParty/cppinyin/csrc)
target_include_directories(meloTTS_ov PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/thirdParty/cppjieba)
target_include_directories(meloTTS_ov PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/thirdParty/cppjieba/include)
target_include_directories(meloTTS_ov PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/thirdParty/cppinyin/csrc)
target_link_libraries(meloTTS_ov
PRIVATE openvino::runtime # Link OpenVINO Runtime privately
)
if (UNIX)
target_link_libraries(meloTTS_ov PRIVATE pthread)
endif()
option(USE_BERT_NPU "Set Bert on NPU" OFF)
if(USE_BERT_NPU)
message(STATUS "USE BERT on NPU: We need a static shape of the model.")
execute_process(
COMMAND ${CMAKE_COMMAND} -E copy_if_different
${CMAKE_SOURCE_DIR}/ov_models/bert_ZH_int8.bin
${CMAKE_SOURCE_DIR}/ov_models/bert_ZH_static_int8.bin
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR})
message("Copying bert_ZH_int8.bin to bert_ZH_int8.bin if bert_ZH_static_int8.bin does not exist")
endif()
option(ENABLE_TEST "Enable tests" OFF) # Disable the tests by default
if (${ENABLE_TEST})
enable_testing()
add_subdirectory(tests)
endif()