summaryrefslogtreecommitdiffstats
path: root/packaging/cmake/Modules/NetdataProtobuf.cmake
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-07-24 09:53:08 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-07-24 09:53:08 +0000
commit6a1900e8bd84c282a500ae4032645ae55c614b7b (patch)
treed4d31289c39fc00da064a825df13a0b98ce95b10 /packaging/cmake/Modules/NetdataProtobuf.cmake
parentAdding upstream version 1.45.3+dfsg. (diff)
downloadnetdata-51e89ed3b2eb6a0b40c93366a00daa66027994dc.tar.xz
netdata-51e89ed3b2eb6a0b40c93366a00daa66027994dc.zip
Adding upstream version 1.46.3.upstream/1.46.3
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'packaging/cmake/Modules/NetdataProtobuf.cmake')
-rw-r--r--packaging/cmake/Modules/NetdataProtobuf.cmake194
1 files changed, 74 insertions, 120 deletions
diff --git a/packaging/cmake/Modules/NetdataProtobuf.cmake b/packaging/cmake/Modules/NetdataProtobuf.cmake
index d4ae3aec6..c142d6566 100644
--- a/packaging/cmake/Modules/NetdataProtobuf.cmake
+++ b/packaging/cmake/Modules/NetdataProtobuf.cmake
@@ -3,52 +3,24 @@
# Copyright (c) 2024 Netdata Inc.
# SPDX-License-Identifier: GPL-3.0-or-later
-macro(netdata_protobuf_21_tags)
- set(PROTOBUF_TAG f0dc78d7e6e331b8c6bb2d5283e06aa26883ca7c) # v21.12
- set(NEED_ABSL False)
-endmacro()
-
-macro(netdata_protobuf_25_tags)
- set(PROTOBUF_TAG 4a2aef570deb2bfb8927426558701e8bfc26f2a4) # v25.3
- set(NEED_ABSL True)
- set(ABSL_TAG 2f9e432cce407ce0ae50676696666f33a77d42ac) # 20240116.1
-endmacro()
-
-# Determine what version of protobuf and abseil to bundle.
-#
-# This is unfortunately very complicated because we support systems
-# older than what Google officially supports for C++.
-macro(netdata_set_bundled_protobuf_tags)
- netdata_protobuf_21_tags()
-
- if(NOT USE_CXX_11)
- if(CMAKE_CXX_COMPILER_ID STREQUAL GNU)
- if(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 7.3.1)
- netdata_protobuf_25_tags()
- endif()
- elseif(CMAKE_CXX_COMPILER_ID STREQUAL Clang)
- if(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 7.0.0)
- netdata_protobuf_25_tags()
- endif()
- elseif(CMAKE_CXX_COMPILER_ID STREQUAL AppleClang)
- if(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 12)
- netdata_protobuf_25_tags()
- endif()
- endif()
- endif()
-endmacro()
-
# Prepare a vendored copy of Protobuf for use with Netdata.
function(netdata_bundle_protobuf)
include(FetchContent)
include(NetdataFetchContentExtra)
- netdata_set_bundled_protobuf_tags()
+ 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})
+ 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)
@@ -56,11 +28,13 @@ function(netdata_bundle_protobuf)
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")
@@ -75,102 +49,77 @@ function(netdata_bundle_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(BUNDLED_PROTOBUF True PARENT_SCOPE)
+ set(ENABLE_BUNDLED_PROTOBUF True PARENT_SCOPE)
endfunction()
# Handle detection of Protobuf
macro(netdata_detect_protobuf)
- 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)
+ if(OS_WINDOWS)
+ set(PROTOBUF_PROTOC_EXECUTABLE "$ENV{PROTOBUF_PROTOC_EXECUTABLE}")
+ if(NOT PROTOBUF_PROTOC_EXECUTABLE)
+ set(PROTOBUF_PROTOC_EXECUTABLE "/bin/protoc")
endif()
- endif()
+ set(PROTOBUF_CFLAGS_OTHER "")
+ set(PROTOBUF_INCLUDE_DIRS "")
+ set(PROTOBUF_LIBRARIES "-lprotobuf")
- if(TARGET protobuf::libprotobuf)
- if(NOT Protobuf_PROTOC_EXECUTABLE AND TARGET protobuf::protoc)
- get_target_property(Protobuf_PROTOC_EXECUTABLE protobuf::protoc
- IMPORTED_LOCATION_RELEASE)
- if(NOT EXISTS "${Protobuf_PROTOC_EXECUTABLE}")
- get_target_property(Protobuf_PROTOC_EXECUTABLE protobuf::protoc
- IMPORTED_LOCATION_RELWITHDEBINFO)
- endif()
- if(NOT EXISTS "${Protobuf_PROTOC_EXECUTABLE}")
- get_target_property(Protobuf_PROTOC_EXECUTABLE protobuf::protoc
- IMPORTED_LOCATION_MINSIZEREL)
- endif()
- if(NOT EXISTS "${Protobuf_PROTOC_EXECUTABLE}")
- get_target_property(Protobuf_PROTOC_EXECUTABLE protobuf::protoc
- IMPORTED_LOCATION_DEBUG)
+ 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()
- if(NOT EXISTS "${Protobuf_PROTOC_EXECUTABLE}")
- get_target_property(Protobuf_PROTOC_EXECUTABLE protobuf::protoc
- IMPORTED_LOCATION_NOCONFIG)
+
+ # 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()
- if(NOT Protobuf_PROTOC_EXECUTABLE)
+ endif()
+
+ if(TARGET protobuf::libprotobuf)
+ if(NOT Protobuf_PROTOC_EXECUTABLE AND TARGET protobuf::protoc)
set(Protobuf_PROTOC_EXECUTABLE protobuf::protoc)
endif()
- 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()
+ # 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(NETDATA_PROTOBUF_PROTOC_EXECUTABLE ${Protobuf_PROTOC_EXECUTABLE})
- set(NETDATA_PROTOBUF_LIBS protobuf::libprotobuf)
- get_target_property(NETDATA_PROTOBUF_CFLAGS_OTHER
- protobuf::libprotobuf
- INTERFACE_COMPILE_DEFINITIONS)
- get_target_property(NETDATA_PROTOBUF_INCLUDE_DIRS
- protobuf::libprotobuf
- INTERFACE_INCLUDE_DIRECTORIES)
-
- if(NETDATA_PROTOBUF_CFLAGS_OTHER STREQUAL NETDATA_PROTOBUF_CFLAGS_OTHER-NOTFOUND)
- set(NETDATA_PROTOBUF_CFLAGS_OTHER "")
+ set(PROTOBUF_PROTOC_EXECUTABLE ${Protobuf_PROTOC_EXECUTABLE})
+ set(PROTOBUF_LIBRARIES protobuf::libprotobuf)
endif()
- if(NETDATA_PROTOBUF_INCLUDE_DIRS STREQUAL NETDATA_PROTOBUF_INCLUDE_DIRS-NOTFOUND)
- set(NETDATA_PROTOBUF_INCLUDE_DIRS "")
- endif()
- else()
- set(NETDATA_PROTOBUF_PROTOC_EXECUTABLE ${PROTOBUF_PROTOC_EXECUTABLE})
- set(NETDATA_PROTOBUF_CFLAGS_OTHER ${PROTOBUF_CFLAGS_OTHER})
- set(NETDATA_PROTOBUF_INCLUDE_DIRS ${PROTOBUF_INCLUDE_DIRS})
- set(NETDATA_PROTOBUF_LIBS ${PROTOBUF_LIBRARIES})
+ set(ENABLE_PROTOBUF True)
+ set(HAVE_PROTOBUF True)
endif()
-
- set(ENABLE_PROTOBUF True)
- set(HAVE_PROTOBUF True)
endmacro()
# Helper function to compile protocol definitions into C++ code.
@@ -203,9 +152,9 @@ function(netdata_protoc_generate_cpp INC_DIR OUT_DIR SRCS HDRS)
endif()
add_custom_command(OUTPUT ${GENERATED_PB_CC} ${GENERATED_PB_H}
- COMMAND ${NETDATA_PROTOBUF_PROTOC_EXECUTABLE}
+ COMMAND ${PROTOBUF_PROTOC_EXECUTABLE}
ARGS "-I$<JOIN:${_PROTOC_INCLUDE_DIRS},;-I>" --cpp_out=${OUT_DIR} ${ABS_FIL}
- DEPENDS ${ABS_FIL} ${NETDATA_PROTOBUF_PROTOC_EXECUTABLE}
+ DEPENDS ${ABS_FIL} ${PROTOBUF_PROTOC_EXECUTABLE}
COMMENT "Running C++ protocol buffer compiler on ${FIL}"
COMMAND_EXPAND_LISTS)
endforeach()
@@ -219,7 +168,12 @@ endfunction()
# Add protobuf to a specified target.
function(netdata_add_protobuf _target)
- target_compile_definitions(${_target} PRIVATE ${NETDATA_PROTOBUF_CFLAGS_OTHER})
- target_include_directories(${_target} PRIVATE ${NETDATA_PROTOBUF_INCLUDE_DIRS})
- target_link_libraries(${_target} PRIVATE ${NETDATA_PROTOBUF_LIBS})
+ 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()