-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
242 lines (192 loc) · 11.3 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
236
237
238
239
240
241
242
cmake_minimum_required(VERSION 3.22)
# This makes the assumption that JUCE is included in CMake project.
if (COMMAND juce_add_module)
message(STATUS "voicevox::voicevox_juce: Add module by juce_add_module command")
# Add voicevox::voicevox_juce module by juce_add_module command
juce_add_module(${CMAKE_CURRENT_SOURCE_DIR}/voicevox_juce ALIAS_NAMESPACE voicevox)
if (${CMAKE_SYSTEM_NAME} STREQUAL "Windows")
# Import as shared library in global scope.
add_library(voicevox_core SHARED IMPORTED GLOBAL)
# Find library path.
set_target_properties(voicevox_core
PROPERTIES
IMPORTED_LOCATION ${CMAKE_CURRENT_SOURCE_DIR}/voicevox_core/windows/voicevox_core.dll
IMPORTED_IMPLIB ${CMAKE_CURRENT_SOURCE_DIR}/voicevox_core/windows/voicevox_core.lib
INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_CURRENT_SOURCE_DIR}/voicevox_core/windows
)
set_property (TARGET voicevox_core APPEND PROPERTY LABELS voicevox_core)
add_library(voicevox::voicevox_core ALIAS voicevox_core)
# Import as shared library in global scope.
add_library(onnxruntime SHARED IMPORTED GLOBAL)
# Find library path.
set_target_properties(onnxruntime
PROPERTIES
IMPORTED_LOCATION ${CMAKE_CURRENT_SOURCE_DIR}/voicevox_core/windows/onnxruntime.dll
)
set_property (TARGET onnxruntime APPEND PROPERTY LABELS onnxruntime)
add_library(voicevox::onnxruntime ALIAS onnxruntime)
# Import as shared library in global scope.
add_library(onnxruntime_providers_shared SHARED IMPORTED GLOBAL)
# Find library path.
set_target_properties(onnxruntime_providers_shared
PROPERTIES
IMPORTED_LOCATION ${CMAKE_CURRENT_SOURCE_DIR}/voicevox_core/windows/onnxruntime_providers_shared.dll
)
set_property (TARGET onnxruntime_providers_shared APPEND PROPERTY LABELS onnxruntime_providers_shared)
add_library(voicevox::onnxruntime_providers_shared ALIAS onnxruntime_providers_shared)
# Add resource importer target.
add_library(voicevox_resource INTERFACE)
set_property (TARGET voicevox_resource APPEND PROPERTY LABELS voicevox_resource)
set_property(TARGET voicevox_resource APPEND PROPERTY resource_model_dir "${CMAKE_CURRENT_SOURCE_DIR}/voicevox_core/windows/model")
set_property(TARGET voicevox_resource APPEND PROPERTY resource_open_jtalk_dic_dir "${CMAKE_CURRENT_SOURCE_DIR}/open_jtalk_dic_utf_8")
add_library(voicevox::voicevox_resource ALIAS voicevox_resource)
elseif (${CMAKE_SYSTEM_NAME} STREQUAL "Darwin")
# Import as shared library in global scope.
add_library(voicevox_core SHARED IMPORTED GLOBAL)
# Set variable
set(VOICEVOX_CORE_LIB_SUFFIX ${CMAKE_CURRENT_SOURCE_DIR}/voicevox_core/macos/lib)
if(UniversalBinary)
# Make universal binary process.
# Make universal binary directory.
execute_process(
COMMAND ${CMAKE_COMMAND} -E make_directory ${VOICEVOX_CORE_LIB_SUFFIX}/universal
RESULT_VARIABLE result
)
if(result)
message(FATAL_ERROR "voicevox::voicevox_juce: Failed to run command make universal binary")
endif()
# Make universal binary directory of libvoicevox_core.dylib.
file(GLOB VOICEVOX_CORE_LIB_ARM64 ${VOICEVOX_CORE_LIB_SUFFIX}/arm64/libvoicevox_core.dylib)
if(NOT VOICEVOX_CORE_LIB_ARM64)
message(FATAL_ERROR "voicevox::voicevox_juce: Can't find libvoicevox_core.dylib for arm64")
endif()
file(GLOB VOICEVOX_CORE_LIB_X86_64 ${VOICEVOX_CORE_LIB_SUFFIX}/x86_64/libvoicevox_core.dylib)
if(NOT VOICEVOX_CORE_LIB_X86_64)
message(FATAL_ERROR "voicevox::voicevox_juce: Can't find libvoicevox_core.dylib for x86_64")
endif()
set(VOICEVOX_CORE_LIB_UNIVERSAL ${VOICEVOX_CORE_LIB_SUFFIX}/universal/libvoicevox_core.dylib)
execute_process(
COMMAND lipo -create ${VOICEVOX_CORE_LIB_ARM64} ${VOICEVOX_CORE_LIB_X86_64} -output ${VOICEVOX_CORE_LIB_UNIVERSAL}
RESULT_VARIABLE result
)
if(result)
message(FATAL_ERROR "voicevox::voicevox_juce: Failed to run command make universal binary")
endif()
# Make universal binary directory of libonnxruntime.dylib
file(GLOB ONNXRUNTIME_SHARED_LIB_ARM64 ${VOICEVOX_CORE_LIB_SUFFIX}/arm64/libonnxruntime.*.dylib)
if(NOT ONNXRUNTIME_SHARED_LIB_ARM64)
message(FATAL_ERROR "voicevox::voicevox_juce: Can't find libonnxruntime.*.dylib for arm64")
endif()
file(GLOB ONNXRUNTIME_SHARED_LIB_X86_64 ${VOICEVOX_CORE_LIB_SUFFIX}/x86_64/libonnxruntime.*.dylib)
if(NOT ONNXRUNTIME_SHARED_LIB_X86_64)
message(FATAL_ERROR "voicevox::voicevox_juce: Can't find libonnxruntime.*.dylib for x86_64")
endif()
# Get actual filename from globbed file name with wild card search.
file(RELATIVE_PATH ONNXRUNTIME_SHARED_LIB_UNIVERSAL_FILENAME ${VOICEVOX_CORE_LIB_SUFFIX}/arm64 ${ONNXRUNTIME_SHARED_LIB_ARM64})
set(ONNXRUNTIME_SHARED_LIB_UNIVERSAL ${VOICEVOX_CORE_LIB_SUFFIX}/universal/${ONNXRUNTIME_SHARED_LIB_UNIVERSAL_FILENAME})
execute_process(
COMMAND lipo -create ${ONNXRUNTIME_SHARED_LIB_ARM64} ${ONNXRUNTIME_SHARED_LIB_X86_64} -output ${ONNXRUNTIME_SHARED_LIB_UNIVERSAL}
RESULT_VARIABLE result
)
if(result)
message(FATAL_ERROR "voicevox::voicevox_juce: Failed to run command make universal binary")
endif()
# Find library path.
set_target_properties(voicevox_core
PROPERTIES
IMPORTED_LOCATION ${VOICEVOX_CORE_LIB_UNIVERSAL}
IMPORTED_NO_SONAME TRUE
INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_CURRENT_SOURCE_DIR}/voicevox_core/macos/include
)
set_property (TARGET voicevox_core APPEND PROPERTY LABELS voicevox_core)
add_library(voicevox::voicevox_core ALIAS voicevox_core)
# Import as shared library in global scope.
add_library(onnxruntime SHARED IMPORTED GLOBAL)
set_target_properties(onnxruntime
PROPERTIES
IMPORTED_LOCATION ${ONNXRUNTIME_SHARED_LIB_UNIVERSAL}
IMPORTED_NO_SONAME TRUE
)
set_property (TARGET onnxruntime APPEND PROPERTY LABELS onnxruntime)
add_library(voicevox::onnxruntime ALIAS onnxruntime)
else()
# Get host machine architecture.
execute_process(
COMMAND uname -m COMMAND tr -d '\n' OUTPUT_VARIABLE HOST_ARCHITECTURE
)
# Find library path.
file(GLOB VOICEVOX_CORE_LIB ${VOICEVOX_CORE_LIB_SUFFIX}/${HOST_ARCHITECTURE}/libvoicevox_core.dylib)
if(NOT VOICEVOX_CORE_LIB)
message(FATAL_ERROR "voicevox::voicevox_juce: Can't find libvoicevox_core.dylib")
endif()
set_target_properties(voicevox_core
PROPERTIES
IMPORTED_LOCATION ${VOICEVOX_CORE_LIB}
IMPORTED_NO_SONAME TRUE
INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_CURRENT_SOURCE_DIR}/voicevox_core/macos/include
)
set_property (TARGET voicevox_core APPEND PROPERTY LABELS voicevox_core)
add_library(voicevox::voicevox_core ALIAS voicevox_core)
# Import as shared library in global scope.
add_library(onnxruntime SHARED IMPORTED GLOBAL)
# Find library path.
file(GLOB ONNXRUNTIME_SHARED_LIB ${VOICEVOX_CORE_LIB_SUFFIX}/${HOST_ARCHITECTURE}/libonnxruntime.*.dylib)
if(NOT ONNXRUNTIME_SHARED_LIB)
message(FATAL_ERROR "voicevox::voicevox_juce: Can't find libonnxruntime.*.dylib")
endif()
set_target_properties(onnxruntime
PROPERTIES
IMPORTED_LOCATION ${ONNXRUNTIME_SHARED_LIB}
IMPORTED_NO_SONAME TRUE
)
set_property (TARGET onnxruntime APPEND PROPERTY LABELS onnxruntime)
add_library(voicevox::onnxruntime ALIAS onnxruntime)
endif()
# Add resource importer target.
add_library(voicevox_resource INTERFACE)
set_property (TARGET voicevox_resource APPEND PROPERTY LABELS voicevox_resource)
set_property(TARGET voicevox_resource APPEND PROPERTY resource_model_dir "${CMAKE_CURRENT_SOURCE_DIR}/voicevox_core/macos/resource/model")
set_property(TARGET voicevox_resource APPEND PROPERTY resource_open_jtalk_dic_dir "${CMAKE_CURRENT_SOURCE_DIR}/open_jtalk_dic_utf_8")
add_library(voicevox::voicevox_resource ALIAS voicevox_resource)
elseif (${CMAKE_SYSTEM_NAME} STREQUAL "Linux")
# Import as shared library in global scope.
add_library(voicevox_core SHARED IMPORTED GLOBAL)
# Find library path.
file(GLOB VOICEVOX_CORE_LIB ${CMAKE_CURRENT_SOURCE_DIR}/voicevox_core/linux/libvoicevox_core.so)
if(NOT VOICEVOX_CORE_LIB)
message(FATAL_ERROR "voicevox::voicevox_juce: Can't find libvoicevox_core.so")
endif()
set_target_properties(voicevox_core
PROPERTIES
IMPORTED_LOCATION ${VOICEVOX_CORE_LIB}
IMPORTED_NO_SONAME TRUE
INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_CURRENT_SOURCE_DIR}/voicevox_core/linux
)
set_property (TARGET voicevox_core APPEND PROPERTY LABELS voicevox_core)
add_library(voicevox::voicevox_core ALIAS voicevox_core)
# Import as shared library in global scope.
add_library(onnxruntime SHARED IMPORTED GLOBAL)
# Find library path.
file(GLOB ONNXRUNTIME_SHARED_LIB ${CMAKE_CURRENT_SOURCE_DIR}/voicevox_core/linux/libonnxruntime.so.*)
if(NOT ONNXRUNTIME_SHARED_LIB)
message(FATAL_ERROR "voicevox::voicevox_juce: Can't find libonnxruntime.so.*")
endif()
set_target_properties(onnxruntime
PROPERTIES
IMPORTED_LOCATION ${ONNXRUNTIME_SHARED_LIB}
IMPORTED_NO_SONAME TRUE
)
set_property (TARGET onnxruntime APPEND PROPERTY LABELS onnxruntime)
add_library(voicevox::onnxruntime ALIAS onnxruntime)
# Add resource importer target.
add_library(voicevox_resource INTERFACE)
set_property (TARGET voicevox_resource APPEND PROPERTY LABELS voicevox_resource)
set_property(TARGET voicevox_resource APPEND PROPERTY resource_model_dir "${CMAKE_CURRENT_SOURCE_DIR}/voicevox_core/linux/model")
set_property(TARGET voicevox_resource APPEND PROPERTY resource_open_jtalk_dic_dir "${CMAKE_CURRENT_SOURCE_DIR}/open_jtalk_dic_utf_8")
add_library(voicevox::voicevox_resource ALIAS voicevox_resource)
else ()
message(FATAL_ERROR "voicevox::voicevox_juce: Can't support platform ${CMAKE_SYSTEM_NAME}")
endif ()
else ()
message(FATAL_ERROR "voicevox::voicevox_juce: Can't determine command juce_add_module")
endif ()