-
Notifications
You must be signed in to change notification settings - Fork 6
/
CMakeLists.txt
630 lines (522 loc) · 18 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
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
CMAKE_MINIMUM_REQUIRED(VERSION 3.9)
PROJECT(nugu)
INCLUDE(GNUInstallDirs)
INCLUDE(FindPkgConfig)
INCLUDE(FeatureSummary)
INCLUDE(CMakePushCheckState)
INCLUDE(CheckSymbolExists)
# Generate compile_commands.json
SET(CMAKE_EXPORT_COMPILE_COMMANDS ON)
# C++ standard: c++11 (not gnu++11)
SET(CMAKE_CXX_STANDARD 11)
SET(CMAKE_CXX_EXTENSIONS OFF)
# C standard: gnu99 (not c99)
SET(CMAKE_C_STANDARD 99)
SET(CMAKE_C_EXTENSIONS ON)
# build type: debug (default)
IF (NOT CMAKE_BUILD_TYPE)
SET(CMAKE_BUILD_TYPE Debug)
ENDIF()
# ----------------------------------------------------------------------------
# Build environment
# ----------------------------------------------------------------------------
MESSAGE(STATUS "Build information")
MESSAGE(" * System: ${CMAKE_SYSTEM_NAME}")
MESSAGE(" * Compiler: ${CMAKE_CXX_COMPILER_ID} ${CMAKE_CXX_COMPILER_VERSION}")
MESSAGE(" * CMAKE_GENERATOR = ${CMAKE_GENERATOR}")
MESSAGE(" * CMAKE_SOURCE_DIR = ${CMAKE_SOURCE_DIR}")
MESSAGE(" * PROJECT_SOURCE_DIR = ${PROJECT_SOURCE_DIR}")
MESSAGE(" * CMAKE_BINARY_DIR = ${CMAKE_BINARY_DIR}")
MESSAGE(" * CMAKE_INSTALL_PREFIX = ${CMAKE_INSTALL_PREFIX}")
MESSAGE(" * CMAKE_FIND_ROOT_PATH = ${CMAKE_FIND_ROOT_PATH}")
IF (MSVC)
MESSAGE(STATUS "Using MSVC compiler")
ENDIF()
# Check for MinGW
IF (CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND WIN32)
IF (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 5)
SET(IS_MINGW TRUE)
MESSAGE(STATUS "Using MinGW compiler")
ENDIF()
ENDIF()
# Check for macOS
IF (${CMAKE_SYSTEM_NAME} STREQUAL "Darwin")
SET(IS_MACOS TRUE)
MESSAGE(STATUS "Using macOS")
ENDIF()
# Check for Linux
IF (${CMAKE_SYSTEM_NAME} STREQUAL "Linux")
SET(IS_LINUX TRUE)
MESSAGE(STATUS "Using Linux")
ENDIF()
# ----------------------------------------------------------------------------
# Variables
# ----------------------------------------------------------------------------
SET(VERSION_MAJOR 1)
SET(VERSION_MINOR 7)
SET(VERSION_PATCH 6)
SET(VERSION "${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}")
# OpenSDK/{sdk-version} ({platform}) Client/{app-version} [additional-info]
SET(NUGU_USERAGENT_FORMAT "OpenSDK/${VERSION} (Linux) Client/%s %s")
SET(NUGU_REGISTRY_URL "https://reg-http.sktnugu.com")
SET(version ${VERSION})
SET(prefix ${CMAKE_INSTALL_PREFIX})
SET(datadir ${CMAKE_INSTALL_FULL_DATAROOTDIR}/nugu)
SET(bindir "${prefix}/${CMAKE_INSTALL_BINDIR}")
SET(requires "")
SET(builtin_decl "")
SET(builtin_list "")
SET(BUILTIN_PLUGIN_LIST "") # Array for built-in plugin
SET(BUILTIN_PLUGIN_LIBS "") # TARGET_LINK_LIBRARIES for libnugu
SET(BUILTIN_PLUGIN_DEPS "") # ADD_DEPENDENCIES for libnugu
IF (PLUGIN_DIR)
SET(plugindir "${PLUGIN_DIR}")
ELSE()
SET(plugindir "${CMAKE_INSTALL_FULL_LIBDIR}/nugu")
ENDIF()
IF (ASSET_DIR)
SET(assetdir "${ASSET_DIR}")
ELSE()
SET(assetdir "${datadir}")
ENDIF()
SET(BUILD_LIBRARY ON)
SET(BUILD_PLUGINS ON)
SET(BUILD_EXAMPLES ON)
SET(BUILD_TESTS ON)
# ----------------------------------------------------------------------------
# Feature
# ----------------------------------------------------------------------------
# Macro for feature definition (Get all options: cmake -LAH)
MACRO(DEFINE_FEATURE id default description)
OPTION(ENABLE_${id} "Enable - ${description} (Default: ${default})" ${default})
add_feature_info(FEATURE_${id} ENABLE_${id} "${description} (Default: ${default})")
ENDMACRO(DEFINE_FEATURE)
# Feature default value
IF (IS_LINUX)
IF (PACKAGING)
SET(ASAN_DEFAULT "OFF")
SET(LTO_DEFAULT "ON")
ELSE()
IF ("${CMAKE_BUILD_TYPE}" STREQUAL "Debug")
SET(ASAN_DEFAULT "ON")
SET(LTO_DEFAULT "OFF")
ELSE()
SET(ASAN_DEFAULT "OFF")
SET(LTO_DEFAULT "ON")
ENDIF()
ENDIF()
SET(BUILTIN_CURL_DEFAULT "ON")
SET(PULSEAUDIO_DEFAULT "ON")
ELSE()
SET(ASAN_DEFAULT "OFF")
SET(LTO_DEFAULT "OFF")
SET(BUILTIN_CURL_DEFAULT "OFF")
SET(PULSEAUDIO_DEFAULT "OFF")
ENDIF()
# Set default build options
DEFINE_FEATURE(LOG_ANSICOLOR ON "ANSI Color to log message")
DEFINE_FEATURE(LTO ${LTO_DEFAULT} "Link Time Optimization")
DEFINE_FEATURE(ASAN ${ASAN_DEFAULT} "Address Sanitizer")
DEFINE_FEATURE(LIBRARY_ONLY OFF "compile only SDK libraries")
DEFINE_FEATURE(PLUGINS_ONLY OFF "compile only plugins")
DEFINE_FEATURE(EXAMPLES_ONLY OFF "compile only examples")
DEFINE_FEATURE(DL_LINKING ON "-ldl linking")
DEFINE_FEATURE(SOCKET_LINKING OFF "-lsocket linking")
DEFINE_FEATURE(EVENTFD ON "eventfd")
DEFINE_FEATURE(PULSEAUDIO ${PULSEAUDIO_DEFAULT} "pulseaudio")
DEFINE_FEATURE(VENDOR_LIBRARY ON "vendor specific library(nugu_wwd, nugu_epd)")
DEFINE_FEATURE(VOICE_STREAMING OFF "voice streaming without epd")
DEFINE_FEATURE(BUILTIN_NJSON ON "compile built-in njson library")
DEFINE_FEATURE(BUILTIN_OPUS OFF "compile built-in OPUS library")
DEFINE_FEATURE(BUILTIN_OPUS_FLOAT_API OFF "floating point to OPUS library")
DEFINE_FEATURE(BUILTIN_CURL ${BUILTIN_CURL_DEFAULT} "compile built-in curl library")
IF (NOT DEFINED ENABLE_BUILTIN_PLUGIN)
SET(ENABLE_BUILTIN_PLUGIN "dummy,filedump" CACHE STRING "List of plugins to be built-in in SDK")
ENDIF()
DEFINE_FEATURE(GSTREAMER_PLUGIN ON "GStreamer plugin")
DEFINE_FEATURE(GSTREAMER_PLUGIN_VOLUME ON "gstreamer plugin volume")
DEFINE_FEATURE(OPUS_PLUGIN ON "OPUS plugin")
DEFINE_FEATURE(SPEEX_PLUGIN ON "SPEEX plugin")
DEFINE_FEATURE(PORTAUDIO_PLUGIN OFF "PortAudio plugin")
DEFINE_FEATURE(OPUSENC_PLUGIN OFF "OPUS encoder plugin")
DEFINE_FEATURE(EXAMPLES_OOB_SETUP ${BUILD_EXAMPLES} "Examples - OOB setup")
DEFINE_FEATURE(EXAMPLES_STANDALONE ${BUILD_EXAMPLES} "Examples - standalone")
DEFINE_FEATURE(EXAMPLES_SIMPLE_TEXT ${BUILD_EXAMPLES} "Examples - simple-text")
DEFINE_FEATURE(EXAMPLES_SIMPLE_ASR ${BUILD_EXAMPLES} "Examples - simple-asr")
DEFINE_FEATURE(EXAMPLES_SIMPLE_PLAY ${BUILD_EXAMPLES} "Examples - simple-play")
DEFINE_FEATURE(EXAMPLES_SIMPLE_TTS ${BUILD_EXAMPLES} "Examples - simple-tts")
DEFINE_FEATURE(EXAMPLES_PROFILING ${BUILD_EXAMPLES} "Examples - profiling")
DEFINE_FEATURE(EXAMPLES_CAP_INJECTION ${BUILD_EXAMPLES} "Examples - capability-injection")
DEFINE_FEATURE(EXAMPLES_RESP_FILTER ${BUILD_EXAMPLES} "Examples - response-filter")
IF (ENABLE_LOG_ANSICOLOR)
# Turn on the colorful log message
ADD_DEFINITIONS(-DNUGU_LOG_USE_ANSICOLOR)
ENDIF()
# Link Time Optimization
IF (ENABLE_LTO)
INCLUDE(CheckIPOSupported)
check_ipo_supported(RESULT IPO_SUPPORTED)
IF (IPO_SUPPORTED)
SET(CMAKE_INTERPROCEDURAL_OPTIMIZATION TRUE)
MESSAGE(" * LTO supported and enabled")
ENDIF()
ENDIF()
# Apply AddressSanitizer
# - https://github.com/google/sanitizers/wiki/AddressSanitizer
IF (ENABLE_ASAN)
ADD_COMPILE_OPTIONS(
-fsanitize=address
# Disable warning message for '... changed in GCC 7.1'
-Wno-psabi)
LINK_LIBRARIES(-lasan)
MESSAGE(" * Address Sanitizer enabled")
ENDIF()
# Settings for building separately
IF (ENABLE_LIBRARY_ONLY)
SET(BUILD_LIBRARY ON)
SET(BUILD_PLUGINS OFF)
SET(BUILD_EXAMPLES OFF)
ENDIF()
IF (ENABLE_PLUGINS_ONLY)
SET(BUILD_LIBRARY OFF)
SET(BUILD_PLUGINS ON)
SET(BUILD_EXAMPLES OFF)
ENDIF()
IF (ENABLE_EXAMPLES_ONLY)
SET(BUILD_LIBRARY OFF)
SET(BUILD_PLUGINS OFF)
SET(BUILD_EXAMPLES ON)
ENDIF()
# Optionable compilation flags
IF (ENABLE_DL_LINKING)
IF(MSVC)
SET(LDFLAG_DL "kernel32")
ELSE()
SET(LDFLAG_DL "-ldl")
ENDIF()
ENDIF()
IF (ENABLE_SOCKET_LINKING)
SET(LDFLAG_SOCKET "-lsocket")
ENDIF()
CMAKE_PUSH_CHECK_STATE(RESET)
SET(CMAKE_REQUIRED_DEFINITIONS -D_GNU_SOURCE)
SET(CMAKE_REQUIRED_LIBRARIES "pthread")
CHECK_SYMBOL_EXISTS(pthread_setname_np "pthread.h" HAVE_PTHREAD_SETNAME_NP)
IF (ENABLE_EVENTFD)
CHECK_SYMBOL_EXISTS(eventfd "sys/eventfd.h" HAVE_EVENTFD)
ENDIF()
CHECK_SYMBOL_EXISTS(syscall "unistd.h" HAVE_SYSCALL)
CMAKE_POP_CHECK_STATE()
IF (HAVE_PTHREAD_SETNAME_NP)
ADD_DEFINITIONS(-DHAVE_PTHREAD_SETNAME_NP)
ENDIF()
IF (HAVE_EVENTFD)
ADD_DEFINITIONS(-DHAVE_EVENTFD)
ENDIF()
IF (HAVE_SYSCALL)
ADD_DEFINITIONS(-DHAVE_SYSCALL)
ENDIF()
IF (ENABLE_PULSEAUDIO AND BUILD_PLUGINS)
ADD_DEFINITIONS(-DENABLE_PULSEAUDIO)
ENDIF()
# Voice streaming (epd not required) and vendor specific library dependency
IF (ENABLE_VOICE_STREAMING)
ADD_DEFINITIONS(-DENABLE_VOICE_STREAMING)
IF (BUILD_LIBRARY AND ENABLE_VENDOR_LIBRARY)
ADD_DEFINITIONS(-DENABLE_VENDOR_LIBRARY)
SET(VENDOR_PKGCONFIG nugu-kwd)
LIST(APPEND PC_DEPS nugu-kwd)
ENDIF()
ELSEIF(ENABLE_VENDOR_LIBRARY)
ADD_DEFINITIONS(-DENABLE_VENDOR_LIBRARY)
IF (BUILD_LIBRARY)
# The SDK libraries require both nugu-kwd and nugu-epd
SET(VENDOR_PKGCONFIG nugu-kwd nugu-epd)
LIST(APPEND PC_DEPS nugu-kwd nugu-epd)
ELSEIF (BUILD_PLUGINS AND ENABLE_SPEEX_PLUGIN)
# The Speex plugin requires the speex API provided by nugu-epd
SET(VENDOR_PKGCONFIG nugu-epd)
LIST(APPEND PC_DEPS nugu-epd)
ENDIF()
ENDIF()
# Built-in njson library
IF (NOT ENABLE_BUILTIN_NJSON)
pkg_check_modules(njson_pkgs REQUIRED njson)
LIST(APPEND PC_DEPS njson)
IF (MSVC)
INCLUDE_DIRECTORIES(${njson_pkgs_INCLUDE_DIRS})
SET(NJSON_LIBRARY ${njson_pkgs_LIBRARIES})
ELSE()
ADD_COMPILE_OPTIONS(${njson_pkgs_CFLAGS})
SET(NJSON_LIBRARY ${njson_pkgs_LDFLAGS})
ENDIF()
LINK_DIRECTORIES(${njson_pkgs_LIBRARY_DIRS})
ENDIF()
# Built-in curl library
IF (ENABLE_BUILTIN_CURL)
SET(CURL_LIBRARY
${PROJECT_BINARY_DIR}/curl/lib/libcurl.a
${PROJECT_BINARY_DIR}/nghttp2/lib/libnghttp2.a)
SET(CURL_INCLUDE ${PROJECT_SOURCE_DIR}/externals/curl/include)
SET(CURL_DEP_PKGCONF zlib openssl)
ELSE()
find_package(CURL)
IF (CURL_FOUND)
SET(CURL_LIBRARY CURL::libcurl)
ELSE()
pkg_check_modules(CURL_PKG REQUIRED libcurl)
SET(CURL_LIBRARY ${CURL_PKG_LDFLAGS})
SET(CURL_INCLUDE ${CURL_PKG_CFLAGS})
ENDIF()
ENDIF()
# Built-in plugin (embedding to libnugu)
IF (ENABLE_BUILTIN_PLUGIN)
# Remove \" from plugin list
STRING(REPLACE "\"" "" TMPSTR ${ENABLE_BUILTIN_PLUGIN} )
# Change comma separated string to array
STRING(REPLACE "," ";" BUILTIN_PLUGIN_LIST ${TMPSTR})
ENDIF()
# GStreamer library dependency
IF (ENABLE_GSTREAMER_PLUGIN)
pkg_check_modules(gstreamer_pkgs REQUIRED
gstreamer-1.0 gstreamer-app-1.0 gstreamer-pbutils-1.0)
IF (MSVC)
SET(GST_LIBRARY ${gstreamer_pkgs_LIBRARIES})
ELSE()
SET(GST_CFLAGS ${gstreamer_pkgs_CFLAGS})
SET(GST_LIBRARY ${gstreamer_pkgs_LDFLAGS})
ENDIF()
SET(GST_INCLUDE_DIR ${gstreamer_pkgs_INCLUDE_DIRS})
IF(ENABLE_GSTREAMER_PLUGIN_VOLUME)
ADD_DEFINITIONS(-DENABLE_GSTREAMER_PLUGIN_VOLUME)
ENDIF()
ENDIF()
# Opus & Ogg library dependency
IF (ENABLE_OPUSENC_PLUGIN OR ENABLE_OPUS_PLUGIN)
IF (NOT ENABLE_BUILTIN_OPUS)
find_package(Opus) # Provide OPUS_LIBRARY, OPUS_INCLUDE_DIR variables
IF (NOT Opus_FOUND)
pkg_check_modules(OPUS_PKG REQUIRED opus)
SET(OPUS_LIBRARY ${OPUS_PKG_LDFLAGS})
SET(OPUS_CFLAGS ${OPUS_PKG_CFLAGS})
ENDIF()
ENDIF()
IF (ENABLE_OPUSENC_PLUGIN)
find_package(Ogg) # Provide OGG_LIBRARY, OGG_INCLUDE_DIR variables
IF(NOT Ogg_FOUND)
pkg_check_modules(OGG_PKG REQUIRED ogg)
SET(OGG_LIBRARY ${OGG_PKG_LDFLAGS})
SET(OGG_CFLAGS ${OGG_PKG_CFLAGS})
ENDIF()
ENDIF()
ENDIF()
# ----------------------------------------------------------------------------
# Compile options - pkg-config
# ----------------------------------------------------------------------------
# pkg-config list
IF (BUILD_LIBRARY)
IF (IS_MINGW OR MSVC)
SET(GIO_PKGCONFIG gio-windows-2.0)
ELSE()
SET(GIO_PKGCONFIG gio-unix-2.0)
ENDIF()
# Set NUGU SDK library default dependency
SET(DEFAULT_LIB_DEPENDENCY glib-2.0 gio-2.0 gthread-2.0
${GIO_PKGCONFIG} ${CURL_DEP_PKGCONF})
ELSE()
SET(DEFAULT_LIB_DEPENDENCY nugu)
ENDIF()
# Set compile flags from pkg-config list
pkg_check_modules(pkgs REQUIRED ${DEFAULT_LIB_DEPENDENCY})
IF (MSVC)
FOREACH(flag ${pkgs_INCLUDE_DIRS})
INCLUDE_DIRECTORIES(${flag})
ENDFOREACH()
ELSE()
FOREACH(flag ${pkgs_CFLAGS})
ADD_COMPILE_OPTIONS(${flag})
ENDFOREACH()
ENDIF()
LINK_DIRECTORIES(${pkgs_LIBRARY_DIRS})
IF (VENDOR_PKGCONFIG)
pkg_check_modules(vendor_pkgs REQUIRED ${VENDOR_PKGCONFIG})
IF (MSVC)
INCLUDE_DIRECTORIES(${vendor_pkgs_INCLUDE_DIRS})
ELSE()
ADD_COMPILE_OPTIONS(${vendor_pkgs_CFLAGS})
ENDIF()
ENDIF()
# Set link flags from pkg-config list
IF (IS_MINGW)
SET(pkgs_LDFLAGS ${pkgs_LDFLAGS} -lstdc++)
ELSEIF (MSVC)
find_package(PThreads4W REQUIRED)
SET(COMMON_LDFLAGS PThreads4W::PThreads4W)
ENDIF()
IF (BUILD_LIBRARY)
IF (MSVC)
SET(COMMON_LDFLAGS ${COMMON_LDFLAGS} ${pkgs_LIBRARIES})
ELSE()
SET(COMMON_LDFLAGS ${COMMON_LDFLAGS} ${vendor_pkgs_LDFLAGS})
# Sets the option so that the built library has a higher link order than
# the library already installed on the system.
LINK_LIBRARIES(-L${PROJECT_BINARY_DIR}/src)
ENDIF()
ENDIF()
IF (NOT MSVC)
SET(COMMON_LDFLAGS ${COMMON_LDFLAGS} ${NJSON_LIBRARY} ${pkgs_LDFLAGS})
ENDIF()
# ----------------------------------------------------------------------------
# Compile options
# ----------------------------------------------------------------------------
IF (NOT BUILD_LIBRARY)
# Dummy target
ADD_CUSTOM_TARGET(libnugu)
ENDIF()
IF (NOT IS_MACOS)
# Run-time buffer overflow detection
ADD_DEFINITIONS(-D_FORTIFY_SOURCE=2)
ENDIF()
# Global compile options
IF (NOT MSVC)
ADD_COMPILE_OPTIONS(
-g -Os
-fPIC
# Improved version of “-fstack-protector” since gcc 4.9
-fstack-protector-strong
# Store the stack frame pointer in a register.
-fno-omit-frame-pointer
# Eliminate unused code and data (with --gc-sections link option)
-fdata-sections -ffunction-sections
# Increase reliability of backtraces
-fasynchronous-unwind-tables
# Turn on all warnings and treat all warnings as errors.
-Werror -Wall -Wextra
# Additional warnings
-Wunreachable-code -Wpointer-arith
-Wformat=2 -Wno-format-nonliteral
# Not warnings
-Wno-missing-field-initializers
-Wno-unused-parameter)
ENDIF()
# Compiler specific options (gcc, clang)
IF (CMAKE_COMPILER_IS_GNUCC)
# Enable a new static analysis pass and associated warnings. (Introduced gcc v10.1)
# This option will not work if LTO is enabled.
IF (CMAKE_C_COMPILER_VERSION VERSION_GREATER 10.1)
# It is recommended to use only C language.
STRING(APPEND CMAKE_C_FLAGS " -fanalyzer")
# Not errors
STRING(APPEND CMAKE_C_FLAGS " -Wno-analyzer-possible-null-dereference")
# Not warnings (GCC 10.3 issue)
STRING(APPEND CMAKE_C_FLAGS " -Wno-analyzer-malloc-leak")
IF (IS_MINGW)
# Not warnings (false alarm in window)
STRING(APPEND CMAKE_C_FLAGS " -Wno-analyzer-fd-leak")
ENDIF()
ENDIF()
IF (NOT IS_MINGW)
ADD_COMPILE_OPTIONS(
# Non-executable stack
-Wa,--execstack
# Eliminate unused code and data (with --gc-sections link option)
-Wl,--gc-sections)
LINK_LIBRARIES(
# Link only needed libraries
-Wl,--as-needed
# Enforces symbol resolution at build time
-Wl,-z,defs
# Non-executable stack
-Wl,-z,noexecstack
# Debian packaging default link flags
-Wl,-Bsymbolic-functions -Wl,-z,relro)
ENDIF()
# RPATH is useful only for testing without installation.
# Please use the '-DPACKAGING' option for debian packaging.
IF (NOT PACKAGING)
LINK_LIBRARIES(-Wl,--rpath=${PROJECT_BINARY_DIR}/src)
ENDIF()
# Add __FILENAME__ macro to use path from source directory instead of full path
IF (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 8.0)
ADD_COMPILE_OPTIONS(-fmacro-prefix-map=${PROJECT_SOURCE_DIR}/=)
ELSE()
IF (CMAKE_GENERATOR MATCHES "Unix Makefiles")
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D__FILENAME__='\"$(subst $(realpath ${PROJECT_SOURCE_DIR})/,,$(abspath $<))\"'")
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D__FILENAME__='\"$(subst $(realpath ${PROJECT_SOURCE_DIR})/,,$(abspath $<))\"'")
ENDIF()
ENDIF()
ELSEIF (MSVC)
ADD_COMPILE_OPTIONS(/W0 /utf-8)
ELSE()
ADD_COMPILE_OPTIONS(-fmacro-prefix-map=${PROJECT_SOURCE_DIR}/=)
IF (NOT PACKAGING)
LINK_LIBRARIES(-Wl,-rpath,${PROJECT_BINARY_DIR}/src)
ENDIF()
ENDIF()
# Set asset file path
ADD_DEFINITIONS(-DNUGU_ASSET_PATH="${assetdir}")
# Global definitions
ADD_DEFINITIONS(
-DNUGU_PLUGIN_FILE_EXTENSION="${CMAKE_SHARED_LIBRARY_SUFFIX}"
# Environment variable names
# - Please comment out the following definition to avoid overwriting
# the value by setting an environment variable. (e.g. Production)
-DNUGU_ENV_LOG="NUGU_LOG"
-DNUGU_ENV_LOG_LEVEL="NUGU_LOG_LEVEL"
-DNUGU_ENV_LOG_MODULE="NUGU_LOG_MODULE"
-DNUGU_ENV_LOG_PREFIX="NUGU_LOG_PREFIX"
-DNUGU_ENV_LOG_PROTOCOL_LINE_LIMIT="NUGU_LOG_PROTOCOL_LINE_LIMIT"
-DNUGU_ENV_NETWORK_REGISTRY_SERVER="NUGU_REGISTRY_SERVER"
-DNUGU_ENV_NETWORK_USERAGENT="NUGU_USERAGENT"
-DNUGU_ENV_NETWORK_USE_V1="NUGU_NETWORK_USE_V1"
-DNUGU_ENV_DUMP_PATH_PCM="NUGU_DUMP_PATH_PCM"
-DNUGU_ENV_DUMP_PATH_RECORDER="NUGU_DUMP_PATH_RECORDER"
-DNUGU_ENV_DUMP_PATH_DECODER="NUGU_DUMP_PATH_DECODER"
-DNUGU_ENV_DUMP_PATH_ENCODER="NUGU_DUMP_PATH_ENCODER"
-DNUGU_ENV_RECORDING_FROM_FILE="NUGU_RECORDING_FROM_FILE"
-DNUGU_ENV_DUMP_LINK_FILE_DECODER="NUGU_DUMP_LINK_FILE_DECODER"
-DNUGU_ENV_DUMP_LINK_FILE_PCM="NUGU_DUMP_LINK_FILE_PCM"
-DNUGU_ENV_DUMP_LINK_FILE_RECORDER="NUGU_DUMP_LINK_FILE_RECORDER"
-DNUGU_ENV_DEFAULT_PCM_DRIVER="NUGU_DEFAULT_PCM_DRIVER"
-DNUGU_ENV_PLUGIN_PATH="NUGU_PLUGIN_PATH"
)
MESSAGE("")
feature_summary(WHAT ALL)
IF (BUILD_LIBRARY)
# Global include directories
INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR}/include)
INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR}/externals/njson/include)
FOREACH(item ${BUILTIN_PLUGIN_LIST})
SET(builtin_decl "${builtin_decl}extern struct nugu_plugin_desc _builtin_plugin_${item};\n")
SET(builtin_list "${builtin_list}&_builtin_plugin_${item},\n")
ENDFOREACH()
CONFIGURE_FILE(src/base/builtin.h.in ${PROJECT_SOURCE_DIR}/src/base/builtin.h @ONLY)
CONFIGURE_FILE(nugu.h.in ${PROJECT_SOURCE_DIR}/include/nugu.h @ONLY)
ENDIF()
# External dependency modules - nghttp2, curl
ADD_SUBDIRECTORY(externals)
# Plugins
IF (BUILD_PLUGINS)
ADD_SUBDIRECTORY(plugins)
ENDIF()
IF (BUILD_LIBRARY)
# Install header files
INSTALL(DIRECTORY include/ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/nugu/)
# Install pkgconfig
STRING(REPLACE ";" " " requires "${PC_DEPS}")
CONFIGURE_FILE(nugu.pc.in ${PROJECT_BINARY_DIR}/nugu.pc @ONLY)
INSTALL(FILES ${PROJECT_BINARY_DIR}/nugu.pc DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig/)
# Install asset files
INSTALL(DIRECTORY assets/model DESTINATION ${assetdir} COMPONENT libnugu_component)
ENABLE_TESTING()
# NUGU SDK
ADD_SUBDIRECTORY(src)
# Unit tests
IF (BUILD_TESTS)
ADD_SUBDIRECTORY(tests)
ENDIF()
ENDIF()
# Examples
IF (BUILD_EXAMPLES)
ADD_SUBDIRECTORY(examples)
ENDIF()