CMake improvements part 1 (#13575)
* generate basic config.h
Timotej S committed
Sep 9, 2022 at 15:09 UTC
0c8c34955e2ad401d03bdcab3b57723e2c97056f
2 files changed
+133
CMakeLists.txt
+77
@@ -330,6 +330,7 @@ IF(LINUX AND EXISTS "${CMAKE_SOURCE_DIR}/externaldeps/libbpf/libbpf.a")
330
list(APPEND NETDATA_COMMON_INCLUDE_DIRS ${ELF_INCLUDE_DIRS})
331
include_directories(BEFORE ${CMAKE_SOURCE_DIR}/externaldeps/libbpf/include ${CMAKE_SOURCE_DIR}/externaldeps/libbpf/include/uapi)
332
set(ENABLE_PLUGIN_EBPF True)
333
+ set(HAVE_LIBBPF True)
334
ELSE(ELF_LIBRARIES)
335
set(ENABLE_PLUGIN_EBPF False)
336
message(STATUS "ebpf plugin: disabled (requires libelf)")
@@ -1671,3 +1672,79 @@ endif()
1672
1673
endif()
1674
endif()
1675
+
1676
+
1677
+# generate config.h so that CMake becomes independent of automake
1678
+
1679
+## netdata version
1680
+set(GIT_EXECUTABLE "git")
1681
+execute_process(COMMAND ${GIT_EXECUTABLE} describe OUTPUT_VARIABLE NETDATA_VERSION OUTPUT_STRIP_TRAILING_WHITESPACE)
1682
+
1683
+IF("${NETDATA_VERSION}" STREQUAL "")
1684
+ file(STRINGS "packaging/version" NETDATA_VERSION LIMIT_COUNT 1)
1685
+ENDIF()
1686
+
1687
+set(NETDATA_USER "netdata" CACHE STRING "use this user to drop privileges")
1688
+
1689
+if(MAC_OS)
1690
+ set(ENABLE_APPS_PLUGIN False)
1691
+else()
1692
+ set(ENABLE_APPS_PLUGIN True)
1693
+endif()
1694
+
1695
+check_include_file(time.h HAVE_TIME_H)
1696
+check_include_file(unistd.h HAVE_UNISTD_H)
1697
+if (HAVE_TIME_H)
1698
+ include(CheckStructHasMember)
1699
+ check_struct_has_member("struct timespec" tv_sec "time.h" HAVE_STRUCT_TIMESPEC)
1700
+endif ()
1701
+
1702
+check_include_file(sys/statfs.h HAVE_SYS_STATFS_H)
1703
+check_include_file(sys/statvfs.h HAVE_SYS_STATVFS_H)
1704
+check_include_file(inttypes.h HAVE_INTTYPES_H)
1705
+check_include_file(stdint.h HAVE_STDINT_H)
1706
+
1707
+include(CheckSymbolExists)
1708
+check_include_file(sys/mkdev.h HAVE_SYS_MKDEV_H)
1709
+if (HAVE_SYS_MKDEV_H)
1710
+ check_symbol_exists(major "sys/mkdev.h" MAJOR_IN_MKDEV)
1711
+endif()
1712
+check_include_file(sys/sysmacros.h HAVE_SYS_SYSMACROS_H)
1713
+if (HAVE_SYS_SYSMACROS_H)
1714
+ check_symbol_exists(major "sys/sysmacros.h" MAJOR_IN_SYSMACROS)
1715
+endif()
1716
+
1717
+if (CRYPTO_FOUND)
1718
+ include(CheckLibraryExists)
1719
+ set(HAVE_CRYPTO True)
1720
+ FIND_LIBRARY(CRYPTO_LIBRARY_LOCATION NAMES crypto)
1721
+ check_library_exists(crypto X509_VERIFY_PARAM_set1_host ${CRYPTO_LIBRARY_LOCATION} HAVE_X509_VERIFY_PARAM_set1_host)
1722
+ if (HAVE_X509_VERIFY_PARAM_set1_host)
1723
+ set(HAVE_X509_VERIFY_PARAM_set1_host True)
1724
+ endif()
1725
+endif()
1726
+
1727
+include(CheckCSourceCompiles)
1728
+check_c_source_compiles("
1729
+ #define _GNU_SOURCE
1730
+ #include <string.h>
1731
+ int main() { char x = *strerror_r(0, &x, sizeof(x)); return 0; }
1732
+ " STRERROR_R_CHAR_P)
1733
+
1734
+IF(${CMAKE_C_COMPILER_ID} STREQUAL "GNU")
1735
+ SET(LIKELY_MACRO "__builtin_expect(!!(x), 1)")
1736
+ SET(UNLIKELY_MACRO "__builtin_expect(!!(x), 0)")
1737
+ELSE()
1738
+ SET(LIKELY_MACRO "(x)")
1739
+ SET(UNLIKELY_MACRO "(x)")
1740
+ENDIF()
1741
+
1742
+IF(${CMAKE_C_COMPILER_ID} STREQUAL "GNU")
1743
+ SET(ALWAYS_UNUSED_MACRO "__attribute__((unused))")
1744
+ SET(MAYBE_UNUSED_MACRO "__attribute__((unused))")
1745
+ELSE()
1746
+ SET(ALWAYS_UNUSED_MACRO "")
1747
+ SET(MAYBE_UNUSED_MACRO "")
1748
+ENDIF()
1749
+
1750
+configure_file(config.cmake.h.in config.h)
config.cmake.h.in
new
+56
@@ -0,0 +1,56 @@
1
+/* This file was generated by CMAKE from config.cmake.h.in */
2
+
3
+#define VERSION "@NETDATA_VERSION@"
4
+
5
+#define CONFIGURE_COMMAND "cmake"
6
+
7
+#define NETDATA_USER "@NETDATA_USER@"
8
+
9
+/* Using a bundled copy of protobuf */
10
+// #undef BUNDLED_PROTOBUF
11
+#define HAVE_PROTOBUF 1
12
+
13
+#define likely(x) @LIKELY_MACRO@
14
+#define unlikely(x) @UNLIKELY_MACRO@
15
+
16
+/* La boring stuff */
17
+#cmakedefine HAVE_STRUCT_TIMESPEC
18
+
19
+/* Enable GNU extensions on systems that have them. */
20
+#ifndef _GNU_SOURCE
21
+# define _GNU_SOURCE 1
22
+#endif
23
+
24
+#cmakedefine HAVE_SYS_STATFS_H
25
+#cmakedefine HAVE_SYS_STATVFS_H
26
+#cmakedefine HAVE_INTTYPES_H
27
+#cmakedefine HAVE_STDINT_H
28
+#cmakedefine STRERROR_R_CHAR_P
29
+
30
+#cmakedefine MAJOR_IN_MKDEV
31
+#cmakedefine MAJOR_IN_SYSMACROS
32
+
33
+#cmakedefine HAVE_CRYPTO
34
+
35
+#cmakedefine ENABLE_PROMETHEUS_REMOTE_WRITE
36
+
37
+/* they are defined as REQUIRED in CMakeLists.txt */
38
+#define NETDATA_WITH_ZLIB 1
39
+#define ENABLE_JSONC 1
40
+
41
+#cmakedefine ENABLE_ML
42
+
43
+#cmakedefine HAVE_LIBBPF
44
+
45
+/* NSA spy stuff */
46
+#define ENABLE_HTTPS 1
47
+#cmakedefine01 HAVE_X509_VERIFY_PARAM_set1_host
48
+
49
+#define ENABLE_ACLK
50
+#define ENABLE_DBENGINE
51
+#define ENABLE_COMPRESSION // pkg_check_modules(LIBLZ4 REQUIRED liblz4)
52
+#cmakedefine ENABLE_APPS_PLUGIN
53
+
54
+
55
+#define __always_unused @ALWAYS_UNUSED_MACRO@
56
+#define __maybe_unused @MAYBE_UNUSED_MACRO@