forked from netdata/netdata
-
Notifications
You must be signed in to change notification settings - Fork 1
/
CMakeLists.txt
3047 lines (2657 loc) · 109 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
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# SPDX-License-Identifier: GPL-3.0-or-later
cmake_minimum_required(VERSION 3.13.0...3.28)
#
# version atrocities
#
find_package(Git)
if(GIT_EXECUTABLE)
execute_process(COMMAND ${GIT_EXECUTABLE} describe
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
RESULT_VARIABLE GIT_DESCRIBE_RESULT
OUTPUT_VARIABLE GIT_DESCRIBE_OUTPUT)
if(GIT_DESCRIBE_RESULT)
file(STRINGS packaging/version GIT_DESCRIBE_OUTPUT)
message(WARNING "using version from packaging/version: '${GIT_DESCRIBE_OUTPUT}'")
endif()
else()
file(STRINGS packaging/version GIT_DESCRIBE_OUTPUT)
message(WARNING "using version from packaging/version: '${GIT_DESCRIBE_OUTPUT}'")
endif()
string(STRIP ${GIT_DESCRIBE_OUTPUT} GIT_DESCRIBE_OUTPUT)
string(REGEX MATCH "v?([0-9]+)\\.([0-9]+)\\.([0-9]+)-?([0-9]+)?-?([0-9a-zA-Z]+)?" MATCHES "${GIT_DESCRIBE_OUTPUT}")
if(CMAKE_MATCH_COUNT EQUAL 3)
set(FIELD_MAJOR ${CMAKE_MATCH_1})
set(FIELD_MINOR ${CMAKE_MATCH_2})
set(FIELD_PATCH ${CMAKE_MATCH_3})
set(FIELD_TWEAK 0)
set(FIELD_DESCR "N/A")
elseif(CMAKE_MATCH_COUNT EQUAL 4)
set(FIELD_MAJOR ${CMAKE_MATCH_1})
set(FIELD_MINOR ${CMAKE_MATCH_2})
set(FIELD_PATCH ${CMAKE_MATCH_3})
set(FIELD_TWEAK ${CMAKE_MATCH_4})
set(FIELD_DESCR "N/A")
elseif(CMAKE_MATCH_COUNT EQUAL 5)
set(FIELD_MAJOR ${CMAKE_MATCH_1})
set(FIELD_MINOR ${CMAKE_MATCH_2})
set(FIELD_PATCH ${CMAKE_MATCH_3})
set(FIELD_TWEAK ${CMAKE_MATCH_4})
set(FIELD_DESCR ${CMAKE_MATCH_5})
else()
message(FATAL_ERROR "Wrong version regex match count ${CMAKE_MATCH_COUNT} (should be in 3, 4 or 5)")
endif()
set(NETDATA_VERSION ${FIELD_MAJOR}.${FIELD_MINOR}.${FIELD_PATCH}.${FIELD_TWEAK})
if(FIELD_DESCR STREQUAL "N/A")
set(CPACK_PACKAGE_VERSION ${FIELD_MAJOR}.${FIELD_MINOR}.${FIELD_PATCH})
else()
set(CPACK_PACKAGE_VERSION ${FIELD_MAJOR}.${FIELD_MINOR}.${FIELD_PATCH}-${FIELD_TWEAK}-${FIELD_DESCR})
endif()
#
# project
#
project(netdata
VERSION ${NETDATA_VERSION}
HOMEPAGE_URL "https://www.netdata.cloud"
LANGUAGES C CXX)
list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/packaging/cmake/Modules")
include(CMakeDependentOption)
find_package(PkgConfig REQUIRED)
set(CMAKE_C_STANDARD 11)
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_INSTALL_DEFAULT_COMPONENT_NAME "netdata")
option(USE_CXX_11 "Use C++11 instead of C++14 (should only be used on legacy systems that cannot support C++14, may disable some features)" False)
mark_as_advanced(USE_CXX_11)
if(USE_CXX_11)
set(CMAKE_CXX_STANDARD 11)
endif()
set(CMAKE_C_STANDARD_REQUIRED On)
set(CMAKE_CXX_STANDARD_REQUIRED On)
set(SIZEOF_VOID_P ${CMAKE_SIZEOF_VOID_P})
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "Release")
endif()
include(NetdataCompilerFlags)
set(CMAKE_EXPORT_COMPILE_COMMANDS On)
# Check for the mold linker and try to use it if available
option(USE_MOLD "If the MOLD linker is available on the system, use it instead of the default linker." TRUE)
if(USE_MOLD)
message(CHECK_START "Searching for MOLD linker")
find_program(MOLD_LINKER NAMES ld.mold mold)
if(MOLD_LINKER)
execute_process(COMMAND ${MOLD_LINKER} --version
RESULT_VARIABLE MOLD_VERSION_RESULT
OUTPUT_VARIABLE MOLD_VERSION)
if(NOT MOLD_VERSION_RESULT)
string(REPLACE "\n" "" MOLD_VERSION "${MOLD_VERSION}")
message(CHECK_PASS "found (version: ${MOLD_VERSION})")
message(STATUS "Using mold instead of the system default for linking.")
add_compile_options("-fuse-ld=mold")
add_link_options("-fuse-ld=mold")
else()
message(CHECK_FAIL "failed")
endif()
else()
message(CHECK_FAIL "failed")
endif()
endif()
set(CONFIG_H_DIR ${CMAKE_BINARY_DIR})
set(CONFIG_H ${CONFIG_H_DIR}/config.h)
# This is intended to make life easier for developers who are working on one
# specific feature.
option(DEFAULT_FEATURE_STATE "Specify the default state for most optional features" True)
mark_as_advanced(DEFAULT_FEATURE_STATE)
# High-level features
option(ENABLE_ACLK "Enable Netdata Cloud support (ACLK)" ${DEFAULT_FEATURE_STATE})
option(ENABLE_CLOUD "Enable Netdata Cloud by default at runtime" ${DEFAULT_FEATURE_STATE})
option(ENABLE_ML "Enable machine learning features" ${DEFAULT_FEATURE_STATE})
option(ENABLE_DBENGINE "Enable dbengine metrics storage" True)
# Data collection plugins
option(ENABLE_PLUGIN_APPS "Enable per-process resource usage monitoring" ${DEFAULT_FEATURE_STATE})
option(ENABLE_PLUGIN_CGROUP_NETWORK "Enable Linux CGroup network usage monitoring" ${DEFAULT_FEATURE_STATE})
option(ENABLE_PLUGIN_CUPS "Enable CUPS monitoring" ${DEFAULT_FEATURE_STATE})
option(ENABLE_PLUGIN_DEBUGFS "Enable Linux DebugFS metric collection" ${DEFAULT_FEATURE_STATE})
option(ENABLE_PLUGIN_EBPF "Enable Linux eBPF metric collection" ${DEFAULT_FEATURE_STATE})
cmake_dependent_option(ENABLE_LEGACY_EBPF_PROGRAMS "Enable eBPF programs for kernels without BTF support" True ENABLE_PLUGIN_EBPF False)
mark_as_advanced(ENABLE_LEGACY_EBPF_PROGRAMS)
option(ENABLE_PLUGIN_FREEIPMI "Enable IPMI monitoring" ${DEFAULT_FEATURE_STATE})
option(ENABLE_PLUGIN_GO "Enable metric collectors written in Go" ${DEFAULT_FEATURE_STATE})
option(ENABLE_PLUGIN_LOCAL_LISTENERS "Enable local listening socket tracking (including service auto-discovery support)" ${DEFAULT_FEATURE_STATE})
option(ENABLE_PLUGIN_LOGS_MANAGEMENT "Enable log collection and monitoring based on Fluent Bit" ${DEFAULT_FEATURE_STATE})
option(ENABLE_PLUGIN_NETWORK_VIEWER "Enable network viewer functionality" ${DEFAULT_FEATURE_STATE})
option(ENABLE_PLUGIN_NFACCT "Enable Linux NFACCT metric collection" ${DEFAULT_FEATURE_STATE})
option(ENABLE_PLUGIN_PERF "Enable Linux performance counter monitoring" ${DEFAULT_FEATURE_STATE})
option(ENABLE_PLUGIN_SLABINFO "Enable Linux kernel SLAB allocator monitoring" ${DEFAULT_FEATURE_STATE})
option(ENABLE_PLUGIN_SYSTEMD_JOURNAL "Enable systemd journal log collection" ${DEFAULT_FEATURE_STATE})
option(ENABLE_PLUGIN_XENSTAT "Enable Xen domain monitoring" ${DEFAULT_FEATURE_STATE})
# Metrics exporters
option(ENABLE_EXPORTER_PROMETHEUS_REMOTE_WRITE "Enable exporting to Prometheus via remote write API" ${DEFAULT_FEATURE_STATE})
option(ENABLE_EXPORTER_MONGODB "Enable exporting to MongoDB" ${DEFAULT_FEATURE_STATE})
# Vendoring
option(ENABLE_BUNDLED_JSONC "Force use of a vendored copy of JSON-C" False)
option(ENABLE_BUNDLED_YAML "Force use of a vendored copy of libyaml" False)
option(ENABLE_BUNDLED_PROTOBUF "Use a vendored copy of protobuf" False)
# Optional test code
cmake_dependent_option(ENABLE_LOGS_MANAGEMENT_TESTS "Enable test code for logs-management plugin." True "NOT ENABLE_PLUGIN_LOGS_MANAGEMENT" False)
mark_as_advanced(ENABLE_LOGS_MANAGEMENT_TESTS)
# Experimental features
option(ENABLE_WEBRTC "Enable WebRTC dashboard communications (experimental)" False)
mark_as_advanced(ENABLE_WEBRTC)
option(ENABLE_H2O "Enable H2O web server (experimental)" True)
mark_as_advanced(ENABLE_H2O)
# Other optional functionality
option(ENABLE_SENTRY "Build with Sentry Native crash reporting" False)
mark_as_advanced(ENABLE_SENTRY)
option(BUILD_FOR_PACKAGING "Include component files for native packages" False)
mark_as_advanced(BUILD_FOR_PACKAGING)
cmake_dependent_option(FORCE_LEGACY_LIBBPF "Force usage of libbpf 0.0.9 instead of the latest version." False "ENABLE_PLUGIN_EBPF" False)
mark_as_advanced(FORCE_LEGACY_LIBBPF)
if(ENABLE_ACLK OR ENABLE_EXPORTER_PROMETHEUS_REMOTE_WRITE)
set(NEED_PROTOBUF True)
else()
set(NEED_PROTOBUF False)
endif()
if(ENABLE_PLUGIN_GO)
include(NetdataGoTools)
find_min_go_version("${CMAKE_SOURCE_DIR}/src/go")
find_package(Go "${MIN_GO_VERSION}" REQUIRED)
endif()
if(ENABLE_WEBRTC)
include(FetchContent)
# ignore debhelper
set(FETCHCONTENT_FULLY_DISCONNECTED Off)
set(PREFER_SYSTEM_LIB True)
set(NO_MEDIA True)
set(NO_WEBSOCKET True)
set(HAVE_LIBDATACHANNEL True)
FetchContent_Declare(libdatachannel
GIT_REPOSITORY https://github.com/paullouisageneau/libdatachannel.git
GIT_TAG v0.20.1
)
FetchContent_MakeAvailable(libdatachannel)
endif()
if(NEED_PROTOBUF)
include(NetdataProtobuf)
if(ENABLE_BUNDLED_PROTOBUF)
netdata_bundle_protobuf()
endif()
endif()
#
# detect OS
#
set(LINUX False)
set(FREEBSD False)
set(MACOS False)
set(WINDOWS False)
set(FOREIGN_OS False)
if("${CMAKE_SYSTEM_NAME}" STREQUAL "Darwin")
set(MACOS True)
set(COMPILED_FOR_MACOS True)
find_library(IOKIT IOKit)
find_library(FOUNDATION Foundation)
message(INFO " Compiling for MacOS... ")
elseif("${CMAKE_SYSTEM_NAME}" STREQUAL "FreeBSD")
set(FREEBSD True)
set(COMPILED_FOR_FREEBSD True)
message(INFO " Compiling for FreeBSD... ")
elseif("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux")
set(LINUX True)
set(COMPILED_FOR_LINUX True)
add_definitions(-D_GNU_SOURCE)
message(INFO " Compiling for Linux... ")
elseif("${CMAKE_SYSTEM_NAME}" STREQUAL "CYGWIN" OR "${CMAKE_SYSTEM_NAME}" STREQUAL "MSYS" OR "${CMAKE_SYSTEM_NAME}" STREQUAL "Windows")
set(WINDOWS True)
set(COMPILED_FOR_WINDOWS True)
add_definitions(-D_GNU_SOURCE)
if($ENV{CLION_IDE})
# clion needs these to find the includes
if("${CMAKE_SYSTEM_NAME}" STREQUAL "MSYS" OR "${CMAKE_SYSTEM_NAME}" STREQUAL "Windows")
if("$ENV{MSYSTEM}" STREQUAL "MSYS")
include_directories(c:/msys64/usr/include)
include_directories(c:/msys64/usr/include/w32api)
elseif("$ENV{MSYSTEM}" STREQUAL "MINGW64")
include_directories(c:/msys64/mingw64/include)
elseif("$ENV{MSYSTEM}" STREQUAL "UCRT64")
include_directories(c:/msys64/ucrt64/include)
endif()
endif()
endif()
message(INFO " Compiling for Windows (${CMAKE_SYSTEM_NAME}, MSYSTEM=$ENV{MSYSTEM})... ")
else()
set(FOREIGN_OS True)
set(COMPILED_FOR_FOREIGN_OS True)
message(WARNING " Compiling for Unknown O/S... (${CMAKE_SYSTEM_NAME})")
endif()
if(ENABLE_PLUGIN_EBPF)
include(NetdataLibBPF)
include(NetdataEBPFCORE)
if(NOT LINUX)
message(FATAL_ERROR "The eBPF plugin is not supported on non-Linux systems")
endif()
netdata_bundle_libbpf()
netdata_fetch_ebpf_co_re()
endif()
#
# Libm
#
# checks link with cmake required libs
cmake_policy(SET CMP0075 NEW)
include(CheckFunctionExists)
check_function_exists(log10 HAVE_LOG10)
if(NOT HAVE_LOG10)
unset(HAVE_LOG10 CACHE)
list(APPEND CMAKE_REQUIRED_LIBRARIES m)
check_function_exists(log10 HAVE_LOG10)
if(HAVE_LOG10)
set(LINK_LIBM True)
else()
message(FATAL_ERROR "Can not use log10 with/without libm.")
endif()
endif()
#
# Custom Modules
#
include(NetdataJSONC)
include(NetdataYAML)
if(ENABLE_LEGACY_EBPF_PROGRAMS)
include(NetdataEBPFLegacy)
endif()
if(ENABLE_SENTRY)
include(NetdataSentry)
endif()
#
# Checks from custom modules
#
netdata_detect_jsonc()
netdata_detect_libyaml()
if(ENABLE_LEGACY_EBPF_PROGRAMS)
netdata_fetch_legacy_ebpf_code()
endif()
if(ENABLE_SENTRY)
netdata_bundle_sentry()
endif()
#
# check include files
#
include(CheckIncludeFile)
check_include_file("netinet/in.h" HAVE_NETINET_IN_H)
check_include_file("resolv.h" HAVE_RESOLV_H)
check_include_file("netdb.h" HAVE_NETDB_H)
check_include_file("sys/prctl.h" HAVE_SYS_PRCTL_H)
check_include_file("sys/stat.h" HAVE_SYS_STAT_H)
check_include_file("sys/vfs.h" HAVE_SYS_VFS_H)
check_include_file("sys/statfs.h" HAVE_SYS_STATFS_H)
check_include_file("linux/magic.h" HAVE_LINUX_MAGIC_H)
check_include_file("sys/mount.h" HAVE_SYS_MOUNT_H)
check_include_file("sys/statvfs.h" HAVE_SYS_STATVFS_H)
check_include_file("inttypes.h" HAVE_INTTYPES_H)
check_include_file("stdint.h" HAVE_STDINT_H)
check_include_file("sys/capability.h" HAVE_SYS_CAPABILITY_H)
check_include_file("arpa/inet.h" HAVE_ARPA_INET_H)
check_include_file("netinet/tcp.h" HAVE_NETINET_TCP_H)
check_include_file("sys/ioctl.h" HAVE_SYS_IOCTL_H)
check_include_file("grp.h" HAVE_GRP_H)
check_include_file("pwd.h" HAVE_PWD_H)
check_include_file("net/if.h" HAVE_NET_IF_H)
check_include_file("poll.h" HAVE_POLL_H)
check_include_file("syslog.h" HAVE_SYSLOG_H)
check_include_file("sys/mman.h" HAVE_SYS_MMAN_H)
check_include_file("sys/resource.h" HAVE_SYS_RESOURCE_H)
check_include_file("sys/socket.h" HAVE_SYS_SOCKET_H)
check_include_file("sys/wait.h" HAVE_SYS_WAIT_H)
check_include_file("sys/un.h" HAVE_SYS_UN_H)
check_include_file("spawn.h" HAVE_SPAWN_H)
#
# check symbols
#
include(CheckSymbolExists)
check_symbol_exists(major "sys/sysmacros.h" MAJOR_IN_SYSMACROS)
check_symbol_exists(major "sys/mkdev.h" MAJOR_IN_MKDEV)
check_symbol_exists(clock_gettime "time.h" HAVE_CLOCK_GETTIME)
check_symbol_exists(strerror_r "string.h" HAVE_STRERROR_R)
check_symbol_exists(finite "math.h" HAVE_FINITE)
check_symbol_exists(isfinite "math.h" HAVE_ISFINITE)
check_symbol_exists(dlsym "dlfcn.h" HAVE_DLSYM)
check_function_exists(pthread_getthreadid_np HAVE_PTHREAD_GETTHREADID_NP)
check_function_exists(pthread_threadid_np HAVE_PTHREAD_THREADID_NP)
check_function_exists(gettid HAVE_GETTID)
check_function_exists(waitid HAVE_WAITID)
check_function_exists(nice HAVE_NICE)
check_function_exists(recvmmsg HAVE_RECVMMSG)
check_function_exists(getpriority HAVE_GETPRIORITY)
check_function_exists(setenv HAVE_SETENV)
check_function_exists(strndup HAVE_STRNDUP)
check_function_exists(sched_getscheduler HAVE_SCHED_GETSCHEDULER)
check_function_exists(sched_setscheduler HAVE_SCHED_SETSCHEDULER)
check_function_exists(sched_get_priority_min HAVE_SCHED_GET_PRIORITY_MIN)
check_function_exists(sched_get_priority_max HAVE_SCHED_GET_PRIORITY_MAX)
check_function_exists(close_range HAVE_CLOSE_RANGE)
check_function_exists(backtrace HAVE_BACKTRACE)
#
# check source compilation
#
include(CheckCSourceCompiles)
include(CheckCXXSourceCompiles)
set(CMAKE_REQUIRED_LIBRARIES pthread)
check_c_source_compiles("
#define _GNU_SOURCE
#include <pthread.h>
int main() {
char name[16];
pthread_t thread = pthread_self();
return pthread_getname_np(thread, name, sizeof(name));
}
" HAVE_PTHREAD_GETNAME_NP)
check_c_source_compiles("
#include <stdio.h>
#define mytype(X) _Generic((X), int: 'i', float: 'f', default: 'u')
int main() {
char type = mytype(0);
return 0;
}
" HAVE_C__GENERIC)
check_c_source_compiles("
#include <malloc.h>
int main() {
mallopt(M_ARENA_MAX, 1);
mallopt(M_PERTURB, 0x5A);
return 0;
}
" HAVE_C_MALLOPT)
check_c_source_compiles("
#define _GNU_SOURCE
#include <stdio.h>
#include <sys/socket.h>
int main() {
accept4(0, NULL, NULL, 0);
return 0;
}
" HAVE_ACCEPT4)
check_c_source_compiles("
#define _GNU_SOURCE
#include <string.h>
int main() {
char x = *strerror_r(0, &x, sizeof(x)); return 0;
}
" STRERROR_R_CHAR_P)
check_c_source_compiles("
#ifndef _GNU_SOURCE
#define _GNU_SOURCE
#endif
#include <sched.h>
int main() {
setns(0, 0); return 0;
}
" HAVE_SETNS)
check_cxx_source_compiles("
int main() {
__atomic_load_8(nullptr, 0);
return 0;
}
" HAVE_BUILTIN_ATOMICS)
check_c_source_compiles("
void my_printf(char const *s, ...) __attribute__((format(gnu_printf, 1, 2)));
int main() { return 0; }
" HAVE_FUNC_ATTRIBUTE_FORMAT_GNU_PRINTF FAIL_REGEX "warning:")
check_c_source_compiles("
void my_printf(char const *s, ...) __attribute__((format(printf, 1, 2)));
int main() { return 0; }
" HAVE_FUNC_ATTRIBUTE_FORMAT_PRINTF FAIL_REGEX "warning:")
check_c_source_compiles("
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
void* my_alloc(size_t size) __attribute__((malloc));
int main() {
void *x = my_alloc(1);
free(x);
return 0;
}
void* my_alloc(size_t size) {
void *ret = malloc(size);
if(!ret) exit(1);
return ret;
}
" HAVE_FUNC_ATTRIBUTE_MALLOC)
check_c_source_compiles("
void my_function() __attribute__((noinline));
int main() { my_function(); return 0; }
void my_function() { ; }
" HAVE_FUNC_ATTRIBUTE_NOINLINE)
check_c_source_compiles("
void my_exit_function() __attribute__((noreturn));
int main() {
my_exit_function(); // Call the noreturn function
return 0;
}
void my_exit_function() {
exit(1);
}
" HAVE_FUNC_ATTRIBUTE_NORETURN)
check_c_source_compiles("
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
void* my_alloc(size_t size) __attribute__((returns_nonnull));
int main() {
void* ptr = my_alloc(10);
free(ptr);
return 0;
}
void* my_alloc(size_t size) {
void *ret = malloc(size);
if(!ret) exit(1);
return ret;
}
" HAVE_FUNC_ATTRIBUTE_RETURNS_NONNULL)
check_c_source_compiles("
int my_function() __attribute__((warn_unused_result));
int main() {
return my_function();
}
int my_function() {
return 1;
}
" HAVE_FUNC_ATTRIBUTE_WARN_UNUSED_RESULT)
if(FREEBSD OR MACOS)
set(HAVE_BUILTIN_ATOMICS True)
endif()
# openssl/crypto
set(ENABLE_OPENSSL True)
pkg_check_modules(OPENSSL openssl)
if(NOT OPENSSL_FOUND)
if(MACOS)
execute_process(COMMAND
brew --prefix --installed openssl
RESULT_VARIABLE BREW_OPENSSL
OUTPUT_VARIABLE BREW_OPENSSL_PREFIX
OUTPUT_STRIP_TRAILING_WHITESPACE)
if((BREW_OPENSSL NOT EQUAL 0) OR (NOT EXISTS "${BREW_OPENSSL_PREFIX}"))
message(FATAL_ERROR "OpenSSL (or LibreSSL) is required for building Netdata, but could not be found.")
endif()
set(OPENSSL_INCLUDE_DIRS "${BREW_OPENSSL_PREFIX}/include")
set(OPENSSL_CFLAGS_OTHER "")
set(OPENSSL_LDFLAGS "-L${BREW_OPENSSL_PREFIX}/lib;-lssl;-lcrypto")
else()
message(FATAL_ERROR "OpenSSL (or LibreSSL) is required for building Netdata, but could not be found.")
endif()
endif()
if(NOT MACOS)
pkg_check_modules(CRYPTO libcrypto)
endif()
#
# figure out if we need protoc/protobuf
#
if(NEED_PROTOBUF)
netdata_detect_protobuf()
endif()
#
# source files
#
set(LIBJUDY_PREV_FILES
src/libnetdata/libjudy/src/JudyL/JudyLPrev.c
src/libnetdata/libjudy/src/JudyL/JudyLPrevEmpty.c
)
set(LIBJUDY_NEXT_FILES
src/libnetdata/libjudy/src/JudyL/JudyLNext.c
src/libnetdata/libjudy/src/JudyL/JudyLNextEmpty.c
)
set(LIBJUDY_SOURCES
src/libnetdata/libjudy/src/Judy.h
src/libnetdata/libjudy/src/JudyCommon/JudyMalloc.c
src/libnetdata/libjudy/src/JudyCommon/JudyPrivate.h
src/libnetdata/libjudy/src/JudyCommon/JudyPrivate1L.h
src/libnetdata/libjudy/src/JudyCommon/JudyPrivateBranch.h
src/libnetdata/libjudy/src/JudyL/JudyL.h
src/libnetdata/libjudy/src/JudyL/JudyLByCount.c
src/libnetdata/libjudy/src/JudyL/JudyLCascade.c
src/libnetdata/libjudy/src/JudyL/JudyLCount.c
src/libnetdata/libjudy/src/JudyL/JudyLCreateBranch.c
src/libnetdata/libjudy/src/JudyL/JudyLDecascade.c
src/libnetdata/libjudy/src/JudyL/JudyLDel.c
src/libnetdata/libjudy/src/JudyL/JudyLFirst.c
src/libnetdata/libjudy/src/JudyL/JudyLFreeArray.c
src/libnetdata/libjudy/src/JudyL/j__udyLGet.c
src/libnetdata/libjudy/src/JudyL/JudyLGet.c
src/libnetdata/libjudy/src/JudyL/JudyLInsArray.c
src/libnetdata/libjudy/src/JudyL/JudyLIns.c
src/libnetdata/libjudy/src/JudyL/JudyLInsertBranch.c
src/libnetdata/libjudy/src/JudyL/JudyLMallocIF.c
src/libnetdata/libjudy/src/JudyL/JudyLMemActive.c
src/libnetdata/libjudy/src/JudyL/JudyLMemUsed.c
src/libnetdata/libjudy/src/JudyL/JudyLTables.c
src/libnetdata/libjudy/src/JudyHS/JudyHS.c
${LIBJUDY_PREV_FILES}
${LIBJUDY_NEXT_FILES}
)
set(LIBNETDATA_FILES
${CONFIG_H}
src/libnetdata/adaptive_resortable_list/adaptive_resortable_list.c
src/libnetdata/adaptive_resortable_list/adaptive_resortable_list.h
src/libnetdata/config/appconfig.c
src/libnetdata/config/appconfig.h
src/libnetdata/aral/aral.c
src/libnetdata/aral/aral.h
src/libnetdata/avl/avl.c
src/libnetdata/avl/avl.h
src/libnetdata/buffer/buffer.c
src/libnetdata/buffer/buffer.h
src/libnetdata/circular_buffer/circular_buffer.c
src/libnetdata/circular_buffer/circular_buffer.h
src/libnetdata/clocks/clocks.c
src/libnetdata/clocks/clocks.h
src/libnetdata/completion/completion.c
src/libnetdata/completion/completion.h
src/libnetdata/datetime/iso8601.c
src/libnetdata/datetime/iso8601.h
src/libnetdata/datetime/rfc7231.c
src/libnetdata/datetime/rfc7231.h
src/libnetdata/datetime/rfc3339.c
src/libnetdata/datetime/rfc3339.h
src/libnetdata/dictionary/dictionary.c
src/libnetdata/dictionary/dictionary.h
src/libnetdata/eval/eval.c
src/libnetdata/eval/eval.h
src/libnetdata/facets/facets.c
src/libnetdata/facets/facets.h
src/libnetdata/functions_evloop/functions_evloop.c
src/libnetdata/functions_evloop/functions_evloop.h
src/libnetdata/gorilla/gorilla.cc
src/libnetdata/gorilla/gorilla.h
src/libnetdata/july/july.c
src/libnetdata/july/july.h
src/libnetdata/inlined.h
src/libnetdata/json/json.c
src/libnetdata/json/json.h
src/libnetdata/json/jsmn.c
src/libnetdata/json/jsmn.h
src/libnetdata/libnetdata.c
src/libnetdata/libnetdata.h
src/libnetdata/line_splitter/line_splitter.c
src/libnetdata/line_splitter/line_splitter.h
src/libnetdata/libnetdata.h
src/libnetdata/locks/locks.c
src/libnetdata/locks/locks.h
src/libnetdata/log/journal.c
src/libnetdata/log/journal.h
src/libnetdata/log/log.c
src/libnetdata/log/log.h
src/libnetdata/os/os.c
src/libnetdata/os/os.h
src/libnetdata/simple_hashtable.h
src/libnetdata/os/byteorder.h
src/libnetdata/onewayalloc/onewayalloc.c
src/libnetdata/onewayalloc/onewayalloc.h
src/libnetdata/popen/popen.c
src/libnetdata/popen/popen.h
src/libnetdata/procfile/procfile.c
src/libnetdata/procfile/procfile.h
src/libnetdata/query_progress/progress.c
src/libnetdata/query_progress/progress.h
src/libnetdata/required_dummies.h
src/libnetdata/socket/security.c
src/libnetdata/socket/security.h
src/libnetdata/simple_pattern/simple_pattern.c
src/libnetdata/simple_pattern/simple_pattern.h
src/libnetdata/socket/socket.c
src/libnetdata/socket/socket.h
src/libnetdata/statistical/statistical.c
src/libnetdata/statistical/statistical.h
src/libnetdata/storage_number/storage_number.c
src/libnetdata/storage_number/storage_number.h
src/libnetdata/string/string.c
src/libnetdata/string/string.h
src/libnetdata/threads/threads.c
src/libnetdata/threads/threads.h
src/libnetdata/url/url.c
src/libnetdata/url/url.h
src/libnetdata/uuid/uuid.c
src/libnetdata/uuid/uuid.h
src/libnetdata/string/utf8.h
src/libnetdata/worker_utilization/worker_utilization.c
src/libnetdata/worker_utilization/worker_utilization.h
src/libnetdata/http/http_access.c
src/libnetdata/http/http_access.h
src/libnetdata/http/http_defs.c
src/libnetdata/http/http_defs.h
src/libnetdata/http/content_type.c
src/libnetdata/http/content_type.h
src/libnetdata/config/dyncfg.c
src/libnetdata/config/dyncfg.h
src/libnetdata/json/json-c-parser-inline.h
src/libnetdata/template-enum.h
src/libnetdata/dictionary/dictionary-internals.h
src/libnetdata/dictionary/dictionary-unittest.c
src/libnetdata/dictionary/thread-cache.c
src/libnetdata/dictionary/thread-cache.h
src/libnetdata/dictionary/dictionary-traversal.c
src/libnetdata/dictionary/dictionary-statistics.h
src/libnetdata/dictionary/dictionary-locks.h
src/libnetdata/dictionary/dictionary-refcount.h
src/libnetdata/dictionary/dictionary-hashtable.h
src/libnetdata/dictionary/dictionary-item.h
src/libnetdata/dictionary/dictionary-callbacks.h
src/libnetdata/linked-lists.h
src/libnetdata/storage-point.h
src/libnetdata/bitmap64.h
src/libnetdata/os/waitid.c
src/libnetdata/os/waitid.h
src/libnetdata/os/gettid.c
src/libnetdata/os/gettid.h
src/libnetdata/os/adjtimex.c
src/libnetdata/os/adjtimex.h
src/libnetdata/os/setresuid.c
src/libnetdata/os/setresuid.h
src/libnetdata/os/setresgid.c
src/libnetdata/os/setresgid.h
src/libnetdata/os/getgrouplist.c
src/libnetdata/os/getgrouplist.h
src/libnetdata/os/get_pid_max.c
src/libnetdata/os/get_pid_max.h
src/libnetdata/os/os-freebsd-wrappers.c
src/libnetdata/os/os-freebsd-wrappers.h
src/libnetdata/os/os-macos-wrappers.c
src/libnetdata/os/os-macos-wrappers.h
src/libnetdata/os/get_system_cpus.c
src/libnetdata/os/get_system_cpus.h
src/libnetdata/os/tinysleep.c
src/libnetdata/os/tinysleep.h
src/libnetdata/os/uuid_generate.c
src/libnetdata/os/uuid_generate.h
src/libnetdata/os/setenv.c
src/libnetdata/os/setenv.h
src/libnetdata/os/strndup.c
src/libnetdata/os/strndup.h
)
if(ENABLE_PLUGIN_EBPF)
list(APPEND LIBNETDATA_FILES
src/libnetdata/ebpf/ebpf.c
src/libnetdata/ebpf/ebpf.h
)
endif()
set(LIBH2O_FILES
src/web/server/h2o/libh2o/deps/cloexec/cloexec.c
src/web/server/h2o/libh2o/deps/libgkc/gkc.c
src/web/server/h2o/libh2o/deps/libyrmcds/close.c
src/web/server/h2o/libh2o/deps/libyrmcds/connect.c
src/web/server/h2o/libh2o/deps/libyrmcds/recv.c
src/web/server/h2o/libh2o/deps/libyrmcds/send.c
src/web/server/h2o/libh2o/deps/libyrmcds/send_text.c
src/web/server/h2o/libh2o/deps/libyrmcds/socket.c
src/web/server/h2o/libh2o/deps/libyrmcds/strerror.c
src/web/server/h2o/libh2o/deps/libyrmcds/text_mode.c
src/web/server/h2o/libh2o/deps/picohttpparser/picohttpparser.c
src/web/server/h2o/libh2o/lib/common/cache.c
src/web/server/h2o/libh2o/lib/common/file.c
src/web/server/h2o/libh2o/lib/common/filecache.c
src/web/server/h2o/libh2o/lib/common/hostinfo.c
src/web/server/h2o/libh2o/lib/common/http1client.c
src/web/server/h2o/libh2o/lib/common/memcached.c
src/web/server/h2o/libh2o/lib/common/memory.c
src/web/server/h2o/libh2o/lib/common/multithread.c
src/web/server/h2o/libh2o/lib/common/serverutil.c
src/web/server/h2o/libh2o/lib/common/socket.c
src/web/server/h2o/libh2o/lib/common/socketpool.c
src/web/server/h2o/libh2o/lib/common/string.c
src/web/server/h2o/libh2o/lib/common/time.c
src/web/server/h2o/libh2o/lib/common/timeout.c
src/web/server/h2o/libh2o/lib/common/url.c
src/web/server/h2o/libh2o/lib/core/config.c
src/web/server/h2o/libh2o/lib/core/configurator.c
src/web/server/h2o/libh2o/lib/core/context.c
src/web/server/h2o/libh2o/lib/core/headers.c
src/web/server/h2o/libh2o/lib/core/logconf.c
src/web/server/h2o/libh2o/lib/core/proxy.c
src/web/server/h2o/libh2o/lib/core/request.c
src/web/server/h2o/libh2o/lib/core/token.c
src/web/server/h2o/libh2o/lib/core/util.c
src/web/server/h2o/libh2o/lib/handler/access_log.c
src/web/server/h2o/libh2o/lib/handler/chunked.c
src/web/server/h2o/libh2o/lib/handler/compress.c
src/web/server/h2o/libh2o/lib/handler/compress/gzip.c
src/web/server/h2o/libh2o/lib/handler/errordoc.c
src/web/server/h2o/libh2o/lib/handler/expires.c
src/web/server/h2o/libh2o/lib/handler/fastcgi.c
src/web/server/h2o/libh2o/lib/handler/file.c
src/web/server/h2o/libh2o/lib/handler/headers.c
src/web/server/h2o/libh2o/lib/handler/mimemap.c
src/web/server/h2o/libh2o/lib/handler/proxy.c
src/web/server/h2o/libh2o/lib/handler/redirect.c
src/web/server/h2o/libh2o/lib/handler/reproxy.c
src/web/server/h2o/libh2o/lib/handler/throttle_resp.c
src/web/server/h2o/libh2o/lib/handler/status.c
src/web/server/h2o/libh2o/lib/handler/headers_util.c
src/web/server/h2o/libh2o/lib/handler/status/events.c
src/web/server/h2o/libh2o/lib/handler/status/requests.c
src/web/server/h2o/libh2o/lib/handler/http2_debug_state.c
src/web/server/h2o/libh2o/lib/handler/status/durations.c
src/web/server/h2o/libh2o/lib/handler/configurator/access_log.c
src/web/server/h2o/libh2o/lib/handler/configurator/compress.c
src/web/server/h2o/libh2o/lib/handler/configurator/errordoc.c
src/web/server/h2o/libh2o/lib/handler/configurator/expires.c
src/web/server/h2o/libh2o/lib/handler/configurator/fastcgi.c
src/web/server/h2o/libh2o/lib/handler/configurator/file.c
src/web/server/h2o/libh2o/lib/handler/configurator/headers.c
src/web/server/h2o/libh2o/lib/handler/configurator/proxy.c
src/web/server/h2o/libh2o/lib/handler/configurator/redirect.c
src/web/server/h2o/libh2o/lib/handler/configurator/reproxy.c
src/web/server/h2o/libh2o/lib/handler/configurator/throttle_resp.c
src/web/server/h2o/libh2o/lib/handler/configurator/status.c
src/web/server/h2o/libh2o/lib/handler/configurator/http2_debug_state.c
src/web/server/h2o/libh2o/lib/handler/configurator/headers_util.c
src/web/server/h2o/libh2o/lib/http1.c
src/web/server/h2o/libh2o/lib/tunnel.c
src/web/server/h2o/libh2o/lib/http2/cache_digests.c
src/web/server/h2o/libh2o/lib/http2/casper.c
src/web/server/h2o/libh2o/lib/http2/connection.c
src/web/server/h2o/libh2o/lib/http2/frame.c
src/web/server/h2o/libh2o/lib/http2/hpack.c
src/web/server/h2o/libh2o/lib/http2/scheduler.c
src/web/server/h2o/libh2o/lib/http2/stream.c
src/web/server/h2o/libh2o/lib/http2/http2_debug_state.c
)
set(DAEMON_FILES
src/daemon/buildinfo.c
src/daemon/buildinfo.h
src/daemon/common.c
src/daemon/common.h
src/daemon/daemon.c
src/daemon/daemon.h
src/daemon/event_loop.c
src/daemon/event_loop.h
src/daemon/global_statistics.c
src/daemon/global_statistics.h
src/daemon/analytics.c
src/daemon/analytics.h
src/daemon/main.c
src/daemon/main.h
src/daemon/signals.c
src/daemon/signals.h
src/daemon/service.c
src/daemon/watcher.c
src/daemon/watcher.h
src/daemon/static_threads.c
src/daemon/static_threads.h
src/daemon/commands.c
src/daemon/commands.h
src/daemon/pipename.c
src/daemon/pipename.h
src/daemon/unit_test.c
src/daemon/unit_test.h
src/daemon/config/dyncfg.c
src/daemon/config/dyncfg.h
src/daemon/config/dyncfg-files.c
src/daemon/config/dyncfg-unittest.c
src/daemon/config/dyncfg-inline.c
src/daemon/config/dyncfg-echo.c
src/daemon/config/dyncfg-internals.h
src/daemon/config/dyncfg-intercept.c
src/daemon/config/dyncfg-tree.c
)
set(H2O_FILES
src/web/server/h2o/http_server.c
src/web/server/h2o/http_server.h
src/web/server/h2o/h2o_utils.c
src/web/server/h2o/h2o_utils.h
src/web/server/h2o/streaming.c
src/web/server/h2o/streaming.h
src/web/server/h2o/connlist.c
src/web/server/h2o/connlist.h
)
if(ENABLE_H2O)
list(APPEND DAEMON_FILES ${H2O_FILES})
endif()
set(API_PLUGIN_FILES
src/web/api/web_api.c
src/web/api/web_api.h
src/web/api/web_api_v1.c
src/web/api/web_api_v1.h
src/web/api/web_api_v2.c
src/web/api/web_api_v2.h
src/web/api/http_auth.c
src/web/api/http_auth.h
src/web/api/http_header.c
src/web/api/http_header.h
src/web/api/badges/web_buffer_svg.c
src/web/api/badges/web_buffer_svg.h
src/web/api/exporters/allmetrics.c
src/web/api/exporters/allmetrics.h
src/web/api/exporters/shell/allmetrics_shell.c
src/web/api/exporters/shell/allmetrics_shell.h
src/web/api/queries/rrdr.c
src/web/api/queries/rrdr.h
src/web/api/queries/query.c
src/web/api/queries/query.h
src/web/api/queries/average/average.c
src/web/api/queries/average/average.h
src/web/api/queries/countif/countif.c
src/web/api/queries/countif/countif.h
src/web/api/queries/incremental_sum/incremental_sum.c
src/web/api/queries/incremental_sum/incremental_sum.h
src/web/api/queries/max/max.c
src/web/api/queries/max/max.h
src/web/api/queries/min/min.c
src/web/api/queries/min/min.h
src/web/api/queries/sum/sum.c
src/web/api/queries/sum/sum.h
src/web/api/queries/median/median.c
src/web/api/queries/median/median.h
src/web/api/queries/percentile/percentile.c
src/web/api/queries/percentile/percentile.h
src/web/api/queries/stddev/stddev.c
src/web/api/queries/stddev/stddev.h
src/web/api/queries/ses/ses.c
src/web/api/queries/ses/ses.h
src/web/api/queries/des/des.c
src/web/api/queries/des/des.h
src/web/api/queries/trimmed_mean/trimmed_mean.c
src/web/api/queries/trimmed_mean/trimmed_mean.h
src/web/api/queries/weights.c
src/web/api/queries/weights.h
src/web/api/formatters/rrd2json.c
src/web/api/formatters/rrd2json.h
src/web/api/formatters/csv/csv.c
src/web/api/formatters/csv/csv.h
src/web/api/formatters/json/json.c
src/web/api/formatters/json/json.h
src/web/api/formatters/ssv/ssv.c
src/web/api/formatters/ssv/ssv.h
src/web/api/formatters/value/value.c
src/web/api/formatters/value/value.h
src/web/api/formatters/json_wrapper.c
src/web/api/formatters/json_wrapper.h
src/web/api/formatters/charts2json.c
src/web/api/formatters/charts2json.h
src/web/api/formatters/rrdset2json.c
src/web/api/formatters/rrdset2json.h
src/web/api/ilove/ilove.c
src/web/api/ilove/ilove.h
src/web/rtc/webrtc.c
src/web/rtc/webrtc.h
)
set(EXPORTING_ENGINE_FILES
src/exporting/exporting_engine.c
src/exporting/exporting_engine.h
src/exporting/graphite/graphite.c
src/exporting/graphite/graphite.h
src/exporting/json/json.c
src/exporting/json/json.h
src/exporting/opentsdb/opentsdb.c
src/exporting/opentsdb/opentsdb.h
src/exporting/prometheus/prometheus.c
src/exporting/prometheus/prometheus.h
src/exporting/read_config.c
src/exporting/clean_connectors.c
src/exporting/init_connectors.c
src/exporting/process_data.c
src/exporting/check_filters.c
src/exporting/send_data.c
src/exporting/send_internal_metrics.c
)
set(HEALTH_PLUGIN_FILES