summaryrefslogtreecommitdiffstats
path: root/packaging/cmake/Modules
diff options
context:
space:
mode:
Diffstat (limited to 'packaging/cmake/Modules')
-rw-r--r--packaging/cmake/Modules/FindGo.cmake39
-rw-r--r--packaging/cmake/Modules/NetdataCompilerFlags.cmake102
-rw-r--r--packaging/cmake/Modules/NetdataDetectSystemd.cmake42
-rw-r--r--packaging/cmake/Modules/NetdataEBPFCORE.cmake27
-rw-r--r--packaging/cmake/Modules/NetdataEBPFLegacy.cmake48
-rw-r--r--packaging/cmake/Modules/NetdataFetchContentExtra.cmake41
-rw-r--r--packaging/cmake/Modules/NetdataGoTools.cmake85
-rw-r--r--packaging/cmake/Modules/NetdataJSONC.cmake108
-rw-r--r--packaging/cmake/Modules/NetdataLibBPF.cmake102
-rw-r--r--packaging/cmake/Modules/NetdataProtobuf.cmake179
-rw-r--r--packaging/cmake/Modules/NetdataSentry.cmake30
-rw-r--r--packaging/cmake/Modules/NetdataUtil.cmake146
-rw-r--r--packaging/cmake/Modules/NetdataVersion.cmake51
-rw-r--r--packaging/cmake/Modules/NetdataYAML.cmake71
-rw-r--r--packaging/cmake/Modules/Packaging.cmake503
15 files changed, 1574 insertions, 0 deletions
diff --git a/packaging/cmake/Modules/FindGo.cmake b/packaging/cmake/Modules/FindGo.cmake
new file mode 100644
index 000000000..454a0051e
--- /dev/null
+++ b/packaging/cmake/Modules/FindGo.cmake
@@ -0,0 +1,39 @@
+# Custom CMake module to find the Go toolchain
+#
+# Copyright (c) 2024 Netdata Inc
+#
+# SPDX-License-Identifier: GPL-3.0-or-later
+#
+# This is a relatively orthodox CMake Find Module. It can be used by
+# simply including it and then invoking `find_package(Go)`.
+#
+# Version handling is done by CMake itself via the
+# find_package_handle_standard_args() function, so `find_package(Go 1.21)`
+# will also work correctly.
+
+if(GO_FOUND)
+ return()
+endif()
+
+# Two passes are needed here so that we prefer a copy in `/usr/local/go/bin` over a system copy.
+find_program(GO_EXECUTABLE go PATHS /usr/local/go/bin DOC "Go toolchain" NO_DEFAULT_PATH)
+find_program(GO_EXECUTABLE go DOC "Go toolchain")
+
+if (GO_EXECUTABLE)
+ execute_process(
+ COMMAND ${GO_EXECUTABLE} version
+ OUTPUT_VARIABLE GO_VERSION_STRING
+ RESULT_VARIABLE RESULT
+ )
+ if (RESULT EQUAL 0)
+ string(REGEX MATCH "go([0-9]+\\.[0-9]+(\\.[0-9]+)?)" GO_VERSION_STRING "${GO_VERSION_STRING}")
+ string(REGEX MATCH "([0-9]+\\.[0-9]+(\\.[0-9]+)?)" GO_VERSION_STRING "${GO_VERSION_STRING}")
+ endif()
+endif()
+
+include(FindPackageHandleStandardArgs)
+find_package_handle_standard_args(
+ Go
+ REQUIRED_VARS GO_EXECUTABLE
+ VERSION_VAR GO_VERSION_STRING
+)
diff --git a/packaging/cmake/Modules/NetdataCompilerFlags.cmake b/packaging/cmake/Modules/NetdataCompilerFlags.cmake
new file mode 100644
index 000000000..28b43b4ec
--- /dev/null
+++ b/packaging/cmake/Modules/NetdataCompilerFlags.cmake
@@ -0,0 +1,102 @@
+# Functions to simplify handling of extra compiler flags.
+#
+# Copyright (c) 2024 Netdata Inc.
+# SPDX-License-Identifier: GPL-3.0-or-later
+
+include(CheckCCompilerFlag)
+include(CheckCXXCompilerFlag)
+
+# Construct a pre-processor safe name
+#
+# This takes a specified value, and assigns the generated name to the
+# specified target.
+function(make_cpp_safe_name value target)
+ string(REPLACE "-" "_" tmp "${value}")
+ string(REPLACE "=" "_" tmp "${tmp}")
+ set(${target} "${tmp}" PARENT_SCOPE)
+endfunction()
+
+# Conditionally add an extra compiler flag to C and C++ flags.
+#
+# If the language flags already match the `match` argument, skip this flag.
+# Otherwise, check for support for `flag` and if support is found, add it to
+# the compiler flags for the run.
+function(add_simple_extra_compiler_flag match flag)
+ set(CMAKE_REQUIRED_FLAGS "-Werror")
+
+ make_cpp_safe_name("${flag}" flag_name)
+
+ if(NOT ${CMAKE_C_FLAGS} MATCHES ${match})
+ check_c_compiler_flag("${flag}" HAVE_C_${flag_name})
+ endif()
+
+ if(NOT ${CMAKE_CXX_FLAGS} MATCHES ${match})
+ check_cxx_compiler_flag("${flag}" HAVE_CXX_${flag_name})
+ endif()
+
+ if(HAVE_C_${flag_name} AND HAVE_CXX_${flag_name})
+ add_compile_options("${flag}")
+ add_link_options("${flag}")
+ endif()
+endfunction()
+
+# Same as add_simple_extra_compiler_flag, but check for a second flag if the
+# first one is unsupported.
+function(add_double_extra_compiler_flag match flag1 flag2)
+ set(CMAKE_REQUIRED_FLAGS "-Werror")
+
+ make_cpp_safe_name("${flag1}" flag1_name)
+ make_cpp_safe_name("${flag2}" flag2_name)
+
+ if(NOT ${CMAKE_C_FLAGS} MATCHES ${match})
+ check_c_compiler_flag("${flag1}" HAVE_C_${flag1_name})
+ if(NOT HAVE_C_${flag1_name})
+ check_c_compiler_flag("${flag2}" HAVE_C_${flag2_name})
+ endif()
+ endif()
+
+ if(NOT ${CMAKE_CXX_FLAGS} MATCHES ${match})
+ check_cxx_compiler_flag("${flag1}" HAVE_CXX_${flag1_name})
+ if(NOT HAVE_CXX_${flag1_name})
+ check_cxx_compiler_flag("${flag2}" HAVE_CXX_${flag2_name})
+ endif()
+ endif()
+
+ if(HAVE_C_${flag1_name} AND HAVE_CXX_${flag1_name})
+ add_compile_options("${flag1}")
+ add_link_options("${flag1}")
+ elseif(HAVE_C_${flag2_name} AND HAVE_CXX${flag2_name})
+ add_compile_options("${flag2}")
+ add_link_options("${flag2}")
+ endif()
+endfunction()
+
+if(CMAKE_BUILD_TYPE STREQUAL "Debug")
+ option(DISABLE_HARDENING "Disable adding extra compiler flags for hardening" TRUE)
+else()
+ option(DISABLE_HARDENING "Disable adding extra compiler flags for hardening" FALSE)
+endif()
+
+option(ENABLE_ADDRESS_SANITIZER "Build with address sanitizer enabled" False)
+mark_as_advanced(ENABLE_ADDRESS_SANITIZER)
+
+if(ENABLE_ADDRESS_SANITIZER)
+ set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=address")
+endif()
+
+set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CMAKE_C_FLAGS}")
+
+if(NOT ${DISABLE_HARDENING})
+ add_double_extra_compiler_flag("stack-protector" "-fstack-protector-strong" "-fstack-protector")
+ add_double_extra_compiler_flag("_FORTIFY_SOURCE" "-D_FORTIFY_SOURCE=3" "-D_FORTIFY_SOURCE=2")
+ add_simple_extra_compiler_flag("stack-clash-protection" "-fstack-clash-protection")
+ add_simple_extra_compiler_flag("-fcf-protection" "-fcf-protection=full")
+ add_simple_extra_compiler_flag("branch-protection" "-mbranch-protection=standard")
+endif()
+
+foreach(FLAG function-sections data-sections)
+ add_simple_extra_compiler_flag("${FLAG}" "-f${FLAG}")
+endforeach()
+
+add_simple_extra_compiler_flag("-Wbuiltin-macro-redefined" "-Wno-builtin-macro-redefined")
+add_simple_extra_compiler_flag("-fexecptions" "-fexceptions")
diff --git a/packaging/cmake/Modules/NetdataDetectSystemd.cmake b/packaging/cmake/Modules/NetdataDetectSystemd.cmake
new file mode 100644
index 000000000..ecac7aaf8
--- /dev/null
+++ b/packaging/cmake/Modules/NetdataDetectSystemd.cmake
@@ -0,0 +1,42 @@
+# CMake Module to handle all the systemd-related checks for Netdata.
+#
+# Copyright (c) 2024 Netdata Inc.
+# SPDX-License-Identifier: GPL-3.0-or-later
+
+macro(detect_systemd)
+ find_library(SYSTEMD_LIBRARY NAMES systemd)
+
+ set(ENABLE_DSYSTEMD_DBUS NO)
+ pkg_check_modules(SYSTEMD libsystemd)
+
+ if(SYSTEMD_FOUND)
+ set(CMAKE_REQUIRED_LIBRARIES_BEFORE_SYSTEMD "${CMAKE_REQUIRED_LIBRARIES}")
+ set(CMAKE_REQUIRED_LIBRARIES "${CMAKE_REQUIRED_LIBRARIES};${SYSTEMD_LIBRARIES}")
+
+ check_c_source_compiles("
+ #include <systemd/sd-journal.h>
+
+ int main() {
+ int x = SD_JOURNAL_OS_ROOT;
+ return 0;
+ }" HAVE_SD_JOURNAL_OS_ROOT)
+
+ check_symbol_exists(SD_JOURNAL_OS_ROOT "systemd/sd-journal.h" HAVE_SD_JOURNAL_OS_ROOT)
+ check_symbol_exists(sd_journal_open_files_fd "systemd/sd-journal.h" HAVE_SD_JOURNAL_OPEN_FILES_FD)
+ check_symbol_exists(sd_journal_restart_fields "systemd/sd-journal.h" HAVE_SD_JOURNAL_RESTART_FIELDS)
+ check_symbol_exists(sd_journal_get_seqnum "systemd/sd-journal.h" HAVE_SD_JOURNAL_GET_SEQNUM)
+
+ check_symbol_exists(sd_bus_default_system "systemd/sd-bus.h" HAVE_SD_BUS_DEFAULT_SYSTEM)
+ check_symbol_exists(sd_bus_call_method "systemd/sd-bus.h" HAVE_SD_BUS_CALL_METHOD)
+ check_symbol_exists(sd_bus_message_enter_container "systemd/sd-bus.h" HAVE_SD_BUS_MESSAGE_ENTER_CONTAINER)
+ check_symbol_exists(sd_bus_message_read "systemd/sd-bus.h" HAVE_SD_BUS_MESSAGE_READ)
+ check_symbol_exists(sd_bus_message_exit_container "systemd/sd-bus.h" HAVE_SD_BUS_MESSAGE_EXIT_CONTAINER)
+
+ set(CMAKE_REQUIRED_LIBRARIES "${CMAKE_REQUIRED_LIBRARIES_BEFORE_SYSTEMD}")
+
+ set(HAVE_SYSTEMD True)
+ if(HAVE_SD_BUS_DEFAULT_SYSTEM AND HAVE_SD_BUS_CALL_METHOD AND HAVE_SD_BUS_MESSAGE_ENTER_CONTAINER AND HAVE_SD_BUS_MESSAGE_READ AND HAVE_SD_BUS_MESSAGE_EXIT_CONTAINER)
+ set(ENABLE_SYSTEMD_DBUS YES)
+ endif()
+ endif()
+endmacro()
diff --git a/packaging/cmake/Modules/NetdataEBPFCORE.cmake b/packaging/cmake/Modules/NetdataEBPFCORE.cmake
new file mode 100644
index 000000000..936124dee
--- /dev/null
+++ b/packaging/cmake/Modules/NetdataEBPFCORE.cmake
@@ -0,0 +1,27 @@
+# Handling for eBPF CO-RE files
+#
+# Copyright (c) 2024 Netdata Inc.
+# SPDX-License-Identifier: GPL-3.0-or-later
+
+include(ExternalProject)
+
+set(ebpf-co-re_SOURCE_DIR "${CMAKE_BINARY_DIR}/ebpf-co-re")
+
+# Fetch and install our eBPF CO-RE files
+function(netdata_fetch_ebpf_co_re)
+ ExternalProject_Add(
+ ebpf-co-re
+ URL https://github.com/netdata/ebpf-co-re/releases/download/v1.4.3/netdata-ebpf-co-re-glibc-v1.4.3.tar.xz
+ URL_HASH SHA256=52a8cf65b4659d173ec3d9fb69315ba48c1f091d1882968748b37a8f7bf9f92d
+ SOURCE_DIR "${ebpf-co-re_SOURCE_DIR}"
+ CONFIGURE_COMMAND ""
+ BUILD_COMMAND ""
+ INSTALL_COMMAND ""
+ EXCLUDE_FROM_ALL 1
+ )
+endfunction()
+
+function(netdata_add_ebpf_co_re_to_target _target)
+ add_dependencies(${_target} ebpf-co-re)
+ target_include_directories(${_target} BEFORE PRIVATE "${ebpf-co-re_SOURCE_DIR}")
+endfunction()
diff --git a/packaging/cmake/Modules/NetdataEBPFLegacy.cmake b/packaging/cmake/Modules/NetdataEBPFLegacy.cmake
new file mode 100644
index 000000000..7658a0e94
--- /dev/null
+++ b/packaging/cmake/Modules/NetdataEBPFLegacy.cmake
@@ -0,0 +1,48 @@
+# Handling for eBPF legacy programs
+#
+# Copyright (c) 2024 Netdata Inc.
+# SPDX-License-Identifier: GPL-3.0-or-later
+
+include(ExternalProject)
+include(NetdataUtil)
+
+set(ebpf-legacy_SOURCE_DIR "${CMAKE_BINARY_DIR}/ebpf-legacy")
+set(ebpf-legacy_BUILD_DIR "${CMAKE_BINARY_DIR}/ebpf-legacy-build")
+
+# Fetch the legacy eBPF code.
+function(netdata_fetch_legacy_ebpf_code)
+ netdata_identify_libc(_libc)
+
+ if(DEFINED BUILD_SHARED_LIBS)
+ if(NOT BUILD_SHARED_LIBS)
+ set(need_static TRUE)
+ endif()
+ endif()
+
+ if(need_static)
+ set(_hash 73cfe6ceb0098447c2a016d8f9674ad8a80ba6dd61cfdd8646710a0dc5c52d9f)
+ set(_libc "static")
+ elseif(_libc STREQUAL "glibc")
+ set(_hash e9b89ff215c56f04249a2169bee15cdae6e61ef913468add258719e8afe6eac2)
+ elseif(_libc STREQUAL "musl")
+ set(_hash 1574e3bbdcac7dae534d783fa6fc6452268240d7477aefd87fadc4e7f705d48e)
+ else()
+ message(FATAL_ERROR "Could not determine libc implementation, unable to install eBPF legacy code.")
+ endif()
+
+ ExternalProject_Add(
+ ebpf-code-legacy
+ URL https://github.com/netdata/kernel-collector/releases/download/v1.4.3/netdata-kernel-collector-${_libc}-v1.4.3.tar.xz
+ URL_HASH SHA256=${_hash}
+ SOURCE_DIR "${ebpf-legacy_SOURCE_DIR}"
+ CONFIGURE_COMMAND ""
+ BUILD_COMMAND sh -c "mkdir -p ${ebpf-legacy_BUILD_DIR}/ebpf.d && mv ${ebpf-legacy_SOURCE_DIR}/*netdata_ebpf_*.o ${ebpf-legacy_BUILD_DIR}/ebpf.d"
+ INSTALL_COMMAND ""
+ )
+endfunction()
+
+function(netdata_install_legacy_ebpf_code)
+ install(DIRECTORY ${ebpf-legacy_BUILD_DIR}/ebpf.d
+ DESTINATION usr/libexec/netdata/plugins.d
+ COMPONENT ebpf-code-legacy)
+endfunction()
diff --git a/packaging/cmake/Modules/NetdataFetchContentExtra.cmake b/packaging/cmake/Modules/NetdataFetchContentExtra.cmake
new file mode 100644
index 000000000..cc70448de
--- /dev/null
+++ b/packaging/cmake/Modules/NetdataFetchContentExtra.cmake
@@ -0,0 +1,41 @@
+# Extra tools for working with FetchContent on older CMake
+#
+# Copyright (c) 2024 Netdata Inc.
+# SPDX-License-Identifier: GPL-3.0-or-later
+
+# FetchContent_MakeAvailable_NoInstall
+#
+# Add a sub-project with FetchContent, but with the EXCLUDE_FROM_ALL
+# argument for the add_subdirectory part.
+#
+# CMake 3.28 and newer provide a way to do this with an extra argument
+# on FetchContent_Declare, but older versions need you to implement
+# the logic yourself. Once we no longer support CMake versions older
+# than 3.28, we can get rid of this macro.
+#
+# Unlike FetchContent_MakeAvailble, this only accepts a single project
+# to make available.
+macro(FetchContent_MakeAvailable_NoInstall name)
+ include(FetchContent)
+
+ FetchContent_GetProperties(${name})
+
+ if(NOT ${name}_POPULATED)
+ FetchContent_Populate(${name})
+ add_subdirectory(${${name}_SOURCE_DIR} ${${name}_BINARY_DIR} EXCLUDE_FROM_ALL)
+ endif()
+endmacro()
+
+# NETDATA_PROPAGATE_TOOLCHAIN_ARGS
+#
+# Defines a set of CMake flags to be passed to CMAKE_ARGS for
+# FetchContent_Declare and ExternalProject_Add to ensure that toolchain
+# configuration propagates correctly to sub-projects.
+#
+# This needs to be explicitly included for any sub-project that needs
+# to be built for the target system.
+set(NETDATA_PROPAGATE_TOOLCHAIN_ARGS
+ "-DCMAKE_C_COMPILER=${CMAKE_C_COMPILER}
+ -DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}
+ $<$<BOOL:${CMAKE_C_COMPILER_TARGET}>:-DCMAKE_C_COMPILER_TARGET=${CMAKE_C_COMPILER_TARGET}
+ $<$<BOOL:${CMAKE_CXX_COMPILER_TARGET}>:-DCMAKE_CXX_COMPILER_TARGET=${CMAKE_CXX_COMPILER_TARGET}")
diff --git a/packaging/cmake/Modules/NetdataGoTools.cmake b/packaging/cmake/Modules/NetdataGoTools.cmake
new file mode 100644
index 000000000..6526c8d7b
--- /dev/null
+++ b/packaging/cmake/Modules/NetdataGoTools.cmake
@@ -0,0 +1,85 @@
+# Macros and functions to assist in working with Go
+#
+# Copyright (c) 2024 Netdata Inc
+#
+# SPDX-License-Identifier: GPL
+
+if(CMAKE_BUILD_TYPE STREQUAL Debug)
+ set(GO_LDFLAGS "-X github.com/netdata/netdata/go/go.d.plugin/pkg/buildinfo.Version=${NETDATA_VERSION_STRING}")
+else()
+ set(GO_LDFLAGS "-w -s -X github.com/netdata/netdata/go/go.d.plugin/pkg/buildinfo.Version=${NETDATA_VERSION_STRING}")
+endif()
+
+# add_go_target: Add a new target that needs to be built using the Go toolchain.
+#
+# Takes four arguments, the target name, the output artifact name, the
+# source tree for the Go module, and the sub-directory of that source tree
+# to pass to `go build`.
+#
+# The target itself will invoke `go build` in the specified source tree,
+# using the `-o` option to produce the final output artifact, and passing
+# the requested sub-directory as the final argument.
+#
+# This will also automatically construct the dependency list for the
+# target by finding all Go source files under the specified source tree
+# and then appending the go.mod and go.sum files from the root of the
+# source tree.
+macro(add_go_target target output build_src build_dir)
+ file(GLOB_RECURSE ${target}_DEPS CONFIGURE_DEPENDS "${build_src}/*.go")
+ list(APPEND ${target}_DEPS
+ "${build_src}/go.mod"
+ "${build_src}/go.sum"
+ )
+
+ add_custom_command(
+ OUTPUT ${output}
+ COMMAND "${CMAKE_COMMAND}" -E env CGO_ENABLED=0 "${GO_EXECUTABLE}" build -buildvcs=false -ldflags "${GO_LDFLAGS}" -o "${CMAKE_BINARY_DIR}/${output}" "./${build_dir}"
+ DEPENDS ${${target}_DEPS}
+ COMMENT "Building Go component ${output}"
+ WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}/${build_src}"
+ VERBATIM
+ )
+ add_custom_target(
+ ${target} ALL
+ DEPENDS ${output}
+ )
+endmacro()
+
+# find_min_go_version: Determine the minimum Go version based on go.mod files
+#
+# Takes one argument, specifying a source tree to scan for go.mod files.
+#
+# All files found will be checked for a `go` directive, and the
+# MIN_GO_VERSION variable will be set to the highest version
+# number found among these directives.
+#
+# Only works on UNIX-like systems, because it has to process the go.mod
+# files in ways that CMake can't do on it's own.
+function(find_min_go_version src_tree)
+ message(STATUS "Determining minimum required version of Go for this build")
+
+ file(GLOB_RECURSE go_mod_files ${src_tree}/go.mod)
+
+ set(result 1.0)
+
+ foreach(f IN ITEMS ${go_mod_files})
+ message(VERBOSE "Checking Go version specified in ${f}")
+ execute_process(
+ COMMAND grep -E "^go .*$" ${f}
+ COMMAND cut -f 2 -d " "
+ RESULT_VARIABLE version_check_result
+ OUTPUT_VARIABLE go_mod_version
+ )
+
+ if(version_check_result EQUAL 0)
+ string(REGEX MATCH "([0-9]+\\.[0-9]+(\\.[0-9]+)?)" go_mod_version "${go_mod_version}")
+
+ if(go_mod_version VERSION_GREATER result)
+ set(result "${go_mod_version}")
+ endif()
+ endif()
+ endforeach()
+
+ message(STATUS "Minimum required Go version determined to be ${result}")
+ set(MIN_GO_VERSION "${result}" PARENT_SCOPE)
+endfunction()
diff --git a/packaging/cmake/Modules/NetdataJSONC.cmake b/packaging/cmake/Modules/NetdataJSONC.cmake
new file mode 100644
index 000000000..9bbb424e1
--- /dev/null
+++ b/packaging/cmake/Modules/NetdataJSONC.cmake
@@ -0,0 +1,108 @@
+# Functions and macros for handling of JSON-C
+#
+# Copyright (c) 2024 Netdata Inc.
+# SPDX-License-Identifier: GPL-3.0-or-later
+
+# Handle bundling of json-c.
+#
+# This pulls it in as a sub-project using FetchContent functionality.
+#
+# This needs to be a function and not a macro for variable scoping
+# reasons. All the things we care about from the sub-project are exposed
+# as targets, which are globally scoped and not function scoped.
+function(netdata_bundle_jsonc)
+ include(FetchContent)
+ include(NetdataFetchContentExtra)
+
+ message(STATUS "Preparing vendored copy of JSON-C")
+
+ if(ENABLE_BUNDLED_JSONC)
+ set(FETCHCONTENT_TRY_FIND_PACKAGE_MODE NEVER)
+ endif()
+
+ set(FETCHCONTENT_FULLY_DISCONNECTED Off)
+
+ # JSON-C supports older versions of CMake than we do, so set
+ # the correct values for the few policies we actually need.
+ set(CMAKE_POLICY_DEFAULT_CMP0077 NEW)
+
+ # JSON-C's build system does string comparisons against option
+ # values instead of treating them as booleans, so we need to use
+ # proper strings for option values instead of just setting them
+ # to true or false.
+ set(DISABLE_BSYMBOLIC ON)
+ set(DISABLE_WERROR ON)
+ set(DISABLE_EXTRA_LIBS ON)
+ set(BUILD_SHARED_LIBS OFF)
+ set(BUILD_STATIC_LIBS ON)
+ set(BUILD_APPS OFF)
+
+ FetchContent_Declare(json-c
+ GIT_REPOSITORY https://github.com/json-c/json-c
+ GIT_TAG b4c371fa0cbc4dcbaccc359ce9e957a22988fb34 # json-c-0.17-20230812
+ CMAKE_ARGS ${NETDATA_CMAKE_PROPAGATE_TOOLCHAIN_ARGS}
+ )
+
+ FetchContent_MakeAvailable_NoInstall(json-c)
+
+ message(STATUS "Finished preparing vendored copy of JSON-C")
+endfunction()
+
+# Handle setup of json-c for the build.
+#
+# This will attempt to find json-c using pkg_check_modules. If it finds
+# a usable copy, that will be used. If not, it will bundle a vendored copy
+# as a sub-project.
+#
+# Irrespective of how json-c is to be included, library names,
+# include directories, and compile definitions will be specified in the
+# NETDATA_JSONC_* variables for later use.
+macro(netdata_detect_jsonc)
+ if(NOT ENABLE_BUNDLED_JSONC)
+ pkg_check_modules(JSONC json-c)
+ endif()
+
+ if(NOT JSONC_FOUND)
+ set(ENABLE_BUNDLED_JSONC True PARENT_SCOPE)
+ netdata_bundle_jsonc()
+ set(NETDATA_JSONC_LDFLAGS json-c)
+ set(NETDATA_JSONC_INCLUDE_DIRS ${PROJECT_BINARY_DIR}/include)
+ get_target_property(NETDATA_JSONC_CFLAGS_OTHER json-c INTERFACE_COMPILE_DEFINITIONS)
+
+ if(NETDATA_JSONC_CFLAGS_OTHER STREQUAL NETDATA_JSONC_CFLAGS_OTHER-NOTFOUND)
+ set(NETDATA_JSONC_CFLAGS_OTHER "")
+ endif()
+
+ add_custom_command(
+ OUTPUT ${PROJECT_BINARY_DIR}/include/json-c
+ COMMAND ${CMAKE_COMMAND} -E make_directory ${PROJECT_BINARY_DIR}/include
+ COMMAND ${CMAKE_COMMAND} -E create_symlink ${json-c_BINARY_DIR} ${PROJECT_BINARY_DIR}/include/json-c
+ COMMENT "Create compatibility symlink for vendored JSON-C headers"
+ DEPENDS json-c
+ )
+ add_custom_target(
+ json-c-compat-link
+ DEPENDS ${PROJECT_BINARY_DIR}/include/json-c
+ )
+ else()
+ set(NETDATA_JSONC_LDFLAGS ${JSONC_LDFLAGS})
+ set(NETDATA_JSONC_CFLAGS_OTHER ${JSONC_CFLAGS_OTHER})
+ set(NETDATA_JSONC_INCLUDE_DIRS ${JSONC_INCLUDE_DIRS})
+ add_custom_target(json-c-compat-link)
+ endif()
+endmacro()
+
+# Add json-c as a public link dependency of the specified target.
+#
+# The specified target must already exist, and the netdata_detect_json-c
+# macro must have already been run at least once for this to work correctly.
+function(netdata_add_jsonc_to_target _target)
+ if(ENABLE_BUNDLED_JSONC)
+ target_include_directories(${_target} BEFORE PUBLIC ${NETDATA_JSONC_INCLUDE_DIRS})
+ else()
+ target_include_directories(${_target} PUBLIC ${NETDATA_JSONC_INCLUDE_DIRS})
+ endif()
+ target_compile_options(${_target} PUBLIC ${NETDATA_JSONC_CFLAGS_OTHER})
+ target_link_libraries(${_target} PUBLIC ${NETDATA_JSONC_LDFLAGS})
+ add_dependencies(${_target} json-c-compat-link)
+endfunction()
diff --git a/packaging/cmake/Modules/NetdataLibBPF.cmake b/packaging/cmake/Modules/NetdataLibBPF.cmake
new file mode 100644
index 000000000..17a26a10f
--- /dev/null
+++ b/packaging/cmake/Modules/NetdataLibBPF.cmake
@@ -0,0 +1,102 @@
+# Handling for libbpf (used by the eBPF plugin)
+#
+# Copyright (c) 2024 Netdata Inc.
+# SPDX-License-Identifier: GPL-3.0-or-later
+
+include(ExternalProject)
+include(NetdataUtil)
+
+set(libbpf_SOURCE_DIR "${CMAKE_BINARY_DIR}/libbpf")
+
+# Check if the kernel is old enough that we need to use a legacy copy of eBPF.
+function(_need_legacy_libbpf _var)
+ if(FORCE_LEGACY_LIBBPF)
+ set(${_var} TRUE PARENT_SCOPE)
+ return()
+ endif()
+
+ netdata_detect_host_kernel_version()
+
+ if(HOST_KERNEL_VERSION VERSION_LESS "4.14.0")
+ set(${_var} TRUE PARENT_SCOPE)
+ else()
+ set(${_var} FALSE PARENT_SCOPE)
+ endif()
+endfunction()
+
+# Prepare a vendored copy of libbpf
+function(netdata_bundle_libbpf)
+ _need_legacy_libbpf(USE_LEGACY_LIBBPF)
+
+ if(USE_LEGACY_LIBBPF)
+ set(_libbpf_tag 673424c56127bb556e64095f41fd60c26f9083ec) # v0.0.9_netdata-1
+ else()
+ set(_libbpf_tag 3d78a726c618560ad7fb03ceaf0fd03e8b2656b4) # v1.4.3p_netdata
+ endif()
+
+ if(DEFINED BUILD_SHARED_LIBS)
+ if(NOT BUILD_SHARED_LIBS)
+ set(need_static TRUE)
+ endif()
+ endif()
+
+ if(NOT need_static)
+ netdata_identify_libc(_libc)
+
+ string(REGEX MATCH "glibc|musl" _libc_supported "${_libc}")
+
+ if(NOT _libc_supported)
+ message(FATAL_ERROR "This system’s libc (detected: ${_libc}) is not not supported by the eBPF plugin.")
+ endif()
+ endif()
+
+ find_program(MAKE_COMMAND make)
+
+ if(MAKE_COMMAND STREQUAL MAKE_COMMAND-NOTFOUND)
+ message(FATAL_ERROR "GNU Make is required when building the eBPF plugin, but could not be found.")
+ endif()
+
+ pkg_check_modules(ELF REQUIRED libelf)
+ pkg_check_modules(ZLIB REQUIRED zlib)
+
+ set(_libbpf_lib_dir lib)
+
+ if(CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64")
+ set(_libbpf_lib_dir lib64)
+ endif()
+
+ set(_libbpf_library "${libbpf_SOURCE_DIR}/usr/${_libbpf_lib_dir}/libbpf.a")
+
+ ExternalProject_Add(
+ libbpf
+ GIT_REPOSITORY https://github.com/netdata/libbpf.git
+ GIT_TAG ${_libbpf_tag}
+ SOURCE_DIR "${libbpf_SOURCE_DIR}"
+ CONFIGURE_COMMAND ""
+ BUILD_COMMAND ${MAKE_COMMAND} -C src CC=${CMAKE_C_COMPILER} BUILD_STATIC_ONLY=1 OBJDIR=build/ DESTDIR=../ install
+ BUILD_IN_SOURCE 1
+ BUILD_BYPRODUCTS "${_libbpf_library}"
+ INSTALL_COMMAND ""
+ EXCLUDE_FROM_ALL 1
+ )
+
+ add_library(libbpf_library STATIC IMPORTED GLOBAL)
+ set_property(
+ TARGET libbpf_library
+ PROPERTY IMPORTED_LOCATION "${_libbpf_library}"
+ )
+ set_property(
+ TARGET libbpf_library
+ PROPERTY INTERFACE_LINK_LIBRARIES "${ELF_LIBRARIES};${ZLIB_LIBRARIES}"
+ )
+ set(NETDATA_LIBBPF_INCLUDE_DIRECTORIES "${libbpf_SOURCE_DIR}/usr/include;${libbpf_SOURCE_DIR}/include;${ELF_INCLUDE_DIRECTORIES};${ZLIB_INCLUDE_DIRECTORIES}" PARENT_SCOPE)
+ set(NETDATA_LIBBPF_COMPILE_OPTIONS "${ELF_CFLAGS_OTHER};${ZLIB_CFLAGS_OTHER}" PARENT_SCOPE)
+endfunction()
+
+# Add libbpf as a link dependency for the given target.
+function(netdata_add_libbpf_to_target _target)
+ target_link_libraries(${_target} PUBLIC libbpf_library)
+ target_include_directories(${_target} BEFORE PUBLIC "${NETDATA_LIBBPF_INCLUDE_DIRECTORIES}")
+ target_compile_options(${_target} PUBLIC "${NETDATA_LIBBPF_COMPILE_OPTIONS}")
+ add_dependencies(${_target} libbpf)
+endfunction()
diff --git a/packaging/cmake/Modules/NetdataProtobuf.cmake b/packaging/cmake/Modules/NetdataProtobuf.cmake
new file mode 100644
index 000000000..c142d6566
--- /dev/null
+++ b/packaging/cmake/Modules/NetdataProtobuf.cmake
@@ -0,0 +1,179 @@
+# Macros and functions for handling of Protobuf
+#
+# Copyright (c) 2024 Netdata Inc.
+# SPDX-License-Identifier: GPL-3.0-or-later
+
+# Prepare a vendored copy of Protobuf for use with Netdata.
+function(netdata_bundle_protobuf)
+ include(FetchContent)
+ include(NetdataFetchContentExtra)
+
+ set(PROTOBUF_TAG f0dc78d7e6e331b8c6bb2d5283e06aa26883ca7c) # v21.12
+ set(NEED_ABSL False)
+
+ if(CMAKE_CXX_STANDARD GREATER_EQUAL 14)
+ set(PROTOBUF_TAG 4a2aef570deb2bfb8927426558701e8bfc26f2a4) # v25.3
+ set(NEED_ABSL True)
+ set(ABSL_TAG 2f9e432cce407ce0ae50676696666f33a77d42ac) # 20240116.1
+ endif()
+
+ set(FETCHCONTENT_TRY_FIND_PACKAGE_MODE NEVER)
+
+ string(REPLACE "-fsanitize=address" "" CMAKE_C_FLAGS "${CMAKE_C_FLAGS}")
+ string(REPLACE "-fsanitize=address" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
+
+ # ignore debhelper
+ set(FETCHCONTENT_FULLY_DISCONNECTED Off)
+
+ if(NEED_ABSL)
+ set(ABSL_PROPAGATE_CXX_STD On)
+ set(ABSL_ENABLE_INSTALL Off)
+ set(BUILD_SHARED_LIBS Off)
+
+ message(STATUS "Preparing bundled Abseil (required by bundled Protobuf)")
+ FetchContent_Declare(absl
+ GIT_REPOSITORY https://github.com/abseil/abseil-cpp
+ GIT_TAG ${ABSL_TAG}
+ CMAKE_ARGS ${NETDATA_CMAKE_PROPAGATE_TOOLCHAIN_ARGS}
+ )
+ FetchContent_MakeAvailable_NoInstall(absl)
+ message(STATUS "Finished preparing bundled Abseil")
+ endif()
+
+ set(protobuf_INSTALL Off)
+ set(protobuf_BUILD_LIBPROTOC Off)
+ set(protobuf_BUILD_TESTS Off)
+ set(protobuf_BUILD_SHARED_LIBS Off)
+
+ message(STATUS "Preparing bundled Protobuf")
+ FetchContent_Declare(protobuf
+ GIT_REPOSITORY https://github.com/protocolbuffers/protobuf.git
+ GIT_TAG ${PROTOBUF_TAG}
+ CMAKE_ARGS ${NETDATA_CMAKE_PROPAGATE_TOOLCHAIN_ARGS}
+ )
+ FetchContent_MakeAvailable_NoInstall(protobuf)
+ message(STATUS "Finished preparing bundled Protobuf.")
+
+ set(ENABLE_BUNDLED_PROTOBUF True PARENT_SCOPE)
+endfunction()
+
+# Handle detection of Protobuf
+macro(netdata_detect_protobuf)
+ if(OS_WINDOWS)
+ set(PROTOBUF_PROTOC_EXECUTABLE "$ENV{PROTOBUF_PROTOC_EXECUTABLE}")
+ if(NOT PROTOBUF_PROTOC_EXECUTABLE)
+ set(PROTOBUF_PROTOC_EXECUTABLE "/bin/protoc")
+ endif()
+ set(PROTOBUF_CFLAGS_OTHER "")
+ set(PROTOBUF_INCLUDE_DIRS "")
+ set(PROTOBUF_LIBRARIES "-lprotobuf")
+
+ set(ENABLE_PROTOBUF True)
+ set(HAVE_PROTOBUF True)
+ else()
+ if(NOT ENABLE_BUNDLED_PROTOBUF)
+ if (NOT BUILD_SHARED_LIBS)
+ set(Protobuf_USE_STATIC_LIBS On)
+ endif()
+
+ # The FindProtobuf CMake module shipped by upstream CMake is
+ # broken for Protobuf version 22.0 and newer because it does
+ # not correctly pull in the new Abseil dependencies. Protobuf
+ # itself sometimes ships a CMake Package Configuration module
+ # that _does_ work correctly, so use that in preference to the
+ # Find module shipped with CMake.
+ #
+ # The code below works by first attempting to use find_package
+ # in config mode, and then checking for the existence of the
+ # target we actually use that gets defined by the protobuf
+ # CMake Package Configuration Module to determine if that
+ # worked. A bit of extra logic is required in the case of the
+ # config mode working, because some systems ship compatibility
+ # logic for the old FindProtobuf module while others do not.
+ #
+ # Upstream bug reference: https://gitlab.kitware.com/cmake/cmake/-/issues/24321
+ find_package(Protobuf CONFIG)
+
+ if(NOT TARGET protobuf::libprotobuf)
+ message(STATUS "Could not find Protobuf using Config mode, falling back to Module mode")
+ find_package(Protobuf REQUIRED)
+ endif()
+ endif()
+
+ if(TARGET protobuf::libprotobuf)
+ if(NOT Protobuf_PROTOC_EXECUTABLE AND TARGET protobuf::protoc)
+ set(Protobuf_PROTOC_EXECUTABLE protobuf::protoc)
+ endif()
+
+ # It is technically possible that this may still not
+ # be set by this point, so we need to check it and
+ # fail noisily if it isn't because the build won't
+ # work without it.
+ if(NOT Protobuf_PROTOC_EXECUTABLE)
+ message(FATAL_ERROR "Could not determine the location of the protobuf compiler for the detected version of protobuf.")
+ endif()
+
+ set(PROTOBUF_PROTOC_EXECUTABLE ${Protobuf_PROTOC_EXECUTABLE})
+ set(PROTOBUF_LIBRARIES protobuf::libprotobuf)
+ endif()
+
+ set(ENABLE_PROTOBUF True)
+ set(HAVE_PROTOBUF True)
+ endif()
+endmacro()
+
+# Helper function to compile protocol definitions into C++ code.
+function(netdata_protoc_generate_cpp INC_DIR OUT_DIR SRCS HDRS)
+ if(NOT ARGN)
+ message(SEND_ERROR "Error: protoc_generate_cpp() called without any proto files")
+ return()
+ endif()
+
+ set(${INC_DIR})
+ set(${OUT_DIR})
+ set(${SRCS})
+ set(${HDRS})
+
+ foreach(FIL ${ARGN})
+ get_filename_component(ABS_FIL ${FIL} ABSOLUTE)
+ get_filename_component(DIR ${ABS_FIL} DIRECTORY)
+ get_filename_component(FIL_WE ${FIL} NAME_WE)
+
+ set(GENERATED_PB_CC "${DIR}/${FIL_WE}.pb.cc")
+ list(APPEND ${SRCS} ${GENERATED_PB_CC})
+
+ set(GENERATED_PB_H "${DIR}/${FIL_WE}.pb.h")
+ list(APPEND ${HDRS} ${GENERATED_PB_H})
+
+ list(APPEND _PROTOC_INCLUDE_DIRS ${INC_DIR})
+
+ if(ENABLE_BUNDLED_PROTOBUF)
+ list(APPEND _PROTOC_INCLUDE_DIRS ${CMAKE_BINARY_DIR}/_deps/protobuf-src/src/)
+ endif()
+
+ add_custom_command(OUTPUT ${GENERATED_PB_CC} ${GENERATED_PB_H}
+ COMMAND ${PROTOBUF_PROTOC_EXECUTABLE}
+ ARGS "-I$<JOIN:${_PROTOC_INCLUDE_DIRS},;-I>" --cpp_out=${OUT_DIR} ${ABS_FIL}
+ DEPENDS ${ABS_FIL} ${PROTOBUF_PROTOC_EXECUTABLE}
+ COMMENT "Running C++ protocol buffer compiler on ${FIL}"
+ COMMAND_EXPAND_LISTS)
+ endforeach()
+
+ set_source_files_properties(${${SRCS}} ${${HDRS}} PROPERTIES GENERATED TRUE)
+ set_source_files_properties(${${SRCS}} ${${HDRS}} PROPERTIES COMPILE_OPTIONS -Wno-deprecated-declarations)
+
+ set(${SRCS} ${${SRCS}} PARENT_SCOPE)
+ set(${HDRS} ${${HDRS}} PARENT_SCOPE)
+endfunction()
+
+# Add protobuf to a specified target.
+function(netdata_add_protobuf _target)
+ if(ENABLE_BUNDLED_PROTOBUF)
+ target_include_directories(${_target} BEFORE PRIVATE ${PROTOBUF_INCLUDE_DIRS})
+ else()
+ target_include_directories(${_target} PRIVATE ${PROTOBUF_INCLUDE_DIRS})
+ endif()
+
+ target_compile_options(${_target} PRIVATE ${PROTOBUF_CFLAGS_OTHER})
+ target_link_libraries(${_target} PRIVATE ${PROTOBUF_LIBRARIES})
+endfunction()
diff --git a/packaging/cmake/Modules/NetdataSentry.cmake b/packaging/cmake/Modules/NetdataSentry.cmake
new file mode 100644
index 000000000..b20aeedd5
--- /dev/null
+++ b/packaging/cmake/Modules/NetdataSentry.cmake
@@ -0,0 +1,30 @@
+# Functions and macros for handling of Sentry
+#
+# Copyright (c) 2024 Netdata Inc.
+# SPDX-License-Identifier: GPL-3.0-or-later
+
+# Handle bundling of Sentry.
+#
+# This pulls it in as a sub-project using FetchContent functionality.
+#
+# This needs to be a function and not a macro for variable scoping
+# reasons. All the things we care about from the sub-project are exposed
+# as targets, which are globally scoped and not function scoped.
+function(netdata_bundle_sentry)
+ include(FetchContent)
+
+ # ignore debhelper
+ set(FETCHCONTENT_FULLY_DISCONNECTED Off)
+
+ set(SENTRY_VERSION 0.6.6)
+ set(SENTRY_BACKEND "breakpad")
+ set(SENTRY_BUILD_SHARED_LIBS OFF)
+
+ FetchContent_Declare(
+ sentry
+ GIT_REPOSITORY https://github.com/getsentry/sentry-native.git
+ GIT_TAG c97bcc63fa89ae557cef9c9b6e3acb11a72ff97d # v0.6.6
+ CMAKE_ARGS ${NETDATA_CMAKE_PROPAGATE_TOOLCHAIN_ARGS}
+ )
+ FetchContent_MakeAvailable(sentry)
+endfunction()
diff --git a/packaging/cmake/Modules/NetdataUtil.cmake b/packaging/cmake/Modules/NetdataUtil.cmake
new file mode 100644
index 000000000..c6a13309f
--- /dev/null
+++ b/packaging/cmake/Modules/NetdataUtil.cmake
@@ -0,0 +1,146 @@
+# Utility functions used by other modules.
+#
+# Copyright (c) 2024 Netdata Inc.
+# SPDX-License-Identifier: GPL-3.0-or-later
+
+include_guard()
+
+# Determine the version of the host kernel.
+#
+# Only works on UNIX-like systems, stores the version in the cache
+# variable HOST_KERNEL_VERSION.
+function(netdata_detect_host_kernel_version)
+ if(DEFINED HOST_KERNEL_VERSION)
+ return()
+ endif()
+
+ message(CHECK_START "Determining host kernel version")
+
+ if(NOT CMAKE_CROSSCOMPILING)
+ include(CheckIncludeFile)
+
+ check_include_file("linux/version.h" CAN_USE_VERSION_H)
+
+ if(CAN_USE_VERSION_H)
+ message(CHECK_START "Checking version using linux/version.h")
+ file(WRITE "${CMAKE_BINARY_DIR}/kversion-test.c" "
+ #include <stdio.h>
+ #include <linux/version.h>
+
+ int main() {
+ printf(\"%i.%i.%i\", LINUX_VERSION_MAJOR, LINUX_VERSION_PATCHLEVEL, LINUX_VERSION_SUBLEVEL);
+ }
+ ")
+
+ try_run(_run_success _compile_success
+ ${CMAKE_BINARY_DIR}
+ SOURCES ${CMAKE_BINARY_DIR}/kversion-test.c
+ RUN_OUTPUT_VARIABLE _kversion_output)
+
+ if(_compile_success AND _run_success EQUAL 0)
+ message(CHECK_PASS "success")
+ set(_kversion_value "${_kversion_output}")
+ else()
+ message(CHECK_FAIL "failed")
+ endif()
+ endif()
+ endif()
+
+ if(NOT DEFINED _kversion_value)
+ message(CHECK_START "Checking version using uname")
+ execute_process(COMMAND uname -r
+ RESULT_VARIABLE _uname_result
+ OUTPUT_VARIABLE _uname_output)
+
+ if(NOT _uname_result EQUAL 0)
+ message(CHECK_FAIL "failed")
+ message(CHECK_FAIL "unknown")
+ set(HOST_KERNEL_VERSION "0.0.0" CACHE STRING "Detected host kernel version")
+ return()
+ else()
+ message(CHECK_PASS "success")
+ endif()
+
+ set(_kversion_value "${_uname_output}")
+ endif()
+
+ string(REGEX REPLACE "-.+$" "" _kversion "${_kversion_value}")
+ message(CHECK_PASS "${_kversion}")
+ set(HOST_KERNEL_VERSION "${_kversion}" CACHE STRING "Detected host kernel version")
+endfunction()
+
+# Check what libc we're using.
+#
+# Sets the specified variable to the name of the libc or "unknown"
+function(netdata_identify_libc _libc_name)
+ if(NOT DEFINED _ND_DETECTED_LIBC)
+ message(CHECK_START "Detecting libc implementation using ldd")
+
+ execute_process(COMMAND ldd --version
+ COMMAND grep -q -i -E "glibc|gnu libc"
+ RESULT_VARIABLE LDD_RESULT
+ OUTPUT_VARIABLE LDD_OUTPUT
+ ERROR_VARIABLE LDD_OUTPUT)
+
+ if(NOT LDD_RESULT)
+ set(${_libc_name} glibc PARENT_SCOPE)
+ set(_ND_DETECTED_LIBC glibc CACHE INTERNAL "")
+ message(CHECK_PASS "glibc")
+ return()
+ endif()
+
+ execute_process(COMMAND sh -c "ldd --version 2>&1 | grep -q -i 'musl'"
+ RESULT_VARIABLE LDD_RESULT
+ OUTPUT_VARIABLE LDD_OUTPUT
+ ERROR_VARIABLE LDD_OUTPUT)
+
+ if(NOT LDD_RESULT)
+ set(${_libc_name} musl PARENT_SCOPE)
+ set(_ND_DETECTED_LIBC musl CACHE INTERNAL "")
+ message(CHECK_PASS "musl")
+ return()
+ endif()
+
+ message(CHECK_FAIL "unknown")
+
+ message(CHECK_START "Looking for libc.so.6")
+ find_program(LIBC_PATH libc.so.6
+ PATHS /lib /lib64 /usr/lib /usr/lib64
+ NO_DEFAULT_PATH
+ NO_PACKAGE_ROOT_PATH
+ NO_CMAKE_PATH
+ NO_CMAKE_ENVIRONMENT_PATH
+ NO_SYSTEM_ENVIRONMENT_PATH
+ NO_CMAKE_SYSTEM_PATH
+ NO_CMAKE_INSTALL_PREFIX
+ NO_CMAKE_FIND_ROOT_PATH)
+
+ if(NOT "${LIBC_PATH}" EQUAL "LIBC_PATH-NOTFOUND")
+ message(CHECK_PASS "found")
+ message(CHECK_START "Detecting libc implementation using libc.so.6")
+
+ execute_process(COMMAND "${LIBC_PATH}"
+ COMMAND head -n 1
+ COMMAND grep -q -i -E "gnu libc|gnu c library"
+ RESULT_VARIABLE LIBC_RESULT
+ OUTPUT_VARIABLE LIBC_OUTPUT
+ ERROR_VARIABLE LIBC_ERROR)
+
+ if(NOT LIBC_RESULT)
+ set(${_libc_name} glibc PARENT_SCOPE)
+ set(_ND_DETECTED_LIBC glibc CACHE INTERNAL "")
+ message(CHECK_PASS "glibc")
+ return()
+ else()
+ message(CHECK_FAIL "unknown")
+ endif()
+ else()
+ message(CHECK_FAIL "not found")
+ endif()
+
+ set(${_libc_name} unknown PARENT_SCOPE)
+ set(_ND_DETECTED_LIBC unknown CACHE INTERNAL "")
+ else()
+ set(${_libc_name} ${_ND_DETECTED_LIBC} PARENT_SCOPE)
+ endif()
+endfunction()
diff --git a/packaging/cmake/Modules/NetdataVersion.cmake b/packaging/cmake/Modules/NetdataVersion.cmake
new file mode 100644
index 000000000..b4bdd43b0
--- /dev/null
+++ b/packaging/cmake/Modules/NetdataVersion.cmake
@@ -0,0 +1,51 @@
+# Copyright (c) 2024 Netdata Inc.
+# SPDX-License-Identifier: GPL-3.0-or-later
+
+# Function to provide information regarding the Netdata version.
+#
+# The high-level logic is (a) use git-describe, (b) fallback to info from
+# packaging/version. This version field are used for cmake's project,
+# cpack's packaging, and the agent's functionality.
+function(netdata_version)
+ 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 "${CMAKE_SOURCE_DIR}/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)
+ set(NETDATA_VERSION_STRING "${GIT_DESCRIBE_OUTPUT}" PARENT_SCOPE)
+
+ 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(NETDATA_VERSION_MAJOR ${CMAKE_MATCH_1} PARENT_SCOPE)
+ set(NETDATA_VERSION_MINOR ${CMAKE_MATCH_2} PARENT_SCOPE)
+ set(NETDATA_VERSION_PATCH ${CMAKE_MATCH_3} PARENT_SCOPE)
+ set(NETDATA_VERSION_TWEAK 0 PARENT_SCOPE)
+ set(NETDATA_VERSION_DESCR "N/A" PARENT_SCOPE)
+ elseif(CMAKE_MATCH_COUNT EQUAL 4)
+ set(NETDATA_VERSION_MAJOR ${CMAKE_MATCH_1} PARENT_SCOPE)
+ set(NETDATA_VERSION_MINOR ${CMAKE_MATCH_2} PARENT_SCOPE)
+ set(NETDATA_VERSION_PATCH ${CMAKE_MATCH_3} PARENT_SCOPE)
+ set(NETDATA_VERSION_TWEAK ${CMAKE_MATCH_4} PARENT_SCOPE)
+ set(NETDATA_VERSION_DESCR "N/A" PARENT_SCOPE)
+ elseif(CMAKE_MATCH_COUNT EQUAL 5)
+ set(NETDATA_VERSION_MAJOR ${CMAKE_MATCH_1} PARENT_SCOPE)
+ set(NETDATA_VERSION_MINOR ${CMAKE_MATCH_2} PARENT_SCOPE)
+ set(NETDATA_VERSION_PATCH ${CMAKE_MATCH_3} PARENT_SCOPE)
+ set(NETDATA_VERSION_TWEAK ${CMAKE_MATCH_4} PARENT_SCOPE)
+ set(NETDATA_VERSION_DESCR ${CMAKE_MATCH_5} PARENT_SCOPE)
+ else()
+ message(FATAL_ERROR "Wrong version regex match count ${CMAKE_MATCH_COUNT} (should be in 3, 4 or 5)")
+ endif()
+endfunction()
diff --git a/packaging/cmake/Modules/NetdataYAML.cmake b/packaging/cmake/Modules/NetdataYAML.cmake
new file mode 100644
index 000000000..f2f9b404e
--- /dev/null
+++ b/packaging/cmake/Modules/NetdataYAML.cmake
@@ -0,0 +1,71 @@
+# Functions and macros for handling of libYAML
+#
+# Copyright (c) 2024 Netdata Inc.
+# SPDX-License-Identifier: GPL-3.0-or-later
+
+# Handle bundling of libyaml.
+#
+# This pulls it in as a sub-project using FetchContent functionality.
+#
+# This needs to be a function and not a macro for variable scoping
+# reasons. All the things we care about from the sub-project are exposed
+# as targets, which are globally scoped and not function scoped.
+function(netdata_bundle_libyaml)
+ include(FetchContent)
+ include(NetdataFetchContentExtra)
+
+ if(ENABLE_BUNDLED_LIBYAML)
+ set(FETCHCONTENT_TRY_FIND_PACKAGE_MODE NEVER)
+ endif()
+
+ set(FETCHCONTENT_FULLY_DISCONNECTED Off)
+
+ FetchContent_Declare(yaml
+ GIT_REPOSITORY https://github.com/yaml/libyaml
+ GIT_TAG 2c891fc7a770e8ba2fec34fc6b545c672beb37e6 # v0.2.5
+ CMAKE_ARGS ${NETDATA_CMAKE_PROPAGATE_TOOLCHAIN_ARGS}
+ )
+
+ FetchContent_MakeAvailable_NoInstall(yaml)
+endfunction()
+
+# Handle setup of libyaml for the build.
+#
+# This will attempt to find libyaml using pkg_check_modules. If it finds
+# a usable copy, that will be used. If not, it will bundle a vendored copy
+# as a sub-project.
+#
+# Irrespective of how libyaml is to be included, library names,
+# include directories, and compile definitions will be specified in the
+# NETDATA_YAML_* variables for later use.
+macro(netdata_detect_libyaml)
+ set(HAVE_LIBYAML True)
+
+ pkg_check_modules(YAML yaml-0.1)
+
+ if(ENABLE_BUNDLED_LIBYAML OR NOT YAML_FOUND)
+ netdata_bundle_libyaml()
+ set(ENABLE_BUNDLED_LIBYAML True PARENT_SCOPE)
+ set(NETDATA_YAML_LDFLAGS yaml)
+ get_target_property(NETDATA_YAML_INCLUDE_DIRS yaml INTERFACE_INCLUDE_DIRECTORIES)
+ get_target_property(NETDATA_YAML_CFLAGS_OTHER yaml INTERFACE_COMPILE_DEFINITIONS)
+ else()
+ set(NETDATA_YAML_LDFLAGS ${YAML_LDFLAGS})
+ set(NETDATA_YAML_CFLAGS_OTHER ${YAML_CFLAGS_OTHER})
+ set(NETDATA_YAML_INCLUDE_DIRS ${YAML_INCLUDE_DIRS})
+ endif()
+endmacro()
+
+# Add libyaml as a public link dependency of the specified target.
+#
+# The specified target must already exist, and the netdata_detect_libyaml
+# macro must have already been run at least once for this to work correctly.
+function(netdata_add_libyaml_to_target _target)
+ if(ENABLE_BUNDLED_LIBYAML)
+ target_include_directories(${_target} BEFORE PUBLIC ${NETDATA_YAML_INCLUDE_DIRS})
+ else()
+ target_include_directories(${_target} PUBLIC ${NETDATA_YAML_INCLUDE_DIRS})
+ endif()
+ target_compile_options(${_target} PUBLIC ${NETDATA_YAML_CFLAGS_OTHER})
+ target_link_libraries(${_target} PUBLIC ${NETDATA_YAML_LDFLAGS})
+endfunction()
diff --git a/packaging/cmake/Modules/Packaging.cmake b/packaging/cmake/Modules/Packaging.cmake
new file mode 100644
index 000000000..1dd2328cd
--- /dev/null
+++ b/packaging/cmake/Modules/Packaging.cmake
@@ -0,0 +1,503 @@
+#
+# CPack options
+#
+
+if(NETDATA_VERSION_DESCR STREQUAL "N/A")
+ set(CPACK_PACKAGE_VERSION ${NETDATA_VERSION_MAJOR}.${NETDATA_VERSION_MINOR}.${NETDATA_VERSION_PATCH})
+else()
+ set(CPACK_PACKAGE_VERSION ${NETDATA_VERSION_MAJOR}.${NETDATA_VERSION_MINOR}.${NETDATA_VERSION_PATCH}-${NETDATA_VERSION_TWEAK}-${NETDATA_VERSION_DESCR})
+endif()
+
+set(CPACK_THREADS 0)
+
+set(CPACK_STRIP_FILES NO)
+set(CPACK_DEBIAN_DEBUGINFO_PACKAGE NO)
+
+set(CPACK_DEBIAN_PACKAGE_SHLIBDEPS YES)
+
+set(CPACK_PACKAGING_INSTALL_PREFIX "/")
+
+set(CPACK_PACKAGE_VENDOR "Netdata Inc.")
+
+set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_SOURCE_DIR}/LICENSE")
+set(CPACK_RESOURCE_FILE_README "${CMAKE_SOURCE_DIR}/README.md")
+
+set(CPACK_PACKAGE_INSTALL_DIRECTORY "netdata")
+set(CPACK_PACKAGE_DIRECTORY "${CMAKE_BINARY_DIR}/packages")
+
+# to silence lintian
+set(CPACK_INSTALL_DEFAULT_DIRECTORY_PERMISSIONS
+ OWNER_READ OWNER_WRITE OWNER_EXECUTE
+ GROUP_READ GROUP_EXECUTE
+ WORLD_READ WORLD_EXECUTE)
+
+#
+# Debian options
+#
+
+set(CPACK_DEB_COMPONENT_INSTALL YES)
+set(CPACK_DEBIAN_ENABLE_COMPONENT_DEPENDS YES)
+set(CPACK_DEBIAN_FILE_NAME DEB-DEFAULT)
+
+set(CPACK_DEBIAN_PACKAGE_MAINTAINER "Netdata Builder <bot@netdata.cloud>")
+
+#
+# netdata
+#
+
+set(CPACK_COMPONENT_NETDATA_DESCRIPTION
+ "real-time charts for system monitoring
+ Netdata is a daemon that collects data in realtime (per second)
+ and presents a web site to view and analyze them. The presentation
+ is also real-time and full of interactive charts that precisely
+ render all collected values.")
+
+set(CPACK_DEBIAN_NETDATA_PACKAGE_NAME "netdata")
+set(CPACK_DEBIAN_NETDATA_PACKAGE_SECTION "net")
+set(CPACK_DEBIAN_NETDATA_PACKAGE_PREDEPENDS "adduser, libcap2-bin")
+set(CPACK_DEBIAN_NETDATA_PACKAGE_SUGGESTS
+ "netdata-plugin-cups (= ${CPACK_PACKAGE_VERSION}), netdata-plugin-freeipmi (= ${CPACK_PACKAGE_VERSION})")
+set(CPACK_DEBIAN_NETDATA_PACKAGE_RECOMMENDS
+ "netdata-plugin-systemd-journal (= ${CPACK_PACKAGE_VERSION}), \
+netdata-plugin-logs-management (= ${CPACK_PACKAGE_VERSION}), \
+netdata-plugin-network-viewer (= ${CPACK_PACKAGE_VERSION})")
+set(CPACK_DEBIAN_NETDATA_PACKAGE_CONFLICTS
+ "netdata-core, netdata-plugins-bash, netdata-plugins-python, netdata-web")
+
+list(APPEND _main_deps "netdata-plugin-chartsd (= ${CPACK_PACKAGE_VERSION})")
+list(APPEND _main_deps "netdata-plugin-pythond (= ${CPACK_PACKAGE_VERSION})")
+
+if(ENABLE_PLUGIN_APPS)
+ list(APPEND _main_deps "netdata-plugin-apps (= ${CPACK_PACKAGE_VERSION})")
+endif()
+
+if(ENABLE_PLUGIN_GO)
+ list(APPEND _main_deps "netdata-plugin-go (= ${CPACK_PACKAGE_VERSION})")
+endif()
+
+if(ENABLE_PLUGIN_DEBUGFS)
+ list(APPEND _main_deps "netdata-plugin-debugfs (= ${CPACK_PACKAGE_VERSION})")
+endif()
+
+if(ENABLE_PLUGIN_NFACCT)
+ list(APPEND _main_deps "netdata-plugin-nfacct (= ${CPACK_PACKAGE_VERSION})")
+endif()
+
+if(ENABLE_PLUGIN_SLABINFO)
+ list(APPEND _main_deps "netdata-plugin-slabinfo (= ${CPACK_PACKAGE_VERSION})")
+endif()
+
+if(ENABLE_PLUGIN_PERF)
+ list(APPEND _main_deps "netdata-plugin-perf (= ${CPACK_PACKAGE_VERSION})")
+endif()
+
+if(ENABLE_PLUGIN_EBPF)
+ list(APPEND _main_deps "netdata-plugin-ebpf (= ${CPACK_PACKAGE_VERSION})")
+endif()
+
+list(JOIN _main_deps ", " CPACK_DEBIAN_NETDATA_PACKAGE_DEPENDS)
+
+set(CPACK_DEBIAN_PACKAGE_CONTROL_EXTRA
+ "${PKG_FILES_PATH}/deb/netdata/conffiles;"
+ "${PKG_FILES_PATH}/deb/netdata/preinst"
+ "${PKG_FILES_PATH}/deb/netdata/postinst"
+ "${PKG_FILES_PATH}/deb/netdata/postrm")
+
+set(CPACK_DEBIAN_NETDATA_DEBUGINFO_PACKAGE On)
+
+#
+# apps.plugin
+#
+
+set(CPACK_COMPONENT_PLUGIN-APPS_DEPENDS "netdata")
+set(CPACK_COMPONENT_PLUGIN-APPS_DESCRIPTION
+ "The per-application metrics collector plugin for the Netdata Agent
+ This plugin allows the Netdata Agent to collect per-application and
+ per-user metrics without using cgroups.")
+
+set(CPACK_DEBIAN_PLUGIN-APPS_PACKAGE_NAME "netdata-plugin-apps")
+set(CPACK_DEBIAN_PLUGIN-APPS_PACKAGE_SECTION "net")
+set(CPACK_DEBIAN_PLUGIN-APPS_PACKAGE_CONFLICTS "netdata (<< 1.40)")
+set(CPACK_DEBIAN_PLUGIN-APPS_PACKAGE_PREDEPENDS "libcap2-bin, adduser")
+
+set(CPACK_DEBIAN_PLUGIN-APPS_PACKAGE_CONTROL_EXTRA
+ "${PKG_FILES_PATH}/deb/plugin-apps/preinst;"
+ "${PKG_FILES_PATH}/deb/plugin-apps/postinst")
+
+set(CPACK_DEBIAN_PLUGIN-APPS_DEBUGINFO_PACKAGE On)
+
+#
+# charts.d.plugin
+#
+
+set(CPACK_COMPONENT_PLUGIN-CHARTSD_DEPENDS "netdata")
+set(CPACK_COMPONENT_PLUGIN-CHARTSD_DESCRIPTION
+ "The charts.d metrics collection plugin for the Netdata Agent
+ This plugin adds a selection of additional collectors written in shell
+ script to the Netdata Agent. It includes collectors for APCUPSD,
+ LibreSWAN, OpenSIPS, and Wireless access point statistics.")
+
+set(CPACK_DEBIAN_PLUGIN-CHARTSD_PACKAGE_NAME "netdata-plugin-chartsd")
+set(CPACK_DEBIAN_PLUGIN-CHARTSD_PACKAGE_SECTION "net")
+set(CPACK_DEBIAN_PLUGIN-CHARTSD_PACKAGE_CONFLICTS "netdata (<< 1.40)")
+set(CPACK_DEBIAN_PLUGIN-CHARTSD_PACKAGE_PREDEPENDS "adduser")
+set(CPACK_DEBIAN_PLUGIN-CHARTSD_PACKAGE_DEPENDS "bash")
+set(CPACK_DEBIAN_PLUGIN-CHARTSD_PACKAGE_ARCHITECTURE "all")
+set(CPACK_DEBIAN_PLUGIN-CHARTSD_PACKAGE_SUGGESTS "apcupsd, iw, sudo")
+
+set(CPACK_DEBIAN_PLUGIN-CHARTSD_PACKAGE_CONTROL_EXTRA
+ "${PKG_FILES_PATH}/deb/plugin-chartsd/preinst;"
+ "${PKG_FILES_PATH}/deb/plugin-chartsd/postinst")
+
+set(CPACK_DEBIAN_PLUGIN-CHARTSD_DEBUGINFO_PACKAGE Off)
+
+#
+# cups.plugin
+#
+
+set(CPACK_COMPONENT_PLUGIN-CUPS_DEPENDS "netdata")
+set(CPACK_COMPONENT_PLUGIN-CUPS_DESCRIPTION
+ "The CUPS metrics collection plugin for the Netdata Agent
+ This plugin allows the Netdata Agent to collect metrics from the Common UNIX Printing System.")
+
+set(CPACK_DEBIAN_PLUGIN-CUPS_PACKAGE_NAME "netdata-plugin-cups")
+set(CPACK_DEBIAN_PLUGIN-CUPS_PACKAGE_SECTION "net")
+set(CPACK_DEBIAN_PLUGIN-CUPS_PACKAGE_PREDEPENDS "adduser")
+set(CPACK_DEBIAN_PLUGIN-CUPS_PACKAGE_CONTROL_EXTRA
+ "${PKG_FILES_PATH}/deb/plugin-cups/preinst;"
+ "${PKG_FILES_PATH}/deb/plugin-cups/postinst")
+
+set(CPACK_DEBIAN_PLUGIN-CUPS_DEBUGINFO_PACKAGE On)
+
+#
+# debugfs.plugin
+#
+
+set(CPACK_COMPONENT_PLUGIN-DEBUGFS_DEPENDS "netdata")
+set(CPACK_COMPONENT_PLUGIN-DEBUGFS_DESCRIPTION
+ "The debugfs metrics collector for the Netdata Agent
+ This plugin allows the Netdata Agent to collect Linux kernel metrics
+ exposed through debugfs.")
+
+set(CPACK_DEBIAN_PLUGIN-DEBUGFS_PACKAGE_NAME "netdata-plugin-debugfs")
+set(CPACK_DEBIAN_PLUGIN-DEBUGFS_PACKAGE_SECTION "net")
+set(CPACK_DEBIAN_PLUGIN-DEBUGFS_PACKAGE_CONFLICTS "netdata (<< 1.40)")
+set(CPACK_DEBIAN_PLUGIN-DEBUGFS_PACKAGE_PREDEPENDS "libcap2-bin, adduser")
+set(CPACK_DEBIAN_PLUGIN-DEBUGFS_PACKAGE_CONTROL_EXTRA
+ "${PKG_FILES_PATH}/deb/plugin-debugfs/preinst;"
+ "${PKG_FILES_PATH}/deb/plugin-debugfs/postinst")
+
+set(CPACK_DEBIAN_PLUGIN-DEBUGFS_DEBUGINFO_PACKAGE On)
+
+#
+# ebpf.plugin
+#
+
+set(CPACK_COMPONENT_PLUGIN-EBPF_DEPENDS "netdata")
+set(CPACK_COMPONENT_PLUGIN-EBPF_DESCRIPTION
+ "The eBPF metrics collection plugin for the Netdata Agent
+ This plugin allows the Netdata Agent to use eBPF code to collect more
+ detailed kernel-level metrics for the system.")
+
+set(CPACK_DEBIAN_PLUGIN-EBPF_PACKAGE_NAME "netdata-plugin-ebpf")
+set(CPACK_DEBIAN_PLUGIN-EBPF_PACKAGE_SECTION "net")
+set(CPACK_DEBIAN_PLUGIN-EBPF_PACKAGE_CONFLICTS "netdata (<< 1.40)")
+set(CPACK_DEBIAN_PLUGIN-EBPF_PACKAGE_PREDEPENDS "adduser")
+set(CPACK_DEBIAN_PLUGIN-EBPF_PACKAGE_RECOMMENDS "netdata-plugin-apps (= ${CPACK_PACKAGE_VERSION}), netdata-ebpf-code-legacy (= ${CPACK_PACKAGE_VERSION})")
+
+set(CPACK_DEBIAN_PLUGIN-EBPF_PACKAGE_CONTROL_EXTRA
+ "${PKG_FILES_PATH}/deb/plugin-ebpf/preinst;"
+ "${PKG_FILES_PATH}/deb/plugin-ebpf/postinst")
+
+set(CPACK_DEBIAN_PLUGIN-EBPF_DEBUGINFO_PACKAGE On)
+
+#
+# ebpf-code-legacy
+#
+
+set(CPACK_COMPONENT_EBPF-CODE-LEGACY_DEPENDS "netdata")
+set(CPACK_COMPONENT_EBPF-CODE-LEGACY_DESCRIPTION
+ "Compiled eBPF legacy code for the Netdata eBPF plugin
+ This package provides the pre-compiled eBPF legacy code for use by
+ the Netdata eBPF plugin. This code is only needed when using the eBPF
+ plugin with kernel that do not include BTF support (mostly kernel
+ versions lower than 5.10).")
+
+set(CPACK_DEBIAN_EBPF-CODE-LEGACY_PACKAGE_NAME "netdata-ebpf-code-legacy")
+set(CPACK_DEBIAN_EBPF-CODE-LEGACY_PACKAGE_SECTION "net")
+set(CPACK_DEBIAN_EBPF-CODE-LEGACY_PACKAGE_CONFLICTS "netdata (<< 1.40)")
+set(CPACK_DEBIAN_EBPF-CODE-LEGACY_PACKAGE_PREDEPENDS "adduser")
+set(CPACK_DEBIAN_EBPF-CODE-LEGACY_PACKAGE_RECOMMENDS "netdata-plugin-ebpf (= ${CPACK_PACKAGE_VERSION})")
+
+set(CPACK_DEBIAN_EBPF-CODE-LEGACY_PACKAGE_CONTROL_EXTRA
+ "${PKG_FILES_PATH}/deb/ebpf-code-legacy/preinst;"
+ "${PKG_FILES_PATH}/deb/ebpf-code-legacy/postinst")
+
+set(CPACK_DEBIAN_EBPF-CODE-LEGACY_DEBUGINFO_PACKAGE Off)
+
+#
+# freeipmi.plugin
+#
+
+set(CPACK_COMPONENT_PLUGIN-FREEIPMI_DEPENDS "netdata")
+set(CPACK_COMPONENT_PLUGIN-FREEIPMI_DESCRIPTION
+ "The FreeIPMI metrics collection plugin for the Netdata Agent
+ This plugin allows the Netdata Agent to collect metrics from hardware
+ using FreeIPMI.")
+
+set(CPACK_DEBIAN_PLUGIN-FREEIPMI_PACKAGE_NAME "netdata-plugin-freeipmi")
+set(CPACK_DEBIAN_PLUGIN-FREEIPMI_PACKAGE_SECTION "net")
+set(CPACK_DEBIAN_PLUGIN-FREEIPMI_PACKAGE_PREDEPENDS "adduser")
+
+set(CPACK_DEBIAN_PLUGIN-FREEIPMI_PACKAGE_CONTROL_EXTRA
+ "${PKG_FILES_PATH}/deb/plugin-freeipmi/preinst;"
+ "${PKG_FILES_PATH}/deb/plugin-freeipmi/postinst")
+
+set(CPACK_DEBIAN_PLUGIN-FREEIPMI_DEBUGINFO_PACKAGE On)
+
+#
+# go.plugin
+#
+
+set(CPACK_COMPONENT_PLUGIN-GO_DEPENDS "netdata")
+set(CPACK_COMPONENT_PLUGIN-GO_DESCRIPTION
+ "The go.d metrics collection plugin for the Netdata Agent
+ This plugin adds a selection of additional collectors written in Go to
+ the Netdata Agent. A significant percentage of the application specific
+ collectors provided by Netdata are part of this plugin, so most users
+ will want it installed.")
+
+set(CPACK_DEBIAN_PLUGIN-GO_PACKAGE_NAME "netdata-plugin-go")
+set(CPACK_DEBIAN_PLUGIN-GO_PACKAGE_SECTION "net")
+set(CPACK_DEBIAN_PLUGIN-GO_PACKAGE_CONFLICTS "netdata (<< 1.40)")
+set(CPACK_DEBIAN_PLUGIN-GO_PACKAGE_PREDEPENDS "libcap2-bin, adduser")
+set(CPACK_DEBIAN_PLUGIN-GO_PACKAGE_SUGGESTS "nvme-cli")
+
+set(CPACK_DEBIAN_PLUGIN-GO_PACKAGE_CONTROL_EXTRA
+ "${PKG_FILES_PATH}/deb/plugin-go/preinst;"
+ "${PKG_FILES_PATH}/deb/plugin-go/postinst")
+
+set(CPACK_DEBIAN_PLUGIN-GO_DEBUGINFO_PACKAGE Off)
+
+#
+# logs-management.plugin
+#
+
+set(CPACK_COMPONENT_PLUGIN-LOGS-MANAGEMENT_DEPENDS "netdata")
+set(CPACK_COMPONENT_PLUGIN-LOGS-MANAGEMENT_DESCRIPTION
+ "The logs-management plugin for the Netdata Agent
+ This plugin allows the Netdata Agent to collect logs from the system
+ and parse them to extract metrics.")
+
+set(CPACK_DEBIAN_PLUGIN-LOGS-MANAGEMENT_PACKAGE_NAME "netdata-plugin-logs-management")
+set(CPACK_DEBIAN_PLUGIN-LOGS-MANAGEMENT_PACKAGE_SECTION "net")
+set(CPACK_DEBIAN_PLUGIN-LOGS-MANAGEMENT_PACKAGE_PREDEPENDS "libcap2-bin, adduser")
+
+set(CPACK_DEBIAN_PLUGIN-LOGS-MANAGEMENT_PACKAGE_CONTROL_EXTRA
+ "${PKG_FILES_PATH}/deb/plugin-logs-management/preinst;"
+ "${PKG_FILES_PATH}/deb/plugin-logs-management/postinst")
+
+set(CPACK_DEBIAN_PLUGIN-LOGS-MANAGEMENT_DEBUGINFO_PACKAGE On)
+
+#
+# network-viewer.plugin
+#
+
+# TODO: recommends netdata-plugin-ebpf
+set(CPACK_COMPONENT_PLUGIN-NETWORK-VIEWER_DEPENDS "netdata")
+set(CPACK_COMPONENT_PLUGIN-NETWORK-VIEWER_DESCRIPTION
+ "The network viewer plugin for the Netdata Agent
+ This plugin allows the Netdata Agent to provide network connection
+ mapping functionality for use in Netdata Cloud.")
+
+set(CPACK_DEBIAN_PLUGIN-NETWORK_VIEWER_PACKAGE_NAME "netdata-plugin-network-viewer")
+set(CPACK_DEBIAN_PLUGIN-NETWORK-VIEWER_PACKAGE_SECTION "net")
+set(CPACK_DEBIAN_PLUGIN-NETWORK-VIEWER_PACKAGE_PREDEPENDS "libcap2-bin, adduser")
+set(CPACK_DEBIAN_PLUGIN-NETWORK-VIEWER_PACKAGE_RECOMMENDS "netdata-plugin-ebpf (= ${CPACK_PACKAGE_VERSION})")
+
+set(CPACK_DEBIAN_PLUGIN-NETWORK-VIEWER_PACKAGE_CONTROL_EXTRA
+ "${PKG_FILES_PATH}/deb/plugin-network-viewer/preinst;"
+ "${PKG_FILES_PATH}/deb/plugin-network-viewer/postinst")
+
+set(CPACK_DEBIAN_PLUGIN-NETWORK-VIEWER_DEBUGINFO_PACKAGE On)
+
+#
+# nfacct.plugin
+#
+
+set(CPACK_COMPONENT_PLUGIN-NFACCT_DEPENDS "netdata")
+set(CPACK_COMPONENT_PLUGIN-NFACCT_DESCRIPTION
+ "The NFACCT metrics collection plugin for the Netdata Agent
+ This plugin allows the Netdata Agent to collect metrics from the firewall
+ using NFACCT objects.")
+
+set(CPACK_DEBIAN_PLUGIN-NFACCT_PACKAGE_NAME "netdata-plugin-nfacct")
+set(CPACK_DEBIAN_PLUGIN-NFACCT_PACKAGE_SECTION "net")
+set(CPACK_DEBIAN_PLUGIN-NFACCT_PACKAGE_CONFLICTS "netdata (<< 1.40)")
+set(CPACK_DEBIAN_PLUGIN-NFACCT_PACKAGE_PREDEPENDS "adduser")
+
+set(CPACK_DEBIAN_PLUGIN-NFACCT_PACKAGE_CONTROL_EXTRA
+ "${PKG_FILES_PATH}/deb/plugin-nfacct/preinst;"
+ "${PKG_FILES_PATH}/deb/plugin-nfacct/postinst")
+
+set(CPACK_DEBIAN_PLUGIN-NFACCT_DEBUGINFO_PACKAGE On)
+
+#
+# perf.plugin
+#
+
+set(CPACK_COMPONENT_PLUGIN-PERF_DEPENDS "netdata")
+set(CPACK_COMPONENT_PLUGIN-PERF_DESCRIPTION
+ "The perf metrics collector for the Netdata Agent
+ This plugin allows the Netdata to collect metrics from the Linux perf
+ subsystem.")
+
+set(CPACK_DEBIAN_PLUGIN-PERF_PACKAGE_NAME "netdata-plugin-perf")
+set(CPACK_DEBIAN_PLUGIN-PERF_PACKAGE_SECTION "net")
+set(CPACK_DEBIAN_PLUGIN-PERF_PACKAGE_CONFLICTS "netdata (<< 1.40)")
+set(CPACK_DEBIAN_PLUGIN-PERF_PACKAGE_PREDEPENDS "libcap2-bin, adduser")
+
+set(CPACK_DEBIAN_PLUGIN-PERF_PACKAGE_CONTROL_EXTRA
+ "${PKG_FILES_PATH}/deb/plugin-perf/preinst;"
+ "${PKG_FILES_PATH}/deb/plugin-perf/postinst")
+
+set(CPACK_DEBIAN_PLUGIN-PERF_DEBUGINFO_PACKAGE On)
+
+#
+# pythond.plugin
+#
+
+set(CPACK_COMPONENT_PLUGIN-PYTHOND_DEPENDS "netdata")
+set(CPACK_COMPONENT_PLUGIN-PYTHOND_DESCRIPTION
+ "The python.d metrics collection plugin for the Netdata Agent
+ Many of the collectors provided by this package are also available
+ in netdata-plugin-god. In msot cases, you probably want to use those
+ versions instead of the Python versions.")
+
+set(CPACK_DEBIAN_PLUGIN-PYTHOND_PACKAGE_NAME "netdata-plugin-pythond")
+set(CPACK_DEBIAN_PLUGIN-PYTHOND_PACKAGE_SECTION "net")
+set(CPACK_DEBIAN_PLUGIN-PYTHOND_PACKAGE_CONFLICTS "netdata (<< 1.40)")
+set(CPACK_DEBIAN_PLUGIN-PYTHOND_PACKAGE_PREDEPENDS "adduser")
+set(CPACK_DEBIAN_PLUGIN-PYTHOND_PACKAGE_SUGGESTS "sudo")
+set(CPACK_DEBIAN_PLUGIN-PYTHOND_PACHAGE_DEPENDS "python3")
+set(CPACK_DEBIAN_PLUGIN-PYTHOND_PACKAGE_ARCHITECTURE "all")
+
+set(CPACK_DEBIAN_PLUGIN-PYTHOND_PACKAGE_CONTROL_EXTRA
+ "${PKG_FILES_PATH}/deb/plugin-pythond/preinst;"
+ "${PKG_FILES_PATH}/deb/plugin-pythond/postinst")
+
+set(CPACK_DEBIAN_PLUGIN-PYTHOND_DEBUGINFO_PACKAGE Off)
+
+#
+# slabinfo.plugin
+#
+
+set(CPACK_COMPONENT_PLUGIN-SLABINFO_DEPENDS "netdata")
+set(CPACK_COMPONENT_PLUGIN-SLABINFO_DESCRIPTION
+ "The slabinfo metrics collector for the Netdata Agent
+ This plugin allows the Netdata Agent to collect perfromance and
+ utilization metrics for the Linux kernel’s SLAB allocator.")
+
+set(CPACK_DEBIAN_PLUGIN-SLABINFO_PACKAGE_NAME "netdata-plugin-slabinfo")
+set(CPACK_DEBIAN_PLUGIN-SLABINFO_PACKAGE_SECTION "net")
+set(CPACK_DEBIAN_PLUGIN-SLABINFO_PACKAGE_CONFLICTS "netdata (<< 1.40)")
+set(CPACK_DEBIAN_PLUGIN-SLABINFO_PACKAGE_PREDEPENDS "libcap2-bin, adduser")
+
+set(CPACK_DEBIAN_PLUGIN-SLABINFO_PACKAGE_CONTROL_EXTRA
+ "${PKG_FILES_PATH}/deb/plugin-slabinfo/preinst;"
+ "${PKG_FILES_PATH}/deb/plugin-slabinfo/postinst")
+
+set(CPACK_DEBIAN_PLUGIN-SLABINFO_DEBUGINFO_PACKAGE On)
+
+#
+# systemd-journal.plugin
+#
+
+set(CPACK_COMPONENT_PLUGIN-SYSTEMD-JOURNAL_DEPENDS "netdata")
+set(CPACK_COMPONENT_PLUGIN-SYSTEMD-JOURNAL_DESCRIPTION
+ "The systemd-journal collector for the Netdata Agent
+ This plugin allows the Netdata Agent to present logs from the systemd
+ journal on Netdata Cloud or the local Agent dashboard.")
+
+set(CPACK_DEBIAN_PLUGIN-SYSTEMD-JOURNAL_PACKAGE_NAME "netdata-plugin-systemd-journal")
+set(CPACK_DEBIAN_PLUGIN-SYSTEMD-JOURNAL_PACKAGE_SECTION "net")
+set(CPACK_DEBIAN_PLUGIN-SYSTEMD-JOURNAL_PACKAGE_PREDEPENDS "libcap2-bin, adduser")
+
+set(CPACK_DEBIAN_PLUGIN-SYSTEMD-JOURNAL_PACKAGE_CONTROL_EXTRA
+ "${PKG_FILES_PATH}/deb/plugin-systemd-journal/preinst;"
+ "${PKG_FILES_PATH}/deb/plugin-systemd-journal/postinst")
+
+set(CPACK_DEBIAN_PLUGIN-SYSTEMD_JOURNAL_DEBUGINFO_PACKAGE On)
+
+#
+# xenstat.plugin
+#
+
+set(CPACK_COMPONENT_PLUGIN-XENSTAT_DEPENDS "netdata")
+set(CPACK_COMPONENT_PLUGIN-XENSTAT_DESCRIPTION
+ "The xenstat plugin for the Netdata Agent
+ This plugin allows the Netdata Agent to collect metrics from the Xen
+ Hypervisor.")
+
+set(CPACK_DEBIAN_PLUGIN-XENSTAT_PACKAGE_NAME "netdata-plugin-xenstat")
+set(CPACK_DEBIAN_PLUGIN-XENSTAT_PACKAGE_SECTION "net")
+set(CPACK_DEBIAN_PLUGIN-XENSTAT_PACKAGE_CONFLICTS "netdata (<< 1.40)")
+set(CPACK_DEBIAN_PLUGIN-XENSTAT_PACKAGE_PREDEPENDS "adduser")
+
+set(CPACK_DEBIAN_PLUGIN-XENSTAT_PACKAGE_CONTROL_EXTRA
+ "${PKG_FILES_PATH}/deb/plugin-xenstat/preinst;"
+ "${PKG_FILES_PATH}/deb/plugin-xenstat/postinst")
+
+set(CPACK_DEBIAN_PLUGIN-XENSTAT_DEBUGINFO_PACKAGE On)
+
+#
+# CPack components
+#
+
+list(APPEND CPACK_COMPONENTS_ALL "netdata")
+if(ENABLE_PLUGIN_APPS)
+ list(APPEND CPACK_COMPONENTS_ALL "plugin-apps")
+endif()
+list(APPEND CPACK_COMPONENTS_ALL "plugin-chartsd")
+if(ENABLE_PLUGIN_CUPS)
+ list(APPEND CPACK_COMPONENTS_ALL "plugin-cups")
+endif()
+if(ENABLE_PLUGIN_DEBUGFS)
+ list(APPEND CPACK_COMPONENTS_ALL "plugin-debugfs")
+endif()
+if(ENABLE_PLUGIN_EBPF)
+ list(APPEND CPACK_COMPONENTS_ALL "plugin-ebpf")
+endif()
+if(ENABLE_EBPF_LEGACY_PROGRAMS)
+ list(APPEND CPACK_COMPONENTS_ALL "ebpf-code-legacy")
+endif()
+if(ENABLE_PLUGIN_FREEIPMI)
+ list(APPEND CPACK_COMPONENTS_ALL "plugin-freeipmi")
+endif()
+if(ENABLE_PLUGIN_GO)
+ list(APPEND CPACK_COMPONENTS_ALL "plugin-go")
+endif()
+if(ENABLE_PLUGIN_LOGS_MANAGEMENT)
+ list(APPEND CPACK_COMPONENTS_ALL "plugin-logs-management")
+endif()
+if(ENABLE_PLUGIN_NETWORK_VIEWER)
+ list(APPEND CPACK_COMPONENTS_ALL "plugin-network-viewer")
+endif()
+if(ENABLE_PLUGIN_NFACCT)
+ list(APPEND CPACK_COMPONENTS_ALL "plugin-nfacct")
+endif()
+if(ENABLE_PLUGIN_PERF)
+ list(APPEND CPACK_COMPONENTS_ALL "plugin-perf")
+endif()
+list(APPEND CPACK_COMPONENTS_ALL "plugin-pythond")
+if(ENABLE_PLUGIN_SLABINFO)
+ list(APPEND CPACK_COMPONENTS_ALL "plugin-slabinfo")
+endif()
+if(ENABLE_PLUGIN_SYSTEMD_JOURNAL)
+ list(APPEND CPACK_COMPONENTS_ALL "plugin-systemd-journal")
+endif()
+if(ENABLE_PLUGIN_XENSTAT)
+ list(APPEND CPACK_COMPONENTS_ALL "plugin-xenstat")
+endif()
+
+include(CPack)