@cryptotaxi247 / netdata-1 / commits / 787cfeed1

Significantly simplify the protobuf handling in CMake. (#17533)

Austin S. Hemmelgarn committed May 1, 2024 at 07:04 UTC 787cfeed1a54949e817b2a1250b640a4f5049a06
1 file changed +16 -83
packaging/cmake/Modules/NetdataProtobuf.cmake
+16 -83
@@ -3,47 +3,19 @@
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 -
6 # Prepare a vendored copy of Protobuf for use with Netdata.
7 function(netdata_bundle_protobuf)
8 include(FetchContent)
9 include(NetdataFetchContentExtra)
10
46 - netdata_set_bundled_protobuf_tags()
11 + set(PROTOBUF_TAG f0dc78d7e6e331b8c6bb2d5283e06aa26883ca7c) # v21.12
12 + set(NEED_ABSL False)
13 +
14 + if(CMAKE_CXX_STANDARD GREATER_EQUAL 14)
15 + set(PROTOBUF_TAG 4a2aef570deb2bfb8927426558701e8bfc26f2a4) # v25.3
16 + set(NEED_ABSL True)
17 + set(ABSL_TAG 2f9e432cce407ce0ae50676696666f33a77d42ac) # 20240116.1
18 + endif()
19
20 set(FETCHCONTENT_TRY_FIND_PACKAGE_MODE NEVER)
21
@@ -115,27 +87,7 @@ macro(netdata_detect_protobuf)
87
88 if(TARGET protobuf::libprotobuf)
89 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()
90 + set(Protobuf_PROTOC_EXECUTABLE protobuf::protoc)
91 endif()
92
93 # It is technically possible that this may still not
@@ -146,27 +98,8 @@ macro(netdata_detect_protobuf)
98 message(FATAL_ERROR "Could not determine the location of the protobuf compiler for the detected version of protobuf.")
99 endif()
100
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})
101 + set(PROTOBUF_PROTOC_EXECUTABLE ${Protobuf_PROTOC_EXECUTABLE})
102 + set(PROTOBUF_LIBRARIES protobuf::libprotobuf)
103 endif()
104
105 set(ENABLE_PROTOBUF True)
@@ -203,9 +136,9 @@ function(netdata_protoc_generate_cpp INC_DIR OUT_DIR SRCS HDRS)
136 endif()
137
138 add_custom_command(OUTPUT ${GENERATED_PB_CC} ${GENERATED_PB_H}
206 - COMMAND ${NETDATA_PROTOBUF_PROTOC_EXECUTABLE}
139 + COMMAND ${PROTOBUF_PROTOC_EXECUTABLE}
140 ARGS "-I$<JOIN:${_PROTOC_INCLUDE_DIRS},;-I>" --cpp_out=${OUT_DIR} ${ABS_FIL}
208 - DEPENDS ${ABS_FIL} ${NETDATA_PROTOBUF_PROTOC_EXECUTABLE}
141 + DEPENDS ${ABS_FIL} ${PROTOBUF_PROTOC_EXECUTABLE}
142 COMMENT "Running C++ protocol buffer compiler on ${FIL}"
143 COMMAND_EXPAND_LISTS)
144 endforeach()
@@ -219,7 +152,7 @@ endfunction()
152
153 # Add protobuf to a specified target.
154 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})
155 + target_compile_definitions(${_target} PRIVATE ${PROTOBUF_CFLAGS_OTHER})
156 + target_include_directories(${_target} PRIVATE ${PROTOBUF_INCLUDE_DIRS})
157 + target_link_libraries(${_target} PRIVATE ${PROTOBUF_LIBRARIES})
158 endfunction()