forked from openDAQ/openDAQ
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
739 lines (602 loc) · 28.8 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
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
cmake_minimum_required(VERSION 3.24)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
set(CMAKE_FOLDER "${CMAKE_FOLDER}/openDAQ")
set(SDK_NAME openDAQ)
set(SDK_TARGET_NAME opendaq)
set(SDK_TARGET_NAMESPACE daq)
set(SDK_OPTION_PREFIX OPENDAQ)
file(READ "opendaq_version" package_version)
string(STRIP ${package_version} package_version)
set(OPENDAQ_PACKAGE_VERSION "${package_version}")
set(CMAKE_MESSAGE_CONTEXT ${SDK_NAME})
set(CMAKE_MESSAGE_CONTEXT_SHOW ON CACHE BOOL "Show CMake message context")
if (${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_BINARY_DIR})
message(FATAL_ERROR "In-source build is not supported! Please choose a separate build directory e.g.: /build/x64/msvc")
endif()
project(${SDK_NAME}
LANGUAGES CXX
VERSION ${OPENDAQ_PACKAGE_VERSION}
)
list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake
)
get_filename_component(ROOT_DIR ${CMAKE_SOURCE_DIR} REALPATH)
get_filename_component(PROJ_DIR ${PROJECT_SOURCE_DIR} REALPATH)
if (NOT ${PROJECT_SOURCE_DIR} STREQUAL ${ROOT_DIR})
set(BUILDING_AS_SUBMODULE ON)
message(STATUS "Building as submodule")
else()
message(STATUS "Building standalone")
set_property(GLOBAL PROPERTY PREDEFINED_TARGETS_FOLDER ".CMakePredefinedTargets")
endif()
find_package(GitInfo)
if (COMMAND GIT_WC_INFO)
GIT_WC_INFO("${CMAKE_CURRENT_SOURCE_DIR}" "OPENDAQ")
if (DEFINED CI_GIT_BRANCH AND NOT ${CI_GIT_BRANCH} STREQUAL "")
STRING(REPLACE "refs/heads/" "" OPENDAQ_WC_BRANCH_NAME ${CI_GIT_BRANCH})
endif()
message(STATUS "Git branch: ${OPENDAQ_WC_BRANCH_NAME} | ${OPENDAQ_WC_REVISION_HASH}")
if (NOT ${OPENDAQ_WC_BRANCH_NAME} MATCHES "^release\/[0-9]+\.[0-9]+(\.[0-9])?(\.[0-9])?(-[a-z|A-Z|0-9]*)?$")
set (OPENDAQ_PACKAGE_VERSION_WITH_SHA "${OPENDAQ_PACKAGE_VERSION}_${OPENDAQ_WC_REVISION_HASH}")
endif()
else()
set(OPENDAQ_WC_REVISION "NA")
endif()
if (NOT ${OPENDAQ_PACKAGE_VERSION_WITH_SHA} STREQUAL "")
message(STATUS "openDAQ package version: ${OPENDAQ_PACKAGE_VERSION_WITH_SHA}")
add_compile_definitions(OPENDAQ_PACKAGE_VERSION="${OPENDAQ_PACKAGE_VERSION_WITH_SHA}")
else()
message(STATUS "openDAQ package version: ${OPENDAQ_PACKAGE_VERSION}")
add_compile_definitions(OPENDAQ_PACKAGE_VERSION="${OPENDAQ_PACKAGE_VERSION}")
endif()
include(CheckCompilerFlag)
include(CheckLinkerFlag)
include(CMakeDependentOption)
include(GNUInstallDirs)
if (POLICY CMP0074)
cmake_policy(SET CMP0074 NEW)
endif()
if (POLICY CMP0076)
cmake_policy(SET CMP0076 NEW)
endif()
if (POLICY CMP0077)
cmake_policy(SET CMP0077 NEW)
endif()
if (POLICY CMP0135)
cmake_policy(SET CMP0135 NEW)
endif()
if (POLICY CMP0076)
cmake_policy(SET CMP0076 NEW)
endif()
# All install targets from within the project should eventually specify the component name.
# This changes the default name for all the targets without an explicit name ("Unspecified").
# The component "Unspecified" is a bit special and makes it hard to be excluded.
# Ideally we would just avoid installing all external components and we wouldn't need setting this at all.
set(CMAKE_INSTALL_DEFAULT_COMPONENT_NAME "External")
if(APPLE)
set(LIB_LOAD_ORIGIN @loader_path)
else()
set(LIB_LOAD_ORIGIN $ORIGIN)
endif()
file(RELATIVE_PATH RPATH_DIR
${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_INSTALL_BINDIR}
${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR}
)
# allow CMAKE_INSTALL_RPATH to be cleared from the command line
if (NOT DEFINED CMAKE_INSTALL_RPATH)
set(CMAKE_INSTALL_RPATH ${LIB_LOAD_ORIGIN} ${LIB_LOAD_ORIGIN}/${RPATH_DIR})
endif()
if (NOT MSVC)
option(OPENDAQ_FORCE_COMPILE_32BIT "Compile 32Bit on non MSVC" OFF)
endif()
if (MSVC)
option(OPENDAQ_MSVC_SINGLE_PROCESS_BUILD "Do not include /MP compile option." OFF)
endif()
# Feature options
option(OPENDAQ_ENABLE_PARAMETER_VALIDATION "Enable parameter validation in functions" ON)
option(OPENDAQ_ENABLE_APPLICATION "Enable building of ${SDK_NAME} application" OFF)
option(OPENDAQ_ENABLE_WEBSOCKET_STREAMING "Enable ${SDK_NAME} websocket streaming" OFF)
option(OPENDAQ_THREAD_SAFE "Enable thread-safe implementations where available" ON)
option(OPENDAQ_MIMALLOC_SUPPORT "Enable MiMalloc-based packet allocator" OFF)
option(OPENDAQ_ENABLE_NATIVE_STREAMING "Enable ${SDK_NAME} native streaming" OFF)
option(OPENDAQ_ALWAYS_FETCH_DEPENDENCIES "Ignore any installed libraries and always build all dependencies from source" ON)
option(OPENDAQ_ENABLE_OPCUA "Enable OpcUa" OFF)
cmake_dependent_option(OPCUA_ENABLE_ENCRYPTION "Enable OpcUa encryption" OFF "OPENDAQ_ENABLE_OPCUA" OFF)
# Bindings
option(OPENDAQ_GENERATE_DELPHI_BINDINGS "Generate Delphi bindings" OFF)
option(OPENDAQ_GENERATE_PYTHON_BINDINGS "Generate Python bindings" OFF)
option(OPENDAQ_GENERATE_CSHARP_BINDINGS "Generate CSharp bindings" OFF)
# Runtime and default 3rd party library linking
option(OPENDAQ_LINK_RUNTIME_STATICALLY "Link the C++ runtime staticaly (embedd it)" OFF)
option(OPENDAQ_LINK_3RD_PARTY_LIBS_STATICALY "Link the 3rd party libraries staticaly (embedd it)" ON)
# Testing and coverage
option(OPENDAQ_ENABLE_TESTS "Enable testing" ON)
option(OPENDAQ_ENABLE_TEST_UTILS "Enable testing utils library" ON)
option(OPENDAQ_ENABLE_OPTIONAL_TESTS "Enable optional (debugging) tests" OFF)
option(OPENDAQ_ENABLE_COVERAGE "Enable code coverage in testing" OFF)
option(OPENDAQ_ENABLE_REGRESSION_TESTS "Enable regression testing" OFF)
# Additional build options
option(OPENDAQ_DISABLE_DEBUG_POSTFIX "Disable debug ('-debug') postfix" OFF)
option(OPENDAQ_DEBUG_WARNINGS_AS_ERRORS "Treat debug warnings as errors" OFF)
option(OPENDAQ_RELEASE_WARNINGS_AS_ERRORS "Treat release warnings as errors" ON)
option(OPENDAQ_USE_CCACHE "Use compiler cache driver if available" ON)
# Dependent options
cmake_dependent_option(OPENDAQ_ENABLE_INTEGRATION_TESTS "Enable testing" ON "OPENDAQ_ENABLE_TESTS" OFF)
cmake_dependent_option(OPENDAQ_ENABLE_DELPHI_BINDINGS_TESTS "Enable delphi bindings tests" ON "OPENDAQ_GENERATE_DELPHI_BINDINGS;OPENDAQ_ENABLE_TESTS" OFF)
cmake_dependent_option(OPENDAQ_ENABLE_PYTHON_BINDINGS_TESTS "Enable python bindings tests" ON "OPENDAQ_GENERATE_PYTHON_BINDINGS;OPENDAQ_ENABLE_TESTS" OFF)
cmake_dependent_option(OPENDAQ_ENABLE_CSHARP_BINDINGS_TESTS "Enable csharp bindings tests" ON "OPENDAQ_GENERATE_CSHARP_BINDINGS;OPENDAQ_ENABLE_TESTS" OFF)
if (NOT APPLE AND UNIX)
cmake_dependent_option(OPENDAQ_ENABLE_WS_SIGGEN_INTEGRATION_TESTS "Enable websocket streaming integration tests" ON "OPENDAQ_ENABLE_TESTS;OPENDAQ_ENABLE_WEBSOCKET_STREAMING" OFF)
endif()
if (OPENDAQ_ENABLE_TESTS)
set(OPENDAQ_ENABLE_TEST_UTILS ON)
endif()
# Optional Modules
option(DAQMODULES_OPENDAQ_CLIENT_MODULE "Building of ${SDK_NAME} client modules" OFF)
option(DAQMODULES_OPENDAQ_SERVER_MODULE "Building of ${SDK_NAME} server modules" OFF)
option(DAQMODULES_EMPTY_MODULE "Building of demo module" OFF)
option(DAQMODULES_AUDIO_DEVICE_MODULE "Building of audio device module" OFF)
option(DAQMODULES_REF_DEVICE_MODULE "Building of reference device module" OFF)
option(DAQMODULES_WASA_200_DEVICE_MODULE "Building of MSCL device module" OFF)
option(DAQMODULES_REF_FB_MODULE "Building of reference function block module" OFF)
cmake_dependent_option(DAQMODULES_REF_FB_MODULE_ENABLE_RENDERER "Enable renderer function block" ON "DAQMODULES_REF_FB_MODULE" ON)
# logging
include(openDAQLogging)
set(OPENDAQ_LOG_LEVEL_DEBUG "Debug" CACHE STRING "Compile time logging level for debug builds")
set_property(CACHE OPENDAQ_LOG_LEVEL_DEBUG PROPERTY STRINGS ${OPENDAQ_LOG_LEVELS})
log_level_str_to_int(${OPENDAQ_LOG_LEVEL_DEBUG} OPENDAQ_LOG_LEVEL_DEBUG_INT)
set(OPENDAQ_LOG_LEVEL_RELEASE "Info" CACHE STRING "Compile time logging level for release builds")
set_property(CACHE OPENDAQ_LOG_LEVEL_RELEASE PROPERTY STRINGS ${OPENDAQ_LOG_LEVELS})
log_level_str_to_int(${OPENDAQ_LOG_LEVEL_RELEASE} OPENDAQ_LOG_LEVEL_RELEASE_INT)
add_compile_definitions(OPENDAQ_LOG_LEVEL=$<IF:$<CONFIG:Debug>,${OPENDAQ_LOG_LEVEL_DEBUG_INT},${OPENDAQ_LOG_LEVEL_RELEASE_INT}>)
set(OPENDAQ_REPO_PREFIX "https://github.com/openDAQ" CACHE STRING "Set this if using a repository mirror")
message(STATUS "${SDK_NAME} repository prefix: ${OPENDAQ_REPO_PREFIX}")
include(CMakePrintHelpers)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
set(OPENDAQ_SOURCE_DIR ${PROJECT_SOURCE_DIR})
set(FETCHCONTENT_EXTERNALS_DIR ${ROOT_DIR}/build/__external CACHE PATH "FetchContent folder prefix")
if (NOT OPENDAQ_CI_RUNNER)
set(OPENDAQ_CI_RUNNER OFF)
endif()
if (OPENDAQ_CI_RUNNER)
message("Configured as CI runner")
add_compile_definitions(DS_CI_RUNNER=1)
set(OPENDAQ_DEBUG_WARNINGS_AS_ERRORS ON)
endif()
if (COMMAND get_mode)
get_mode(CMAKE_MODE)
message(STATUS "CMake Mode is ${CMAKE_MODE}")
endif()
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
set(CMAKE_COMPILER_IS_CLANGXX On CACHE INTERNAL "Compiler is LLVM Clang")
endif ()
if (UNIX AND (CMAKE_COMPILER_IS_CLANGXX OR CMAKE_COMPILER_IS_GNUXX))
# hide all symbols expect those specifically exported with PUBLIC_EXPORT macro
if (APPLE)
# not possible on Mac, should be done per library
else()
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,--exclude-libs,ALL")
endif()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvisibility=hidden -fvisibility-inlines-hidden")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fvisibility=hidden -fvisibility-inlines-hidden")
endif()
string(TIMESTAMP CONFIGURE_DATE)
string(TIMESTAMP CURRENT_YEAR "%Y")
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
if (UNIX AND ${CMAKE_SYSTEM_PROCESSOR} MATCHES "^arm.*$") #e.g. armv7l
set(BUILD_ARM On CACHE INTERNAL "Build for ARM architecture")
endif()
if (UNIX AND ${CMAKE_SYSTEM_PROCESSOR} MATCHES "^aarch.*$") #e.g. aarch64
set(BUILD_ARM On CACHE INTERNAL "Build for ARM architecture")
endif()
include(DaqUtils)
opendaq_is_64bit_build(BUILD_64Bit)
set(BUILD_64Bit ${BUILD_64Bit} CACHE INTERNAL "Build in 64-bit mode")
if(BUILD_64Bit OR BUILD_ARM)
set(OPENDAQ_FPIC On CACHE INTERNAL "Set Position independent code flag")
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
else()
set(OPENDAQ_FPIC Off CACHE INTERNAL "Set Position independent code flag")
endif()
if (NOT BUILDING_AS_SUBMODULE)
message(STATUS "Platform: ${CMAKE_SYSTEM_PROCESSOR} | ${CMAKE_SYSTEM_NAME} ${CMAKE_SYSTEM_VERSION}")
message(STATUS "Generator: ${CMAKE_GENERATOR} | ${CMAKE_GENERATOR_PLATFORM}")
message(STATUS "Build type: ${CMAKE_BUILD_TYPE}")
message(STATUS "Setting -fPIC to ${OPENDAQ_FPIC}")
endif()
if(NOT CMAKE_DEBUG_POSTFIX AND NOT OPENDAQ_DISABLE_DEBUG_POSTFIX)
set(CMAKE_DEBUG_POSTFIX -debug)
endif()
if (OPENDAQ_ENABLE_COVERAGE)
if(NOT OPENDAQ_ENABLE_TESTS)
message(FATAL_ERROR "Coverage enabled, but testing disabled. Enable testing")
endif()
if(CMAKE_COMPILER_IS_GNUCXX OR MSVC)
message(STATUS "Coverage enabled")
else()
message(FATAL_ERROR "Coverage supported only for GCC, G++ and MSVC")
endif()
include(CodeCoverage)
endif()
if (OPENDAQ_ENABLE_TESTS)
message(STATUS "Unit tests are ENABLED")
enable_testing()
if (NOT gtest IN_LIST TESTING_LIBS)
set(TESTING_LIBS gtest gmock ${TESTING_LIBS})
endif()
set(gtest_force_shared_crt On CACHE BOOL "Force shared CRT")
if (OPENDAQ_ENABLE_DELPHI_BINDINGS_TESTS)
if (WIN32)
if ("${DELPHI_BIN_DIR}" STREQUAL "" AND NOT "$ENV{DELPHI_BIN_DIR}" STREQUAL "")
set(DELPHI_BIN_DIR $ENV{DELPHI_BIN_DIR})
endif()
find_program(DELPHI_RSVARS rsvars.bat PATHS ${DELPHI_BIN_DIR})
if (NOT DELPHI_RSVARS)
message(FATAL_ERROR "Delphi not found, set DELPHI_BIN_DIR variable. Delphi bindings will not be tested!")
else()
message(STATUS "Delphi found: ${DELPHI_RSVARS}")
endif()
else()
message(FATAL_ERROR "Delphi bindings only available in Windows")
endif()
endif()
else()
message(STATUS "Unit tests are DISABLED")
endif()
set(CMAKE_CXX_STANDARD 17)
if (WIN32)
set(MIN_WINDOWS_VERSION 0x0601)
add_compile_definitions(NOMINMAX
_WIN32_WINNT=${MIN_WINDOWS_VERSION} # Windows 7 Compat
)
add_compile_definitions(UNICODE _UNICODE)
endif()
if (NOT COMMAND set_mode)
message(STATUS "Including Modern.cmake")
include(Modern)
else()
set_mode(MODERN)
endif()
# module suffix
if (NOT DEFINED OPENDAQ_MODULE_SUFFIX)
set(OPENDAQ_MODULE_SUFFIX ".module${CMAKE_SHARED_LIBRARY_SUFFIX}")
endif()
if (NOT DEFINED CACHE{OPENDAQ_MODULE_SUFFIX})
set(OPENDAQ_MODULE_SUFFIX ${OPENDAQ_MODULE_SUFFIX} CACHE INTERNAL "Default DLL/SO extension")
endif()
message(STATUS "Default Module extension: ${OPENDAQ_MODULE_SUFFIX}")
add_compile_definitions(OPENDAQ_MODULE_SUFFIX="${OPENDAQ_MODULE_SUFFIX}")
if ((CMAKE_COMPILER_IS_GNUCXX OR CMAKE_COMPILER_IS_CLANGXX) AND NOT MSVC)
option(OPENDAQ_FORCE_LLD_LINKER "Force the use of the fast LLVM LLD linker" OFF)
if (NOT WIN32)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread")
endif()
if(OPENDAQ_FORCE_COMPILE_32BIT)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -m32")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -m32")
set(BUILD_64Bit OFF)
endif()
# The flag -fuse-ld=lld is needed on MinGW where the default linker is hardly usable.
# It is not available on macOS (it is ignored though, unless you pass -Werror).
# It might be default on Linux distros, but it might not be always available.
# The following code just says "use LLD whenever it seems feasible".
check_linker_flag(CXX "-fuse-ld=lld" COMPILER_SUPPORTS_LLD_LINKER)
if(COMPILER_SUPPORTS_LLD_LINKER)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fuse-ld=lld")
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -fuse-ld=lld")
set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} -fuse-ld=lld")
message(STATUS "LLD Linker enabled")
endif()
endif()
if (CMAKE_COMPILER_IS_GNUCXX)
set(GCC_W_NO_EXTRA "-Wno-comment -Wno-unused-parameter -Wno-missing-field-initializers")
set(GCC_W_NO_WALL "-Wno-unknown-pragmas -Wno-parentheses -Wno-misleading-indentation -Wno-unused-variable -Wno-switch -Wno-maybe-uninitialized -Wno-psabi")
set(GCC_CHARSET_FLAGS "-fexec-charset=UTF-8 -finput-charset=UTF-8")
#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pedantic -Wall -Wextra ${GCC_W_NO_EXTRA} ${GCC_W_NO_WALL} ${GCC_W_NO_PEDANTIC} -Werror=return-type")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra ${GCC_W_NO_EXTRA} ${GCC_W_NO_WALL} ${GCC_W_NO_PEDANTIC} -Werror=return-type ${GCC_CHARSET_FLAGS}")
# Treat warnings as errors if OPENDAQ_<DEBUG|RELEASE>_WARNINGS_AS_ERRORS is ON
add_compile_options($<$<OR:$<AND:$<CONFIG:Debug>,$<BOOL:${OPENDAQ_DEBUG_WARNINGS_AS_ERRORS}>>,$<AND:$<NOT:$<CONFIG:Debug>>,$<BOOL:${OPENDAQ_RELEASE_WARNINGS_AS_ERRORS}>>>:-Werror>)
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -g -ggdb")
if (MINGW)
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,--exclude-all-symbols")
endif()
if (APPLE)
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,-undefined,error")
else()
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,--no-undefined")
endif()
if (OPENDAQ_ENABLE_COVERAGE)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --coverage -fprofile-arcs -ftest-coverage -fno-elide-constructors")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} --coverage -fprofile-arcs -ftest-coverage")
endif()
if (WIN32 AND NOT BUILD_64Bit)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mfpmath=sse -msse2")
endif()
if (NOT (WIN32 OR APPLE))
if (NOT DEFINED HAVE_SPLIT_DWARF)
check_compiler_flag(CXX "-gsplit-dwarf" HAVE_SPLIT_DWARF)
endif()
if (HAVE_SPLIT_DWARF)
# Only add for debug builds, but could also expand the
# generator expression to add for RelWithDebInfo too
add_compile_options("$<$<CONFIG:Debug>:-gsplit-dwarf>")
endif()
endif()
if (OPENDAQ_FORCE_LLD_LINKER)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fuse-ld=lld")
endif()
endif()
if(CMAKE_COMPILER_IS_CLANGXX)
# MinGW Clang does not support TLS so try emulating it
if (MINGW)
add_compile_options(-femulated-tls)
endif()
endif()
if (OPENDAQ_FORCE_LLD_LINKER)
message(STATUS "Forcing the use of LLVM LLD linker. Make sure it is installed and available.")
endif()
if (MSVC)
# As above CMAKE_CXX_STANDARD but for VS
add_compile_options($<$<COMPILE_LANGUAGE:CXX>:/std:c++17>)
foreach (flag IN ITEMS
# Set source and execution character sets to UTF-8
# https://learn.microsoft.com/en-us/cpp/build/reference/utf-8-set-source-and-executable-character-sets-to-utf-8
/utf-8
# Display level 1, level 2, and level 3 warnings, and all level 4 (informational) warnings that aren't off by default.
# https://learn.microsoft.com/en-us/cpp/build/reference/compiler-option-warning-level
/W4
# data member 'member1' will be initialized after data member 'member2'
# https://learn.microsoft.com/en-us/cpp/error-messages/compiler-warnings/c5038
/w15038
# Supress warnings
# https://learn.microsoft.com/en-us/cpp/build/reference/compiler-option-warning-level
#
# 'class1' : inherits 'class2::member' via dominance
# https://learn.microsoft.com/en-us/cpp/error-messages/compiler-warnings/compiler-warning-level-2-c4250
/wd4250
# Your code uses a function, class member, variable, or typedef that's marked deprecated.
# https://learn.microsoft.com/en-us/cpp/error-messages/compiler-warnings/compiler-warning-level-3-c4996
/wd4996
# declaration of 'identifier' hides class member
# https://learn.microsoft.com/en-us/cpp/error-messages/compiler-warnings/compiler-warning-level-4-c4458
/wd4458
# nonstandard extension used : nameless struct/union
# https://learn.microsoft.com/en-us/cpp/error-messages/compiler-warnings/compiler-warning-level-4-c4201
/wd4201
# unreachable code
# https://learn.microsoft.com/en-us/cpp/error-messages/compiler-warnings/compiler-warning-level-4-c4702
/wd4702
# declaration of 'identifier' hides global declaration
# https://learn.microsoft.com/en-us/cpp/error-messages/compiler-warnings/compiler-warning-level-4-c4459
/wd4459
# 'function' : unreferenced local function has been removed
# https://learn.microsoft.com/en-us/cpp/error-messages/compiler-warnings/compiler-warning-level-4-c4505
/wd4505
# conditional expression is constant
# https://learn.microsoft.com/en-us/cpp/error-messages/compiler-warnings/compiler-warning-level-4-c4127
/wd4127
# assignment within conditional expression
# https://learn.microsoft.com/en-us/cpp/error-messages/compiler-warnings/compiler-warning-level-4-c4706
/wd4706
# loss of data / precision, unsigned <--> signed
#
# 'argument' : conversion from 'type1' to 'type2', possible loss of data
# https://learn.microsoft.com/en-us/cpp/error-messages/compiler-warnings/compiler-warning-level-2-c4244
/wd4244
# 'var' : conversion from 'size_t' to 'type', possible loss of data
# https://learn.microsoft.com/en-us/cpp/error-messages/compiler-warnings/compiler-warning-level-3-c4267
/wd4267
)
add_compile_options($<$<COMPILE_LANGUAGE:C,CXX>:${flag}>)
endforeach()
# Maintain binary compatibilty with older msvc runtime environments
# https://github.com/microsoft/STL/wiki/Changelog
add_compile_definitions(_DISABLE_CONSTEXPR_MUTEX_CONSTRUCTOR)
if (NOT OPENDAQ_MSVC_SINGLE_PROCESS_BUILD)
# Build with multiple processes
# https://learn.microsoft.com/en-us/cpp/build/reference/mp-build-with-multiple-processes
add_compile_options($<$<COMPILE_LANGUAGE:C,CXX>:/MP>)
endif()
# Treat warnings as errors if OPENDAQ_<DEBUG|RELEASE>_WARNINGS_AS_ERRORS is ON
add_compile_options($<$<OR:$<AND:$<CONFIG:Debug>,$<BOOL:${OPENDAQ_DEBUG_WARNINGS_AS_ERRORS}>>,$<AND:$<NOT:$<CONFIG:Debug>>,$<BOOL:${OPENDAQ_RELEASE_WARNINGS_AS_ERRORS}>>>:/WX>)
if (MSVC_VERSION GREATER_EQUAL 1910)
# /Zc:__cplusplus forces MSVC to use the correct value of __cplusplus macro (otherwise always C++98)
add_compile_options($<$<COMPILE_LANGUAGE:CXX>:/Zc:__cplusplus>)
if (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
# /Zf (Faster PDB generation) is not supported by ClangCL
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /Zf")
endif()
# Produce diagnostic messages with exact location
add_compile_options($<$<COMPILE_LANGUAGE:C,CXX>:/diagnostics:caret>)
endif()
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} /ignore:4221")
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} /ignore:4221")
set(CMAKE_STATIC_LINKER_FLAGS "${CMAKE_STATIC_LINKER_FLAGS} /ignore:4221")
set(CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO "${CMAKE_EXE_LINKER_FLAGS} /DEBUG /OPT:REF /OPT:ICF")
set(CMAKE_MODULE_LINKER_FLAGS_RELWITHDEBINFO "${CMAKE_MODULE_LINKER_FLAGS} /DEBUG /OPT:REF /OPT:ICF")
set(CMAKE_SHARED_LINKER_FLAGS_RELWITHDEBINFO "${CMAKE_SHARED_LINKER_FLAGS} /DEBUG /OPT:REF /OPT:ICF")
set(CMAKE_STATIC_LINKER_FLAGS_RELWITHDEBINFO "${CMAKE_STATIC_LINKER_FLAGS} /DEBUG /OPT:REF /OPT:ICF")
if(OPENDAQ_ENABLE_COVERAGE)
# /PROFILE add profiler info to PDB
# /OPT:NOREF do not omit unreferenced files/functions/classes in the PDB (would hide completely untested code)
#set(CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS} /PROFILE /OPT:NOREF")
set(CMAKE_MODULE_LINKER_FLAGS_DEBUG "${CMAKE_MODULE_LINKER_FLAGS} /PROFILE /OPT:NOREF")
set(CMAKE_SHARED_LINKER_FLAGS_DEBUG "${CMAKE_SHARED_LINKER_FLAGS} /PROFILE /OPT:NOREF")
set(CMAKE_STATIC_LINKER_FLAGS_DEBUG "${CMAKE_STATIC_LINKER_FLAGS} /PROFILE /OPT:NOREF")
endif()
endif()
# Sanitizers
if (CMAKE_COMPILER_IS_GNUCXX)
set(OPENDAQ_SANITIZER "" CACHE STRING "Add sanitizers. Options are: thread, address, ...")
if (NOT "${OPENDAQ_SANITIZER}" STREQUAL "")
set(SANITIZE_SWITCH "-fsanitize=${OPENDAQ_SANITIZER}")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${SANITIZE_SWITCH}")
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} ${SANITIZE_SWITCH}")
#set(CMAKE_STATIC_LINKER_FLAGS "${CMAKE_STATIC_LINKER_FLAGS} ${SANITIZE_SWITCH}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${SANITIZE_SWITCH}")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${SANITIZE_SWITCH}")
endif()
endif()
if(OPENDAQ_GENERATE_PYTHON_BINDINGS OR OPENDAQ_ENABLE_COVERAGE) #gcc coverage
set(OPENDAQ_PYTHON_VERSION_INTERNAL 3.8)
set(OPENDAQ_PYTHON_COMPONENTS Interpreter)
if(OPENDAQ_GENERATE_PYTHON_BINDINGS)
list(APPEND OPENDAQ_PYTHON_COMPONENTS Development.Module)
endif()
set(OPENDAQ_PYTHON_VERSION "" CACHE STRING "Exact Python version to use for bindings generation")
if(OPENDAQ_PYTHON_VERSION)
set(OPENDAQ_PYTHON_VERSION_INTERNAL ${OPENDAQ_PYTHON_VERSION})
set(OPENDAQ_PYTHON_EXACT EXACT)
set(OPENDAQ_PYTHON_REQUIRED REQUIRED)
endif()
find_package(Python ${OPENDAQ_PYTHON_VERSION_INTERNAL} ${OPENDAQ_PYTHON_EXACT} ${OPENDAQ_PYTHON_REQUIRED} COMPONENTS ${OPENDAQ_PYTHON_COMPONENTS})
#help pybind11 find the correct python version
set(PYTHON_EXECUTABLE ${Python_EXECUTABLE})
endif()
if (MSVC)
set(FLEX_FLAGS "--wincompat")
endif()
set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads REQUIRED)
find_package(Filesystem REQUIRED COMPONENTS Final Experimental)
if(OPENDAQ_GENERATE_DELPHI_BINDINGS OR OPENDAQ_GENERATE_PYTHON_BINDINGS OR OPENDAQ_GENERATE_CSHARP_BINDINGS)
set(OPENDAQ_GENERATE_BINDINGS On)
endif()
if(OPENDAQ_ENABLE_DELPHI_BINDINGS_TESTS OR OPENDAQ_ENABLE_PYTHON_BINDINGS_TESTS OR OPENDAQ_ENABLE_CSHARP_BINDINGS_TESTS)
set(TEST_BINDINGS On)
endif()
set(OPENDAQ_GENERATE_BINDINGS_LANG "")
if(OPENDAQ_GENERATE_DELPHI_BINDINGS)
message(STATUS "Generating Delphi bindings")
set(OPENDAQ_GENERATE_BINDINGS_LANG ${OPENDAQ_GENERATE_BINDINGS_LANG} Delphi)
endif()
if(OPENDAQ_GENERATE_PYTHON_BINDINGS)
message(STATUS "Generating Python bindings")
set(OPENDAQ_GENERATE_BINDINGS_LANG ${OPENDAQ_GENERATE_BINDINGS_LANG} Python)
endif()
if(OPENDAQ_GENERATE_CSHARP_BINDINGS)
message(STATUS "Generating C# bindings")
set(OPENDAQ_GENERATE_BINDINGS_LANG ${OPENDAQ_GENERATE_BINDINGS_LANG} CSharp)
endif()
if(OPENDAQ_LINK_RUNTIME_STATICALLY)
opendaq_set_runtime(STATIC)
endif()
add_compile_definitions(BOOST_ALL_NO_LIB=1)
set(RTGEN_NAMESPACE ${SDK_TARGET_NAMESPACE})
include(RTGen)
set(CMAKE_INSTALL_DEBUG_LIBRARIES ON)
include(InstallRequiredSystemLibraries)
if (NOT WIN32)
set(MONO_C mono)
endif()
set(RTGEN "${CMAKE_CURRENT_SOURCE_DIR}/shared/tools/RTGen/bin/rtgen.exe" CACHE INTERNAL "RTGEN")
execute_process(COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/.editorconfig ${CMAKE_BINARY_DIR})
execute_process(COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/.clang-format ${CMAKE_BINARY_DIR})
if (OPENDAQ_ENABLE_OPTIONAL_TESTS)
set(OPENDAQ_ENABLE_OPTIONAL_TESTS ON CACHE BOOL "Enable optional (debugging) tests")
message(STATUS "Optional tests enabled")
add_compile_definitions(OPENDAQ_ENABLE_OPTIONAL_TESTS)
set(OPENDAQ_TEST_COMPILE_DEFINES "OPENDAQ_ENABLE_OPTIONAL_TESTS=1")
endif()
if (OPENDAQ_ENABLE_PARAMETER_VALIDATION)
message(STATUS "Parameter validation enabled")
else()
message(STATUS "Parameter validation disabled")
endif()
if (OPENDAQ_THREAD_SAFE)
message(STATUS "Thread-safe implementations enabled")
else()
message(STATUS "Thread-safe implementations disabled")
endif()
if (OPENDAQ_MIMALLOC_SUPPORT)
message(STATUS "MiMalloc allocator enabled")
add_compile_definitions(OPENDAQ_MIMALLOC_SUPPORT)
else()
message(STATUS "MiMalloc allocator disabled")
endif()
if (OPENDAQ_ENABLE_WEBSOCKET_STREAMING)
message(STATUS "Websocket streaming enabled")
add_compile_definitions(OPENDAQ_ENABLE_WEBSOCKET_STREAMING)
else()
message(STATUS "Websocket streaming disabled")
endif()
if (OPENDAQ_ENABLE_NATIVE_STREAMING)
message(STATUS "Native streaming enabled")
add_compile_definitions(OPENDAQ_ENABLE_NATIVE_STREAMING)
else()
message(STATUS "Native streaming disabled")
endif()
use_compiler_cache()
if (WIN32)
add_compile_definitions(WIN32_LEAN_AND_MEAN)
endif()
# libraries needed before the core is read
add_subdirectory(external)
if(CMAKE_COMPILER_IS_CLANGXX)
set(CLANG_FLAGS "\
-Wno-unused-variable \
-Wno-missing-braces \
-Wno-unused-function \
-Wno-logical-op-parentheses \
-Wno-unused-variable \
-Werror=return-type \
-Wno-deprecated-declarations \
-Wno-undef \
-Wno-incompatible-pointer-types \
-Wno-unused-parameter \
-Wno-misleading-indentation \
-Wno-missing-field-initializers"
)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CLANG_FLAGS}")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${CLANG_FLAGS}")
# Treat warnings as errors if OPENDAQ_<DEBUG|RELEASE>_WARNINGS_AS_ERRORS is ON
add_compile_options($<$<OR:$<AND:$<CONFIG:Debug>,$<BOOL:${OPENDAQ_DEBUG_WARNINGS_AS_ERRORS}>>,$<AND:$<NOT:$<CONFIG:Debug>>,$<BOOL:${OPENDAQ_RELEASE_WARNINGS_AS_ERRORS}>>>:-Werror>)
endif()
add_subdirectory(core)
add_subdirectory(modules)
add_subdirectory(bindings)
add_subdirectory(shared)
add_subdirectory(app)
add_subdirectory(examples)
add_subdirectory(docs)
add_subdirectory(simulator)
if (OPENDAQ_ENABLE_REGRESSION_TESTS)
add_subdirectory(regression)
endif()
if (NOT BUILDING_AS_SUBMODULE)
set_property(GLOBAL PROPERTY PREDEFINED_TARGETS_FOLDER ".CMakePredefinedTargets")
endif()
if (NOT WIN32)
set(INSTALLED_MODULES_DIR ${CMAKE_INSTALL_LIBDIR})
else()
set(INSTALLED_MODULES_DIR ${CMAKE_INSTALL_BINDIR})
endif()
set(INSTALLED_CMAKE_CONFIG_DIR ${CMAKE_INSTALL_LIBDIR}/cmake)
include(CMakePackageConfigHelpers)
configure_package_config_file(
cmake/${SDK_NAME}Config.cmake.in ${SDK_NAME}Config.cmake
INSTALL_DESTINATION ${INSTALLED_CMAKE_CONFIG_DIR}/${SDK_TARGET_NAME}
PATH_VARS
CMAKE_INSTALL_DATAROOTDIR
INSTALLED_MODULES_DIR
INSTALLED_CMAKE_CONFIG_DIR
NO_SET_AND_CHECK_MACRO
NO_CHECK_REQUIRED_COMPONENTS_MACRO
)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${SDK_NAME}Config.cmake
DESTINATION ${INSTALLED_CMAKE_CONFIG_DIR}/${SDK_TARGET_NAME}
COMPONENT ${SDK_NAME}_Development
)
install(FILES cmake/${SDK_NAME}Utils.cmake
DESTINATION share/cmake
COMPONENT ${SDK_NAME}_Development
)
install(EXPORT ${SDK_NAME}
NAMESPACE ${SDK_TARGET_NAMESPACE}::
FILE ${SDK_NAME}.cmake
DESTINATION ${INSTALLED_CMAKE_CONFIG_DIR}/${SDK_TARGET_NAME}
COMPONENT ${SDK_NAME}_Development
)
set(OPENDAQ_CONFIGURED_ONCE TRUE CACHE INTERNAL "A flag showing that CMake has configured at least once.")
include(cmake/Packing.cmake)