@cryptotaxi247 / netdata-1 / commits / 804fd4ce5

Prefer Protobuf’s own CMake config over CMake's FindProtobuf. (#17128)

* Prefer Protobuf’s own CMake config over CMake's FindProtobuf. 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. Upstream bug reference: https://gitlab.kitware.com/cmake/cmake/-/issues/24321 * Properly handle protoc executable. * Restructure to explicitly handle fallback case ourselves. This allows proper handling of compatibility code in a way that actually works for us without us needing to ship a special module to handle the compatibility case. * Switch to bundling protobuf via CMake instead of an external script. * Fix handling of Protobuf inclusion. - Add correct include directories for protoc. - Skip installing protobuf when installing the agent. * Drop spurious quotation marks. * Properly fix generator expression for protoc include paths. * Properly default to bundling protobuf in installer code. * Disable ASAN in unit tests. It doesn’t work with the modified protobuf handling and per discussion with the team is non-critical. * Change comment based on review. * Revert "Disable ASAN in unit tests." This reverts commit 6cb98b1b59c55d639d68694424b98e790ba2f5a7. * Disable IPMI and NFACCT plugins for unit tests. We don’t actually have any unit tests for them, and they cause issues building reliably in the unit testing environment. * Disable ASAN for Abseil and Protobuf when vendoring them. * Switch to commit hashes for protobuf/abseil. * Restructure to better encapsulate protobuf handling as it’s own module. * Fix up bundled protobuf version handling. Google has complicated rules for C++ build environment support, so we really need to be checking compiler versions and not _just_ C++ standard version. * Fix warnings about invalid defines.

