diff options
author | Timotej S <6674623+underhood@users.noreply.github.com> | 2022-09-09 15:09:20 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-09-09 15:09:20 +0200 |
commit | 0c8c34955e2ad401d03bdcab3b57723e2c97056f (patch) | |
tree | d8c36b26c4c846523fce6a5d644a98670884aa5e | |
parent | 34613b88fe1d78227eb512731947407faca3dc0a (diff) |
CMake improvements part 1 (#13575)
* generate basic config.h
-rw-r--r-- | CMakeLists.txt | 77 | ||||
-rw-r--r-- | config.cmake.h.in | 56 |
2 files changed, 133 insertions, 0 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 82729885c4..c2dfcc02ef 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -330,6 +330,7 @@ IF(LINUX AND EXISTS "${CMAKE_SOURCE_DIR}/externaldeps/libbpf/libbpf.a") list(APPEND NETDATA_COMMON_INCLUDE_DIRS ${ELF_INCLUDE_DIRS}) include_directories(BEFORE ${CMAKE_SOURCE_DIR}/externaldeps/libbpf/include ${CMAKE_SOURCE_DIR}/externaldeps/libbpf/include/uapi) set(ENABLE_PLUGIN_EBPF True) + set(HAVE_LIBBPF True) ELSE(ELF_LIBRARIES) set(ENABLE_PLUGIN_EBPF False) message(STATUS "ebpf plugin: disabled (requires libelf)") @@ -1671,3 +1672,79 @@ endif() endif() endif() + + +# generate config.h so that CMake becomes independent of automake + +## netdata version +set(GIT_EXECUTABLE "git") +execute_process(COMMAND ${GIT_EXECUTABLE} describe OUTPUT_VARIABLE NETDATA_VERSION OUTPUT_STRIP_TRAILING_WHITESPACE) + +IF("${NETDATA_VERSION}" STREQUAL "") + file(STRINGS "packaging/version" NETDATA_VERSION LIMIT_COUNT 1) +ENDIF() + +set(NETDATA_USER "netdata" CACHE STRING "use this user to drop privileges") + +if(MAC_OS) + set(ENABLE_APPS_PLUGIN False) +else() + set(ENABLE_APPS_PLUGIN True) +endif() + +check_include_file(time.h HAVE_TIME_H) +check_include_file(unistd.h HAVE_UNISTD_H) +if (HAVE_TIME_H) + include(CheckStructHasMember) + check_struct_has_member("struct timespec" tv_sec "time.h" HAVE_STRUCT_TIMESPEC) +endif () + +check_include_file(sys/statfs.h HAVE_SYS_STATFS_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) + +include(CheckSymbolExists) +check_include_file(sys/mkdev.h HAVE_SYS_MKDEV_H) +if (HAVE_SYS_MKDEV_H) + check_symbol_exists(major "sys/mkdev.h" MAJOR_IN_MKDEV) +endif() +check_include_file(sys/sysmacros.h HAVE_SYS_SYSMACROS_H) +if (HAVE_SYS_SYSMACROS_H) + check_symbol_exists(major "sys/sysmacros.h" MAJOR_IN_SYSMACROS) +endif() + +if (CRYPTO_FOUND) + include(CheckLibraryExists) + set(HAVE_CRYPTO True) + FIND_LIBRARY(CRYPTO_LIBRARY_LOCATION NAMES crypto) + check_library_exists(crypto X509_VERIFY_PARAM_set1_host ${CRYPTO_LIBRARY_LOCATION} HAVE_X509_VERIFY_PARAM_set1_host) + if (HAVE_X509_VERIFY_PARAM_set1_host) + set(HAVE_X509_VERIFY_PARAM_set1_host True) + endif() +endif() + +include(CheckCSourceCompiles) +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) + +IF(${CMAKE_C_COMPILER_ID} STREQUAL "GNU") + SET(LIKELY_MACRO "__builtin_expect(!!(x), 1)") + SET(UNLIKELY_MACRO "__builtin_expect(!!(x), 0)") +ELSE() + SET(LIKELY_MACRO "(x)") + SET(UNLIKELY_MACRO "(x)") +ENDIF() + +IF(${CMAKE_C_COMPILER_ID} STREQUAL "GNU") + SET(ALWAYS_UNUSED_MACRO "__attribute__((unused))") + SET(MAYBE_UNUSED_MACRO "__attribute__((unused))") +ELSE() + SET(ALWAYS_UNUSED_MACRO "") + SET(MAYBE_UNUSED_MACRO "") +ENDIF() + +configure_file(config.cmake.h.in config.h) diff --git a/config.cmake.h.in b/config.cmake.h.in new file mode 100644 index 0000000000..cc06bd6950 --- /dev/null +++ b/config.cmake.h.in @@ -0,0 +1,56 @@ +/* This file was generated by CMAKE from config.cmake.h.in */ + +#define VERSION "@NETDATA_VERSION@" + +#define CONFIGURE_COMMAND "cmake" + +#define NETDATA_USER "@NETDATA_USER@" + +/* Using a bundled copy of protobuf */ +// #undef BUNDLED_PROTOBUF +#define HAVE_PROTOBUF 1 + +#define likely(x) @LIKELY_MACRO@ +#define unlikely(x) @UNLIKELY_MACRO@ + +/* La boring stuff */ +#cmakedefine HAVE_STRUCT_TIMESPEC + +/* Enable GNU extensions on systems that have them. */ +#ifndef _GNU_SOURCE +# define _GNU_SOURCE 1 +#endif + +#cmakedefine HAVE_SYS_STATFS_H +#cmakedefine HAVE_SYS_STATVFS_H +#cmakedefine HAVE_INTTYPES_H +#cmakedefine HAVE_STDINT_H +#cmakedefine STRERROR_R_CHAR_P + +#cmakedefine MAJOR_IN_MKDEV +#cmakedefine MAJOR_IN_SYSMACROS + +#cmakedefine HAVE_CRYPTO + +#cmakedefine ENABLE_PROMETHEUS_REMOTE_WRITE + +/* they are defined as REQUIRED in CMakeLists.txt */ +#define NETDATA_WITH_ZLIB 1 +#define ENABLE_JSONC 1 + +#cmakedefine ENABLE_ML + +#cmakedefine HAVE_LIBBPF + +/* NSA spy stuff */ +#define ENABLE_HTTPS 1 +#cmakedefine01 HAVE_X509_VERIFY_PARAM_set1_host + +#define ENABLE_ACLK +#define ENABLE_DBENGINE +#define ENABLE_COMPRESSION // pkg_check_modules(LIBLZ4 REQUIRED liblz4) +#cmakedefine ENABLE_APPS_PLUGIN + + +#define __always_unused @ALWAYS_UNUSED_MACRO@ +#define __maybe_unused @MAYBE_UNUSED_MACRO@ |