summaryrefslogtreecommitdiffstats
path: root/CMakeLists.txt
diff options
context:
space:
mode:
authorAustin S. Hemmelgarn <austin@netdata.cloud>2024-03-20 07:13:44 -0400
committerGitHub <noreply@github.com>2024-03-20 07:13:44 -0400
commit804fd4ce548ba147f9b513517c3846cb6829f03d (patch)
tree4c66d0e1f9625f8ffea17a7a9527740f37ce7b4d /CMakeLists.txt
parenteb1b5478c200a402ebb6b395ab523045ac087187 (diff)
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.
Diffstat (limited to 'CMakeLists.txt')
-rw-r--r--CMakeLists.txt101
1 files changed, 30 insertions, 71 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index c90e10a966..d72320bc4c 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -128,6 +128,12 @@ option(ENABLE_LOGS_MANAGEMENT_TESTS "enable logs management tests" True)
option(ENABLE_SENTRY "enable sentry" False)
option(ENABLE_WEBRTC "enable webrtc" False)
+if(ENABLE_ACLK OR ENABLE_EXPORTER_PROMETHEUS_REMOTE_WRITE)
+ set(NEED_PROTOBUF True)
+else()
+ set(NEED_PROTOBUF False)
+endif()
+
if(ENABLE_PLUGIN_GO)
include(NetdataGoTools)
@@ -173,6 +179,14 @@ if(ENABLE_WEBRTC)
FetchContent_MakeAvailable(libdatachannel)
endif()
+if(NEED_PROTOBUF)
+ include(NetdataProtobuf)
+
+ if(ENABLE_BUNDLED_PROTOBUF)
+ netdata_bundle_protobuf()
+ endif()
+endif()
+
#
# handling of extra compiler flags
#
@@ -491,24 +505,8 @@ endif()
# figure out if we need protoc/protobuf
#
-if(ENABLE_ACLK OR ENABLE_EXPORTER_PROMETHEUS_REMOTE_WRITE)
- if(ENABLE_BUNDLED_PROTOBUF)
- set(PROTOBUF_PROTOC_EXECUTABLE "${CMAKE_SOURCE_DIR}/externaldeps/protobuf/src/protoc")
- set(PROTOBUF_INCLUDE_DIRS "${CMAKE_SOURCE_DIR}/externaldeps/protobuf/src")
- set(PROTOBUF_LIBRARIES "${CMAKE_SOURCE_DIR}/externaldeps/protobuf/src/.libs/libprotobuf.a")
- else()
- if (NOT BUILD_SHARED_LIBS)
- set(Protobuf_USE_STATIC_LIBS On)
- endif()
-
- find_package(Protobuf REQUIRED)
- endif()
-
- set(ENABLE_PROTOBUF True)
- set(HAVE_PROTOBUF True)
- if (ENABLE_BUNDLED_PROTOBUF)
- set(BUNDLED_PROTOBUF True)
- endif()
+if(NEED_PROTOBUF)
+ netdata_detect_protobuf()
endif()
#
@@ -1610,46 +1608,6 @@ if(MNL_FOUND)
endif()
#
-# helper function to build protos
-#
-
-function(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})
-
- add_custom_command(OUTPUT ${GENERATED_PB_CC} ${GENERATED_PB_H}
- COMMAND ${PROTOBUF_PROTOC_EXECUTABLE} ARGS -I=${INC_DIR} --cpp_out=${OUT_DIR} ${ABS_FIL}
- DEPENDS ${ABS_FIL} ${PROTOBUF_PROTOC_EXECUTABLE}
- COMMENT "Running C++ protocol buffer compiler on ${FIL}"
- VERBATIM)
- 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()
-
-#
# mqtt library
#
if (ENABLE_H2O OR ENABLE_ACLK)
@@ -1680,11 +1638,11 @@ if(ENABLE_ACLK)
#
# proto definitions
#
- protoc_generate_cpp("${CMAKE_SOURCE_DIR}/src/aclk/aclk-schemas"
- "${CMAKE_SOURCE_DIR}/src/aclk/aclk-schemas"
- ACLK_PROTO_BUILT_SRCS
- ACLK_PROTO_BUILT_HDRS
- ${ACLK_PROTO_DEFS})
+ netdata_protoc_generate_cpp("${CMAKE_SOURCE_DIR}/src/aclk/aclk-schemas"
+ "${CMAKE_SOURCE_DIR}/src/aclk/aclk-schemas"
+ ACLK_PROTO_BUILT_SRCS
+ ACLK_PROTO_BUILT_HDRS
+ ${ACLK_PROTO_DEFS})
list(APPEND ACLK_FILES ${ACLK_PROTO_BUILT_SRCS}
${ACLK_PROTO_BUILT_HDRS})
@@ -2030,11 +1988,11 @@ if(ENABLE_EXPORTER_PROMETHEUS_REMOTE_WRITE)
endif()
endif()
- protoc_generate_cpp("${CMAKE_SOURCE_DIR}/src/exporting/prometheus/remote_write"
- "${CMAKE_SOURCE_DIR}/src/exporting/prometheus/remote_write"
- PROMETHEUS_REMOTE_WRITE_BUILT_SRCS
- PROMETHEUS_REMOTE_WRITE_BUILT_HDRS
- "src/exporting/prometheus/remote_write/remote_write.proto")
+ netdata_protoc_generate_cpp("${CMAKE_SOURCE_DIR}/src/exporting/prometheus/remote_write"
+ "${CMAKE_SOURCE_DIR}/src/exporting/prometheus/remote_write"
+ PROMETHEUS_REMOTE_WRITE_BUILT_SRCS
+ PROMETHEUS_REMOTE_WRITE_BUILT_HDRS
+ "src/exporting/prometheus/remote_write/remote_write.proto")
list(APPEND PROMETHEUS_REMOTE_WRITE_EXPORTING_FILES
${PROMETHEUS_REMOTE_WRITE_BUILT_SRCS}
@@ -2056,14 +2014,12 @@ add_executable(netdata
)
target_compile_definitions(netdata PRIVATE
- "$<$<BOOL:${ENABLE_PROTOBUF}>:${PROTOBUF_CFLAGS_OTHER}>"
"$<$<BOOL:${ENABLE_ML}>:DLIB_NO_GUI_SUPPORT>"
"$<$<BOOL:${ENABLE_EXPORTER_MONGODB}>:${MONGOC_CFLAGS_OTHER}>"
"$<$<BOOL:${ENABLE_EXPORTER_PROMETHEUS_REMOTE_WRITE}>:${SNAPPY_CFLAGS_OTHER}>"
)
target_include_directories(netdata PRIVATE
- "$<$<BOOL:${ENABLE_PROTOBUF}>:${PROTOBUF_INCLUDE_DIRS}>"
"$<$<BOOL:${ENABLE_ACLK}>:${CMAKE_SOURCE_DIR}/src/aclk/aclk-schemas>"
"$<$<BOOL:${ENABLE_EXPORTER_MONGODB}>:${MONGOC_INCLUDE_DIRS}>"
"$<$<BOOL:${ENABLE_EXPORTER_PROMETHEUS_REMOTE_WRITE}>:${SNAPPY_INCLUDE_DIRS}>"
@@ -2074,7 +2030,6 @@ target_link_libraries(netdata PRIVATE
libnetdata
"$<$<BOOL:${LINUX}>:rt>"
"$<$<BOOL:${ENABLE_MQTTWEBSOCKETS}>:mqttwebsockets>"
- "$<$<BOOL:${ENABLE_PROTOBUF}>:${PROTOBUF_LIBRARIES}>"
"$<$<BOOL:${ENABLE_EXPORTER_MONGODB}>:${MONGOC_LIBRARIES}>"
"$<$<BOOL:${ENABLE_EXPORTER_PROMETHEUS_REMOTE_WRITE}>:${SNAPPY_LIBRARIES}>"
"$<$<BOOL:${MACOS}>:${IOKIT};${FOUNDATION}>"
@@ -2083,6 +2038,10 @@ target_link_libraries(netdata PRIVATE
"$<$<BOOL:${ENABLE_H2O}>:h2o>"
)
+if(NEED_PROTOBUF)
+ netdata_add_protobuf(netdata)
+endif()
+
#
# build systemd-cat-native
#