Austin S. Hemmelgarn committed Mar 20, 2024 at 07:13 UTC 804fd4ce548ba147f9b513517c3846cb6829f03d
10 files changed +283 -183
CMakeLists.txt
+30 -71
@@ -128,6 +128,12 @@ option(ENABLE_LOGS_MANAGEMENT_TESTS "enable logs management tests" True)
128 option(ENABLE_SENTRY "enable sentry" False)
129 option(ENABLE_WEBRTC "enable webrtc" False)
130
131 +if(ENABLE_ACLK OR ENABLE_EXPORTER_PROMETHEUS_REMOTE_WRITE)
132 + set(NEED_PROTOBUF True)
133 +else()
134 + set(NEED_PROTOBUF False)
135 +endif()
136 +
137 if(ENABLE_PLUGIN_GO)
138 include(NetdataGoTools)
139
@@ -173,6 +179,14 @@ if(ENABLE_WEBRTC)
179 FetchContent_MakeAvailable(libdatachannel)
180 endif()
181
182 +if(NEED_PROTOBUF)
183 + include(NetdataProtobuf)
184 +
185 + if(ENABLE_BUNDLED_PROTOBUF)
186 + netdata_bundle_protobuf()
187 + endif()
188 +endif()
189 +
190 #
191 # handling of extra compiler flags
192 #
@@ -491,24 +505,8 @@ endif()
505 # figure out if we need protoc/protobuf
506 #
507
494 -if(ENABLE_ACLK OR ENABLE_EXPORTER_PROMETHEUS_REMOTE_WRITE)
495 - if(ENABLE_BUNDLED_PROTOBUF)
496 - set(PROTOBUF_PROTOC_EXECUTABLE "${CMAKE_SOURCE_DIR}/externaldeps/protobuf/src/protoc")
497 - set(PROTOBUF_INCLUDE_DIRS "${CMAKE_SOURCE_DIR}/externaldeps/protobuf/src")
498 - set(PROTOBUF_LIBRARIES "${CMAKE_SOURCE_DIR}/externaldeps/protobuf/src/.libs/libprotobuf.a")
499 - else()
500 - if (NOT BUILD_SHARED_LIBS)
501 - set(Protobuf_USE_STATIC_LIBS On)
502 - endif()
503 -
504 - find_package(Protobuf REQUIRED)
505 - endif()
506 -
507 - set(ENABLE_PROTOBUF True)
508 - set(HAVE_PROTOBUF True)
509 - if (ENABLE_BUNDLED_PROTOBUF)
510 - set(BUNDLED_PROTOBUF True)
511 - endif()
508 +if(NEED_PROTOBUF)
509 + netdata_detect_protobuf()
510 endif()
511
512 #
@@ -1609,46 +1607,6 @@ if(MNL_FOUND)
1607 set(HAVE_LIBMNL True)
1608 endif()
1609
1612 -#
1613 -# helper function to build protos
1614 -#
1615 -
1616 -function(protoc_generate_cpp INC_DIR OUT_DIR SRCS HDRS)
1617 - if(NOT ARGN)
1618 - message(SEND_ERROR "Error: protoc_generate_cpp() called without any proto files")
1619 - return()
1620 - endif()
1621 -
1622 - set(${INC_DIR})
1623 - set(${OUT_DIR})
1624 - set(${SRCS})
1625 - set(${HDRS})
1626 -
1627 - foreach(FIL ${ARGN})
1628 - get_filename_component(ABS_FIL ${FIL} ABSOLUTE)
1629 - get_filename_component(DIR ${ABS_FIL} DIRECTORY)
1630 - get_filename_component(FIL_WE ${FIL} NAME_WE)
1631 -
1632 - set(GENERATED_PB_CC "${DIR}/${FIL_WE}.pb.cc")
1633 - list(APPEND ${SRCS} ${GENERATED_PB_CC})
1634 -
1635 - set(GENERATED_PB_H "${DIR}/${FIL_WE}.pb.h")
1636 - list(APPEND ${HDRS} ${GENERATED_PB_H})
1637 -
1638 - add_custom_command(OUTPUT ${GENERATED_PB_CC} ${GENERATED_PB_H}
1639 - COMMAND ${PROTOBUF_PROTOC_EXECUTABLE} ARGS -I=${INC_DIR} --cpp_out=${OUT_DIR} ${ABS_FIL}
1640 - DEPENDS ${ABS_FIL} ${PROTOBUF_PROTOC_EXECUTABLE}
1641 - COMMENT "Running C++ protocol buffer compiler on ${FIL}"
1642 - VERBATIM)
1643 - endforeach()
1644 -
1645 - set_source_files_properties(${${SRCS}} ${${HDRS}} PROPERTIES GENERATED TRUE)
1646 - set_source_files_properties(${${SRCS}} ${${HDRS}} PROPERTIES COMPILE_OPTIONS -Wno-deprecated-declarations)
1647 -
1648 - set(${SRCS} ${${SRCS}} PARENT_SCOPE)
1649 - set(${HDRS} ${${HDRS}} PARENT_SCOPE)
1650 -endfunction()
1651 -
1610 #
1611 # mqtt library
1612 #
@@ -1680,11 +1638,11 @@ if(ENABLE_ACLK)
1638 #
1639 # proto definitions
1640 #
1683 - protoc_generate_cpp("${CMAKE_SOURCE_DIR}/src/aclk/aclk-schemas"
1684 - "${CMAKE_SOURCE_DIR}/src/aclk/aclk-schemas"
1685 - ACLK_PROTO_BUILT_SRCS
1686 - ACLK_PROTO_BUILT_HDRS
1687 - ${ACLK_PROTO_DEFS})
1641 + netdata_protoc_generate_cpp("${CMAKE_SOURCE_DIR}/src/aclk/aclk-schemas"
1642 + "${CMAKE_SOURCE_DIR}/src/aclk/aclk-schemas"
1643 + ACLK_PROTO_BUILT_SRCS
1644 + ACLK_PROTO_BUILT_HDRS
1645 + ${ACLK_PROTO_DEFS})
1646
1647 list(APPEND ACLK_FILES ${ACLK_PROTO_BUILT_SRCS}
1648 ${ACLK_PROTO_BUILT_HDRS})
@@ -2030,11 +1988,11 @@ if(ENABLE_EXPORTER_PROMETHEUS_REMOTE_WRITE)
1988 endif()
1989 endif()
1990
2033 - protoc_generate_cpp("${CMAKE_SOURCE_DIR}/src/exporting/prometheus/remote_write"
2034 - "${CMAKE_SOURCE_DIR}/src/exporting/prometheus/remote_write"
2035 - PROMETHEUS_REMOTE_WRITE_BUILT_SRCS
2036 - PROMETHEUS_REMOTE_WRITE_BUILT_HDRS
2037 - "src/exporting/prometheus/remote_write/remote_write.proto")
1991 + netdata_protoc_generate_cpp("${CMAKE_SOURCE_DIR}/src/exporting/prometheus/remote_write"
1992 + "${CMAKE_SOURCE_DIR}/src/exporting/prometheus/remote_write"
1993 + PROMETHEUS_REMOTE_WRITE_BUILT_SRCS
1994 + PROMETHEUS_REMOTE_WRITE_BUILT_HDRS
1995 + "src/exporting/prometheus/remote_write/remote_write.proto")
1996
1997 list(APPEND PROMETHEUS_REMOTE_WRITE_EXPORTING_FILES
1998 ${PROMETHEUS_REMOTE_WRITE_BUILT_SRCS}
@@ -2056,14 +2014,12 @@ add_executable(netdata
2014 )
2015
2016 target_compile_definitions(netdata PRIVATE
2059 - "$<$<BOOL:${ENABLE_PROTOBUF}>:${PROTOBUF_CFLAGS_OTHER}>"
2017 "$<$<BOOL:${ENABLE_ML}>:DLIB_NO_GUI_SUPPORT>"
2018 "$<$<BOOL:${ENABLE_EXPORTER_MONGODB}>:${MONGOC_CFLAGS_OTHER}>"
2019 "$<$<BOOL:${ENABLE_EXPORTER_PROMETHEUS_REMOTE_WRITE}>:${SNAPPY_CFLAGS_OTHER}>"
2020 )
2021
2022 target_include_directories(netdata PRIVATE
2066 - "$<$<BOOL:${ENABLE_PROTOBUF}>:${PROTOBUF_INCLUDE_DIRS}>"
2023 "$<$<BOOL:${ENABLE_ACLK}>:${CMAKE_SOURCE_DIR}/src/aclk/aclk-schemas>"
2024 "$<$<BOOL:${ENABLE_EXPORTER_MONGODB}>:${MONGOC_INCLUDE_DIRS}>"
2025 "$<$<BOOL:${ENABLE_EXPORTER_PROMETHEUS_REMOTE_WRITE}>:${SNAPPY_INCLUDE_DIRS}>"
@@ -2074,7 +2030,6 @@ target_link_libraries(netdata PRIVATE
2030 libnetdata
2031 "$<$<BOOL:${LINUX}>:rt>"
2032 "$<$<BOOL:${ENABLE_MQTTWEBSOCKETS}>:mqttwebsockets>"
2077 - "$<$<BOOL:${ENABLE_PROTOBUF}>:${PROTOBUF_LIBRARIES}>"
2033 "$<$<BOOL:${ENABLE_EXPORTER_MONGODB}>:${MONGOC_LIBRARIES}>"
2034 "$<$<BOOL:${ENABLE_EXPORTER_PROMETHEUS_REMOTE_WRITE}>:${SNAPPY_LIBRARIES}>"
2035 "$<$<BOOL:${MACOS}>:${IOKIT};${FOUNDATION}>"
@@ -2083,6 +2038,10 @@ target_link_libraries(netdata PRIVATE
2038 "$<$<BOOL:${ENABLE_H2O}>:h2o>"
2039 )
2040
2041 +if(NEED_PROTOBUF)
2042 + netdata_add_protobuf(netdata)
2043 +endif()
2044 +
2045 #
2046 # build systemd-cat-native
2047 #
netdata-installer.sh
-85
@@ -556,91 +556,6 @@ fi
556
557 trap build_error EXIT
558
559 -# -----------------------------------------------------------------------------
560 -build_protobuf() {
561 - env_cmd=''
562 -
563 - if [ -z "${DONT_SCRUB_CFLAGS_EVEN_THOUGH_IT_MAY_BREAK_THINGS}" ]; then
564 - env_cmd="env CFLAGS='-fPIC -pipe' CXXFLAGS='-fPIC -pipe' LDFLAGS="
565 - fi
566 -
567 - cd "${1}" > /dev/null || return 1
568 - if ! run eval "${env_cmd} ./configure --disable-shared --without-zlib --disable-dependency-tracking --with-pic"; then
569 - cd - > /dev/null || return 1
570 - return 1
571 - fi
572 -
573 - if ! run eval "${env_cmd} ${make} ${MAKEOPTS}"; then
574 - cd - > /dev/null || return 1
575 - return 1
576 - fi
577 -
578 - cd - > /dev/null || return 1
579 -}
580 -
581 -copy_protobuf() {
582 - target_dir="${PWD}/externaldeps/protobuf"
583 -
584 - run mkdir -p "${target_dir}" || return 1
585 - run cp -a "${1}/src" "${target_dir}" || return 1
586 -}
587 -
588 -bundle_protobuf() {
589 - if [ -n "${NETDATA_DISABLE_CLOUD}" ] && [ -n "${EXPORTER_PROMETHEUS}" ] && [ "${EXPORTER_PROMETHEUS}" -eq 0 ]; then
590 - echo "Skipping protobuf"
591 - return 0
592 - fi
593 -
594 - if [ -n "${USE_SYSTEM_PROTOBUF}" ]; then
595 - echo "Skipping protobuf"
596 - warning "You have requested use of a system copy of protobuf. This should work, but it is not recommended as it's very likely to break if you upgrade the currently installed version of protobuf."
597 - return 0
598 - fi
599 -
600 - if [ -z "${make}" ]; then
601 - warning "No usable copy of Make found, which is required for bundling protobuf. Attempting to use a system copy of protobuf instead."
602 - USE_SYSTEM_PROTOBUF=1
603 - return 0
604 - fi
605 -
606 - [ -n "${GITHUB_ACTIONS}" ] && echo "::group::Bundling protobuf."
607 -
608 - PROTOBUF_PACKAGE_VERSION="$(cat packaging/protobuf.version)"
609 -
610 - if [ -f "${PWD}/externaldeps/protobuf/.version" ] && [ "${PROTOBUF_PACKAGE_VERSION}" = "$(cat "${PWD}/externaldeps/protobuf/.version")" ]
611 - then
612 - echo >&2 "Found compiled protobuf, same version, not compiling it again. Remove file '${PWD}/externaldeps/protobuf/.version' to recompile."
613 - USE_SYSTEM_PROTOBUF=0
614 - return 0
615 - fi
616 -
617 - tmp="$(mktemp -d -t netdata-protobuf-XXXXXX)"
618 - PROTOBUF_PACKAGE_BASENAME="protobuf-cpp-${PROTOBUF_PACKAGE_VERSION}.tar.gz"
619 -
620 - if fetch_and_verify "protobuf" \
621 - "https://github.com/protocolbuffers/protobuf/releases/download/v${PROTOBUF_PACKAGE_VERSION}/${PROTOBUF_PACKAGE_BASENAME}" \
622 - "${PROTOBUF_PACKAGE_BASENAME}" \
623 - "${tmp}" \
624 - "${NETDATA_LOCAL_TARBALL_VERRIDE_PROTOBUF}"; then
625 - if run tar --no-same-owner -xf "${tmp}/${PROTOBUF_PACKAGE_BASENAME}" -C "${tmp}" &&
626 - build_protobuf "${tmp}/protobuf-${PROTOBUF_PACKAGE_VERSION}" &&
627 - copy_protobuf "${tmp}/protobuf-${PROTOBUF_PACKAGE_VERSION}" &&
628 - echo "${PROTOBUF_PACKAGE_VERSION}" >"${PWD}/externaldeps/protobuf/.version" &&
629 - rm -rf "${tmp}"; then
630 - run_ok "protobuf built and prepared."
631 - USE_SYSTEM_PROTOBUF=0
632 - else
633 - run_failed "Failed to build protobuf. Netdata Cloud support will not be available in this build."
634 - fi
635 - else
636 - run_failed "Unable to fetch sources for protobuf. Netdata Cloud support will not be available in this build."
637 - fi
638 -
639 - [ -n "${GITHUB_ACTIONS}" ] && echo "::endgroup::"
640 -}
641 -
642 -bundle_protobuf
643 -
559 # -----------------------------------------------------------------------------
560 build_jsonc() {
561 env_cmd=''
netdata.spec.in
-6
@@ -315,12 +315,6 @@ happened, on your systems and applications.
315
316 %prep
317 %setup -q -n "%{name}-%{version}"
318 -# Only bundle protobuf on CentOS 7 or earlier
319 -%if 0%{?centos_ver:1}
320 -%if %{centos_ver} < 8
321 -export CFLAGS="${CFLAGS} -fPIC" && ${RPM_BUILD_DIR}/%{name}-%{version}/packaging/bundle-protobuf.sh ${RPM_BUILD_DIR}/%{name}-%{version}
322 -%endif
323 -%endif
318 %if 0%{?_have_ebpf}
319 %if 0%{?centos_ver:1}
320 %if %{centos_ver} < 8
packaging/bundle-protobuf.sh deleted
-16
@@ -1,16 +0,0 @@
1 -#!/bin/sh
2 -
3 -PROTOBUF_TARBALL="protobuf-cpp-$(cat "${1}/packaging/protobuf.version").tar.gz"
4 -PROTOBUF_BUILD_PATH="${1}/externaldeps/protobuf/protobuf-$(cat "${1}/packaging/protobuf.version")"
5 -
6 -mkdir -p "${1}/externaldeps/protobuf" || exit 1
7 -curl -sSL --connect-timeout 10 --retry 3 "https://github.com/protocolbuffers/protobuf/releases/download/v$(cat "${1}/packaging/protobuf.version")/${PROTOBUF_TARBALL}" > "${PROTOBUF_TARBALL}" || exit 1
8 -sha256sum -c "${1}/packaging/protobuf.checksums" || exit 1
9 -tar -xz --no-same-owner -f "${PROTOBUF_TARBALL}" -C "${1}/externaldeps/protobuf" || exit 1
10 -OLDPWD="${PWD}"
11 -cd "${PROTOBUF_BUILD_PATH}" || exit 1
12 -./configure --disable-shared --without-zlib --disable-dependency-tracking --with-pic || exit 1
13 -make -j "$(nproc)" || exit 1
14 -cd "${OLDPWD}" || exit 1
15 -
16 -cp -a "${PROTOBUF_BUILD_PATH}/src" "${1}/externaldeps/protobuf" || exit 1
packaging/cmake/Modules/NetdataFetchContentExtra.cmake new
+27
@@ -0,0 +1,27 @@
1 +# Extra tools for working with FetchContent on older CMake
2 +#
3 +# Copyright (c) 2024 Netdata Inc.
4 +# SPDX-License-Identifier: GPL-3.0-or-later
5 +
6 +# FetchContent_MakeAvailable_NoInstall
7 +#
8 +# Add a sub-project with FetchContent, but with the EXCLUDE_FROM_ALL
9 +# argument for the add_subdirectory part.
10 +#
11 +# CMake 3.28 and newer provide a way to do this with an extra argument
12 +# on FetchContent_Declare, but older versions need you to implement
13 +# the logic yourself. Once we no longer support CMake versions older
14 +# than 3.28, we can get rid of this macro.
15 +#
16 +# Unlike FetchContent_MakeAvailble, this only accepts a single project
17 +# to make available.
18 +macro(FetchContent_MakeAvailable_NoInstall name)
19 + include(FetchContent)
20 +
21 + FetchContent_GetProperties(${name})
22 +
23 + if(NOT ${name}_POPULATED)
24 + FetchContent_Populate(${name})
25 + add_subdirectory(${${name}_SOURCE_DIR} ${${name}_BINARY_DIR} EXCLUDE_FROM_ALL)
26 + endif()
27 +endmacro()
packaging/cmake/Modules/NetdataProtobuf.cmake new
+225
@@ -0,0 +1,225 @@
1 +# Macros and functions for handling of Protobuf
2 +#
3 +# Copyright (c) 2024 Netdata Inc.
4 +# SPDX-License-Identifier: GPL-3.0-or-later
5 +
6 +macro(netdata_protobuf_21_tags)
7 + set(PROTOBUF_TAG f0dc78d7e6e331b8c6bb2d5283e06aa26883ca7c) # v21.12
8 + set(NEED_ABSL False)
9 +endmacro()
10 +
11 +macro(netdata_protobuf_25_tags)
12 + set(PROTOBUF_TAG 4a2aef570deb2bfb8927426558701e8bfc26f2a4) # v25.3
13 + set(NEED_ABSL True)
14 + set(ABSL_TAG 2f9e432cce407ce0ae50676696666f33a77d42ac) # 20240116.1
15 +endmacro()
16 +
17 +# Determine what version of protobuf and abseil to bundle.
18 +#
19 +# This is unfortunately very complicated because we support systems
20 +# older than what Google officially supports for C++.
21 +macro(netdata_set_bundled_protobuf_tags)
22 + netdata_protobuf_21_tags()
23 +
24 + if(NOT USE_CXX_11)
25 + if(CMAKE_CXX_COMPILER_ID STREQUAL GNU)
26 + if(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 7.3.1)
27 + netdata_protobuf_25_tags()
28 + endif()
29 + elseif(CMAKE_CXX_COMPILER_ID STREQUAL Clang)
30 + if(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 7.0.0)
31 + netdata_protobuf_25_tags()
32 + endif()
33 + elseif(CMAKE_CXX_COMPILER_ID STREQUAL AppleClang)
34 + if(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 12)
35 + netdata_protobuf_25_tags()
36 + endif()
37 + endif()
38 + endif()
39 +endmacro()
40 +
41 +# Prepare a vendored copy of Protobuf for use with Netdata.
42 +function(netdata_bundle_protobuf)
43 + include(FetchContent)
44 + include(NetdataFetchContentExtra)
45 +
46 + netdata_set_bundled_protobuf_tags()
47 +
48 + set(FETCHCONTENT_TRY_FIND_PACKAGE_MODE NEVER)
49 +
50 + string(REPLACE "-fsanitize=address" "" CMAKE_C_FLAGS ${CMAKE_C_FLAGS})
51 + string(REPLACE "-fsanitize=address" "" CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS})
52 +
53 + # ignore debhelper
54 + set(FETCHCONTENT_FULLY_DISCONNECTED Off)
55 +
56 + if(NEED_ABSL)
57 + set(ABSL_PROPAGATE_CXX_STD On)
58 + set(ABSL_ENABLE_INSTALL Off)
59 +
60 + message(STATUS "Preparing bundled Abseil (required by bundled Protobuf)")
61 + FetchContent_Declare(absl
62 + GIT_REPOSITORY https://github.com/abseil/abseil-cpp
63 + GIT_TAG ${ABSL_TAG}
64 + )
65 + FetchContent_MakeAvailable_NoInstall(absl)
66 + message(STATUS "Finished preparing bundled Abseil")
67 + endif()
68 +
69 + set(protobuf_INSTALL Off)
70 + set(protobuf_BUILD_LIBPROTOC Off)
71 + set(protobuf_BUILD_TESTS Off)
72 + set(protobuf_BUILD_SHARED_LIBS Off)
73 +
74 + message(STATUS "Preparing bundled Protobuf")
75 + FetchContent_Declare(protobuf
76 + GIT_REPOSITORY https://github.com/protocolbuffers/protobuf.git
77 + GIT_TAG ${PROTOBUF_TAG}
78 + )
79 + FetchContent_MakeAvailable_NoInstall(protobuf)
80 + message(STATUS "Finished preparing bundled Protobuf.")
81 +
82 + set(BUNDLED_PROTOBUF True PARENT_SCOPE)
83 +endfunction()
84 +
85 +# Handle detection of Protobuf
86 +macro(netdata_detect_protobuf)
87 + if(NOT ENABLE_BUNDLED_PROTOBUF)
88 + if (NOT BUILD_SHARED_LIBS)
89 + set(Protobuf_USE_STATIC_LIBS On)
90 + endif()
91 +
92 + # The FindProtobuf CMake module shipped by upstream CMake is
93 + # broken for Protobuf version 22.0 and newer because it does
94 + # not correctly pull in the new Abseil dependencies. Protobuf
95 + # itself sometimes ships a CMake Package Configuration module
96 + # that _does_ work correctly, so use that in preference to the
97 + # Find module shipped with CMake.
98 + #
99 + # The code below works by first attempting to use find_package
100 + # in config mode, and then checking for the existence of the
101 + # target we actually use that gets defined by the protobuf
102 + # CMake Package Configuration Module to determine if that
103 + # worked. A bit of extra logic is required in the case of the
104 + # config mode working, because some systems ship compatibility
105 + # logic for the old FindProtobuf module while others do not.
106 + #
107 + # Upstream bug reference: https://gitlab.kitware.com/cmake/cmake/-/issues/24321
108 + find_package(Protobuf CONFIG)
109 +
110 + if(NOT TARGET protobuf::libprotobuf)
111 + message(STATUS "Could not find Protobuf using Config mode, falling back to Module mode")
112 + find_package(Protobuf REQUIRED)
113 + endif()
114 + endif()
115 +
116 + if(TARGET protobuf::libprotobuf)
117 + if(NOT Protobuf_PROTOC_EXECUTABLE AND TARGET protobuf::protoc)
118 + get_target_property(Protobuf_PROTOC_EXECUTABLE protobuf::protoc
119 + IMPORTED_LOCATION_RELEASE)
120 + if(NOT EXISTS "${Protobuf_PROTOC_EXECUTABLE}")
121 + get_target_property(Protobuf_PROTOC_EXECUTABLE protobuf::protoc
122 + IMPORTED_LOCATION_RELWITHDEBINFO)
123 + endif()
124 + if(NOT EXISTS "${Protobuf_PROTOC_EXECUTABLE}")
125 + get_target_property(Protobuf_PROTOC_EXECUTABLE protobuf::protoc
126 + IMPORTED_LOCATION_MINSIZEREL)
127 + endif()
128 + if(NOT EXISTS "${Protobuf_PROTOC_EXECUTABLE}")
129 + get_target_property(Protobuf_PROTOC_EXECUTABLE protobuf::protoc
130 + IMPORTED_LOCATION_DEBUG)
131 + endif()
132 + if(NOT EXISTS "${Protobuf_PROTOC_EXECUTABLE}")
133 + get_target_property(Protobuf_PROTOC_EXECUTABLE protobuf::protoc
134 + IMPORTED_LOCATION_NOCONFIG)
135 + endif()
136 + if(NOT Protobuf_PROTOC_EXECUTABLE)
137 + set(Protobuf_PROTOC_EXECUTABLE protobuf::protoc)
138 + endif()
139 + endif()
140 +
141 + # It is technically possible that this may still not
142 + # be set by this point, so we need to check it and
143 + # fail noisily if it isn't because the build won't
144 + # work without it.
145 + if(NOT Protobuf_PROTOC_EXECUTABLE)
146 + message(FATAL_ERROR "Could not determine the location of the protobuf compiler for the detected version of protobuf.")
147 + endif()
148 +
149 + set(NETDATA_PROTOBUF_PROTOC_EXECUTABLE ${Protobuf_PROTOC_EXECUTABLE})
150 + set(NETDATA_PROTOBUF_LIBS protobuf::libprotobuf)
151 + get_target_property(NETDATA_PROTOBUF_CFLAGS_OTHER
152 + protobuf::libprotobuf
153 + INTERFACE_COMPILE_DEFINITIONS)
154 + get_target_property(NETDATA_PROTOBUF_INCLUDE_DIRS
155 + protobuf::libprotobuf
156 + INTERFACE_INCLUDE_DIRECTORIES)
157 +
158 + if(NETDATA_PROTOBUF_CFLAGS_OTHER STREQUAL NETDATA_PROTOBUF_CFLAGS_OTHER-NOTFOUND)
159 + set(NETDATA_PROTOBUF_CFLAGS_OTHER "")
160 + endif()
161 +
162 + if(NETDATA_PROTOBUF_INCLUDE_DIRS STREQUAL NETDATA_PROTOBUF_INCLUDE_DIRS-NOTFOUND)
163 + set(NETDATA_PROTOBUF_INCLUDE_DIRS "")
164 + endif()
165 + else()
166 + set(NETDATA_PROTOBUF_PROTOC_EXECUTABLE ${PROTOBUF_PROTOC_EXECUTABLE})
167 + set(NETDATA_PROTOBUF_CFLAGS_OTHER ${PROTOBUF_CFLAGS_OTHER})
168 + set(NETDATA_PROTOBUF_INCLUDE_DIRS ${PROTOBUF_INCLUDE_DIRS})
169 + set(NETDATA_PROTOBUF_LIBS ${PROTOBUF_LIBRARIES})
170 + endif()
171 +
172 + set(ENABLE_PROTOBUF True)
173 + set(HAVE_PROTOBUF True)
174 +endmacro()
175 +
176 +# Helper function to compile protocol definitions into C++ code.
177 +function(netdata_protoc_generate_cpp INC_DIR OUT_DIR SRCS HDRS)
178 + if(NOT ARGN)
179 + message(SEND_ERROR "Error: protoc_generate_cpp() called without any proto files")
180 + return()
181 + endif()
182 +
183 + set(${INC_DIR})
184 + set(${OUT_DIR})
185 + set(${SRCS})
186 + set(${HDRS})
187 +
188 + foreach(FIL ${ARGN})
189 + get_filename_component(ABS_FIL ${FIL} ABSOLUTE)
190 + get_filename_component(DIR ${ABS_FIL} DIRECTORY)
191 + get_filename_component(FIL_WE ${FIL} NAME_WE)
192 +
193 + set(GENERATED_PB_CC "${DIR}/${FIL_WE}.pb.cc")
194 + list(APPEND ${SRCS} ${GENERATED_PB_CC})
195 +
196 + set(GENERATED_PB_H "${DIR}/${FIL_WE}.pb.h")
197 + list(APPEND ${HDRS} ${GENERATED_PB_H})
198 +
199 + list(APPEND _PROTOC_INCLUDE_DIRS ${INC_DIR})
200 +
201 + if(ENABLE_BUNDLED_PROTOBUF)
202 + list(APPEND _PROTOC_INCLUDE_DIRS ${CMAKE_BINARY_DIR}/_deps/protobuf-src/src/)
203 + endif()
204 +
205 + add_custom_command(OUTPUT ${GENERATED_PB_CC} ${GENERATED_PB_H}
206 + COMMAND ${NETDATA_PROTOBUF_PROTOC_EXECUTABLE}
207 + ARGS "-I$<JOIN:${_PROTOC_INCLUDE_DIRS},;-I>" --cpp_out=${OUT_DIR} ${ABS_FIL}
208 + DEPENDS ${ABS_FIL} ${NETDATA_PROTOBUF_PROTOC_EXECUTABLE}
209 + COMMENT "Running C++ protocol buffer compiler on ${FIL}"
210 + COMMAND_EXPAND_LISTS)
211 + endforeach()
212 +
213 + set_source_files_properties(${${SRCS}} ${${HDRS}} PROPERTIES GENERATED TRUE)
214 + set_source_files_properties(${${SRCS}} ${${HDRS}} PROPERTIES COMPILE_OPTIONS -Wno-deprecated-declarations)
215 +
216 + set(${SRCS} ${${SRCS}} PARENT_SCOPE)
217 + set(${HDRS} ${${HDRS}} PARENT_SCOPE)
218 +endfunction()
219 +
220 +# Add protobuf to a specified target.
221 +function(netdata_add_protobuf _target)
222 + target_compile_definitions(${_target} PRIVATE ${NETDATA_PROTOBUF_CFLAGS_OTHER})
223 + target_include_directories(${_target} PRIVATE ${NETDATA_PROTOBUF_INCLUDE_DIRS})
224 + target_link_libraries(${_target} PRIVATE ${NETDATA_PROTOBUF_LIBS})
225 +endfunction()
packaging/installer/functions.sh
+1 -1
@@ -263,7 +263,7 @@ prepare_cmake_options() {
263 enable_feature PLUGIN_GO 0
264 fi
265
266 - if [ "${USE_SYSTEM_PROTOBUF:-1}" -eq 1 ]; then
266 + if [ "${USE_SYSTEM_PROTOBUF:-0}" -eq 1 ]; then
267 enable_feature BUNDLED_PROTOBUF 0
268 else
269 enable_feature BUNDLED_PROTOBUF 1
packaging/protobuf.checksums deleted
-1
@@ -1 +0,0 @@
1 -89ac31a93832e204db6d73b1e80f39f142d5747b290f17340adce5be5b122f94 protobuf-cpp-3.19.4.tar.gz
packaging/protobuf.version deleted
-1
@@ -1 +0,0 @@
1 -3.19.4
tests/run-unit-tests.sh
-2
@@ -26,8 +26,6 @@ install_netdata() {
26 --install-prefix "$HOME" \
27 --dont-wait \
28 --dont-start-it \
29 - --enable-plugin-nfacct \
30 - --enable-plugin-freeipmi \
29 --disable-lto \
30 --enable-logsmanagement-tests
31 }