-
Notifications
You must be signed in to change notification settings - Fork 77
/
CMakeLists.txt
435 lines (394 loc) · 14.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
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
cmake_minimum_required(VERSION 3.5.1)
if(NOT ${CMAKE_VERSION} VERSION_LESS "3.15")
cmake_policy(SET CMP0091 NEW) # required for CMAKE_MSVC_RUNTIME_LIBRARY but it's only supported by CMake 3.15 or later
endif()
project(openSMILE)
option(STATIC_LINK "Build libopensmile as a static lib." ON)
option(MARCH_NATIVE "Tune compiler optimizations to the processor of this machine. Disable if the compiled binary needs to be portable." OFF)
option(WITH_PORTAUDIO "Compile with PortAudio support." OFF)
option(WITH_FFMPEG "Compile with FFmpeg support." OFF)
option(WITH_OPENSLES "Compile with OpenSL ES support (Android only)." OFF)
option(WITH_OPENCV "Compile with OpenCV support." OFF)
set(BUILD_FLAGS "" CACHE STRING "Build flags controlling which components of openSMILE are included in the build.")
set(PROFILE_GENERATE "" CACHE PATH "Path where to save profile information for profile-guided optimization.")
set(PROFILE_USE "" CACHE PATH "Path to profile information to use for profile-guided optimization.")
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY BOTH)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE BOTH)
set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE BOTH)
if(PROFILE_GENERATE AND PROFILE_USE)
message(FATAL_ERROR "PROFILE_GENERATE and PROFILE_USE must not be set at the same time.")
endif()
set(WATCH_PLATFORMS WATCHOS WATCHOSCOMBINED SIMULATOR_WATCHOS)
if(IS_IOS_PLATFORM AND (PLATFORM IN_LIST WATCH_PLATFORMS))
set(IS_IOS_WATCH_PLATFORM ON)
else()
set(IS_IOS_WATCH_PLATFORM OFF)
endif()
# set C and C++ standards for all targets
set(CMAKE_C_STANDARD 99)
set(CMAKE_C_STANDARD_REQUIRED ON)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
# set build type-specific compilation flags
string(APPEND CMAKE_C_FLAGS_DEBUG " -D_DEBUG")
string(APPEND CMAKE_CXX_FLAGS_DEBUG " -D_DEBUG")
string(APPEND CMAKE_C_FLAGS_RELEASE " -DNDEBUG")
string(APPEND CMAKE_CXX_FLAGS_RELEASE " -DNDEBUG")
# disable a set of commonly occurring warnings in gcc
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
string(APPEND CMAKE_C_FLAGS " -Wno-unused-result")
string(APPEND CMAKE_CXX_FLAGS " -Wno-unused-result")
endif()
# disable a set of commonly occurring warnings in Visual C++ compiler
# also enable /EHsc required for exception handling
if(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
string(APPEND CMAKE_C_FLAGS " /wd4244 /wd4267 /wd4305 /EHsc")
string(APPEND CMAKE_CXX_FLAGS " /wd4244 /wd4267 /wd4305 /EHsc")
endif()
# set default build type to Release (can be overridden by calling e.g. cmake -DCMAKE_BUILD_TYPE=Debug ..)
# allowed values: "Debug", "Release", "MinSizeRel", "RelWithDebInfo"
if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
message("Setting build type to 'Release' as none was specified.")
set(CMAKE_BUILD_TYPE Release)
endif()
# set __WINDOWS directive on Windows platforms and disable some common warnings
if(WIN32)
add_definitions(
-D__WINDOWS
-D_CRT_SECURE_NO_WARNINGS # disable warnings for using unsafe functions in Visual C++ runtime
-D_CRT_NONSTDC_NO_DEPRECATE # disable warnings for non-standard POSIX functions like strdup
-D_WINSOCK_DEPRECATED_NO_WARNINGS # disable warnings for using deprecated WinSock2 functions
)
endif()
# set __ANDROID__ directive when compiling for Android
if(ANDROID_NDK)
add_definitions(-D__ANDROID__)
endif()
# set __IOS__ directive when compiling for iOS
if(IS_IOS_PLATFORM)
add_definitions(-D__IOS__)
# set __IOS_WATCH__ directive when compiling for iOS Watch
if(IS_IOS_WATCH_PLATFORM)
add_definitions(-D__IOS_WATCH__)
endif()
endif()
# set __OSX__ directive when compiling for Mac
if(APPLE)
add_definitions(-D__OSX__)
endif()
add_definitions(${BUILD_FLAGS})
# update version information in src/include/core/git_version.hpp
if(IS_IOS_PLATFORM)
# when using ios.toolchain.cmake, we need to use find_host_package to find Git on the host system
find_host_package(Git)
else()
find_package(Git)
endif()
if(GIT_FOUND)
execute_process(COMMAND ${GIT_EXECUTABLE} rev-parse --verify --quiet --short HEAD
WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}
ERROR_VARIABLE GIT_ERROR
OUTPUT_VARIABLE VERSION_INFO_WC_REVISION
OUTPUT_STRIP_TRAILING_WHITESPACE)
if(NOT ${GIT_ERROR} EQUAL 0)
set(VERSION_INFO_WC_REVISION "unknown")
endif()
execute_process(COMMAND ${GIT_EXECUTABLE} symbolic-ref --short HEAD
WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}
ERROR_VARIABLE GIT_ERROR
OUTPUT_VARIABLE VERSION_INFO_BUILD_BRANCH
OUTPUT_STRIP_TRAILING_WHITESPACE)
if(NOT ${GIT_ERROR} EQUAL 0)
set(VERSION_INFO_BUILD_BRANCH "unknown")
endif()
else(GIT_FOUND)
set(VERSION_INFO_WC_REVISION "unknown")
set(VERSION_INFO_BUILD_BRANCH "unknown")
endif()
string(TIMESTAMP VERSION_INFO_BUILD_DATE UTC)
configure_file(src/include/core/git_version.hpp.in src/include/core/git_version.hpp)
# add targets in subdirectories
add_subdirectory(src/newmat)
add_subdirectory(progsrc/smileapi)
if(NOT IS_IOS_PLATFORM AND NOT IS_IOS_WATCH_PLATFORM)
add_subdirectory(progsrc/smilextract)
endif()
# libopensmile target #########################################################
set(opensmile_SOURCES
$<TARGET_OBJECTS:newmat>
src/classifiers/libsvm/svm.cpp
src/classifiers/libsvmliveSink.cpp
src/classifiers/svmSink.cpp
src/core/commandlineParser.cpp
src/core/componentManager.cpp
src/core/configManager.cpp
src/core/dataMemory.cpp
src/core/dataMemoryLevel.cpp
src/core/dataProcessor.cpp
src/core/dataReader.cpp
src/core/dataSelector.cpp
src/core/dataSink.cpp
src/core/dataSource.cpp
src/core/dataWriter.cpp
src/core/exceptions.cpp
src/core/nullSink.cpp
src/core/smileCommon.cpp
src/core/smileComponent.cpp
src/core/smileLogger.cpp
src/core/smileThread.cpp
src/core/vecToWinProcessor.cpp
src/core/vectorProcessor.cpp
src/core/vectorTransform.cpp
src/core/winToVecProcessor.cpp
src/core/windowProcessor.cpp
src/dsp/dbA.cpp
src/dsp/signalGenerator.cpp
src/dsp/smileResample.cpp
src/dsp/specResample.cpp
src/dsp/vadV1.cpp
src/dsp/specScale.cpp
src/dspcore/acf.cpp
src/dspcore/amdf.cpp
src/dspcore/contourSmoother.cpp
src/dspcore/deltaRegression.cpp
src/dspcore/fftmagphase.cpp
src/dspcore/fftsg.c
src/dspcore/framer.cpp
src/dspcore/fullinputMean.cpp
src/dspcore/fullturnMean.cpp
src/dspcore/monoMixdown.cpp
src/dspcore/preemphasis.cpp
src/dspcore/transformFft.cpp
src/dspcore/turnDetector.cpp
src/dspcore/vectorMVN.cpp
src/dspcore/vectorPreemphasis.cpp
src/dspcore/windower.cpp
src/examples/exampleSink.cpp
src/examples/exampleSource.cpp
src/examples/simpleMessageSender.cpp
src/ffmpeg/ffmpegSource.cpp
src/functionals/functionalComponent.cpp
src/functionals/functionalCrossings.cpp
src/functionals/functionalDCT.cpp
src/functionals/functionalExtremes.cpp
src/functionals/functionalLpc.cpp
src/functionals/functionalMeans.cpp
src/functionals/functionalMoments.cpp
src/functionals/functionalOnset.cpp
src/functionals/functionalPeaks.cpp
src/functionals/functionalPeaks2.cpp
src/functionals/functionalPercentiles.cpp
src/functionals/functionalRegression.cpp
src/functionals/functionalSamples.cpp
src/functionals/functionalSegments.cpp
src/functionals/functionalTimes.cpp
src/functionals/functionalModulation.cpp
src/functionals/functionals.cpp
src/io/libsvmSink.cpp
src/iocore/arffSink.cpp
src/iocore/arffSource.cpp
src/iocore/csvSink.cpp
src/iocore/csvSource.cpp
src/iocore/datadumpSink.cpp
src/iocore/dataPrintSink.cpp
src/iocore/htkSink.cpp
src/iocore/htkSource.cpp
src/iocore/externalSink.cpp
src/iocore/externalSource.cpp
src/iocore/externalAudioSource.cpp
src/iocore/waveSink.cpp
src/iocore/waveSinkCut.cpp
src/iocore/waveSource.cpp
src/lld/cens.cpp
src/lld/chroma.cpp
src/lld/formantLpc.cpp
src/lld/formantSmoother.cpp
src/lld/lpc.cpp
src/lld/lsp.cpp
src/lld/pitchDirection.cpp
src/lld/pitchJitter.cpp
src/lld/pitchShs.cpp
src/lld/pitchSmootherViterbi.cpp
src/lld/tonefilt.cpp
src/lld/tonespec.cpp
src/lld/harmonics.cpp
src/lldcore/energy.cpp
src/lldcore/intensity.cpp
src/lldcore/melspec.cpp
src/lldcore/mfcc.cpp
src/lldcore/mzcr.cpp
src/lldcore/pitchACF.cpp
src/lldcore/pitchBase.cpp
src/lldcore/pitchSmoother.cpp
src/lldcore/plp.cpp
src/lldcore/spectral.cpp
src/other/maxIndex.cpp
src/other/valbasedSelector.cpp
src/other/vectorConcat.cpp
src/other/vectorBinaryOperation.cpp
src/other/vectorOperation.cpp
src/other/externalMessageInterface.cpp
src/portaudio/portaudioDuplex.cpp
src/portaudio/portaudioSink.cpp
src/portaudio/portaudioSource.cpp
src/portaudio/portaudioWavplayer.cpp
src/android/openslesSource.cpp
src/rnn/rnn.cpp
src/rnn/rnnProcessor.cpp
src/rnn/rnnSink.cpp
src/rnn/rnnVad2.cpp
src/smileutil/smileUtil.c
src/smileutil/smileUtilSpline.c
src/smileutil/smileUtilCsv.cpp
src/smileutil/zerosolve.cpp
src/smileutil/JsonClasses.cpp
src/video/openCVSource.cpp
)
if(IS_IOS_PLATFORM AND NOT IS_IOS_WATCH_PLATFORM)
list(APPEND opensmile_SOURCES
src/ios/iosRecorder.cpp
src/ios/coreAudioSource.cpp
)
endif()
if(STATIC_LINK)
add_library(opensmile STATIC ${opensmile_SOURCES})
target_compile_definitions(opensmile PUBLIC -D__STATIC_LINK)
else()
add_library(opensmile SHARED ${opensmile_SOURCES})
endif()
target_include_directories(opensmile
PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src/include>
$<INSTALL_INTERFACE:src/include>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/progsrc/include>
$<INSTALL_INTERFACE:progsrc/include>
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/src/include> # for generated files (git_version.hpp)
)
target_link_libraries(opensmile
PUBLIC
Threads::Threads
)
# dl library needed for dynamic loading of libraries under Linux
if(NOT WIN32 AND NOT STATIC_LINK)
target_link_libraries(opensmile
PRIVATE
dl
)
endif()
if(WIN32)
target_link_libraries(opensmile
PRIVATE
Ws2_32 # Winsock2 for networking under Windows
)
endif()
if(ANDROID_NDK)
find_library(log-lib log)
target_link_libraries(opensmile PRIVATE ${log-lib})
endif(ANDROID_NDK)
if(IS_IOS_PLATFORM)
# compile all C++ sources as Objective-C++
foreach(source IN ITEMS ${opensmile_SOURCES})
get_filename_component(extension "${source}" EXT)
string(TOLOWER "${extension}" extension)
if(extension STREQUAL ".cpp")
set_source_files_properties(${source}
PROPERTIES
COMPILE_FLAGS "-x objective-c++"
)
endif()
endforeach()
find_library(COREFOUNDATION CoreFoundation REQUIRED)
find_library(AVFOUNDATION AVFoundation REQUIRED)
find_library(AUDIOTOOLBOX AudioToolbox REQUIRED)
target_link_libraries(opensmile
PRIVATE
${COREFOUNDATION}
${AVFOUNDATION}
${AUDIOTOOLBOX}
)
endif()
# allow linking of libopensmile into shared libraries
set_property(TARGET opensmile PROPERTY POSITION_INDEPENDENT_CODE ON)
if (MARCH_NATIVE AND NOT MSVC AND NOT ANDROID_NDK AND NOT IS_IOS_PLATFORM)
target_compile_options(opensmile
PRIVATE
-march=native
-mtune=native
)
endif()
# profile-guided optimization
#
# 1. Compile with -DPROFILE_GENERATE=<path to profile folder>
# 2. Run SMILExtract on training samples. Profile information will be saved in the chosen folder.
# 3. If compiling using Clang: run
# llvm-profdata merge -output=default.profdata *.profraw
# in the profile folder.
# 4. Compile again with -DPROFILE_USE=<path to profile folder>
#
if(PROFILE_GENERATE)
target_compile_options(opensmile
PRIVATE
"-fprofile-generate=${PROFILE_GENERATE}"
)
target_link_libraries(opensmile
PRIVATE
"-fprofile-generate=${PROFILE_GENERATE}"
)
endif()
if(PROFILE_USE)
target_compile_options(opensmile
PRIVATE
"-fprofile-use=${PROFILE_USE}"
)
target_link_libraries(opensmile
PRIVATE
"-fprofile-use=${PROFILE_USE}"
)
endif()
# add own cmake folder with .cmake files to CMake module path (used by find_package commands)
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake")
# pthread
set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads REQUIRED)
# Portaudio
if(WITH_PORTAUDIO)
find_package(portaudio REQUIRED)
target_include_directories(opensmile PRIVATE ${PORTAUDIO_INCLUDE_DIRS})
target_link_libraries(opensmile PRIVATE ${PORTAUDIO_LIBRARIES})
target_compile_definitions(opensmile PRIVATE ${PORTAUDIO_DEFINITIONS})
if((PORTAUDIO_VERSION EQUAL 19) OR (PORTAUDIO_VERSION GREATER 19))
target_compile_definitions(opensmile PRIVATE -DHAVE_PORTAUDIO -DHAVE_PORTAUDIO_V19)
else()
target_compile_definitions(opensmile PRIVATE -DHAVE_PORTAUDIO)
endif()
endif(WITH_PORTAUDIO)
# FFmpeg
if(WITH_FFMPEG)
set(FFmpeg_FIND_COMPONENTS AVCODEC AVFORMAT AVUTIL) # specify required FFmpeg components
find_package(FFmpeg REQUIRED)
target_include_directories(opensmile PRIVATE ${FFMPEG_INCLUDE_DIRS})
target_link_libraries(opensmile PRIVATE ${FFMPEG_LIBRARIES})
target_compile_definitions(opensmile PRIVATE ${FFMPEG_DEFINITIONS})
target_compile_definitions(opensmile PRIVATE -DHAVE_FFMPEG)
endif(WITH_FFMPEG)
# OpenSLES (Android-specific)
if(WITH_OPENSLES AND ANDROID_NDK)
find_package(OpenSLES REQUIRED)
target_include_directories(opensmile PRIVATE ${OPENSLES_INCLUDE_DIRS})
target_link_libraries(opensmile PRIVATE ${OPENSLES_LIBRARIES})
target_compile_definitions(opensmile PRIVATE ${OPENSLES_DEFINITIONS})
target_compile_definitions(opensmile PRIVATE -DHAVE_OPENSLES)
endif(WITH_OPENSLES AND ANDROID_NDK)
# OpenCV
if(WITH_OPENCV)
find_package(OpenCV REQUIRED)
target_include_directories(opensmile PRIVATE ${OpenCV_INCLUDE_DIRS})
target_link_libraries(opensmile PRIVATE ${OpenCV_LIBS})
target_compile_definitions(opensmile PRIVATE -DHAVE_OPENCV)
endif(WITH_OPENCV)
install(TARGETS opensmile
DESTINATION lib
EXPORT opensmile-targets)
install(EXPORT opensmile-targets
FILE opensmile-config.cmake
DESTINATION lib/cmake/opensmile)