Skip to content

Commit e09cb53

Browse files
committed
Fix build failure with the Protobuf 23.3
### Motivation The current CMakeLists.txt does not work with the latest Protobuf (23.3.0). It's because currently the Module mode is used to find Protobuf, while the `FindProtobuf.cmake` is not updated to find the Abseil dependency. See protocolbuffers/protobuf#12292 (comment) ### Modifications For macOS, use the Config mode to find Protobuf. It's because in other systems, the Module mode works well. Besides, enable `PROTOBUF_USE_DLLS` as a workaround for protocolbuffers/protobuf#12983 is not released. Pin the default C++ standard to 17 for macOS so that users don't need to set the C++ standard manually.
1 parent 0202218 commit e09cb53

File tree

5 files changed

+47
-31
lines changed

5 files changed

+47
-31
lines changed

.github/workflows/ci-pr-validation.yaml

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,7 @@ jobs:
5050
- name: Install deps (macOS)
5151
if: ${{ startsWith(matrix.os, 'macos') }}
5252
run: |
53-
# Install protobuf v21.12
54-
wget https://raw.githubusercontent.com/Homebrew/homebrew-core/2d47ed2eac09d59ffc2c92b1d804f1c232188c88/Formula/protobuf.rb
55-
brew install --formula ./protobuf.rb
56-
brew install pkg-config wireshark
57-
53+
brew install pkg-config wireshark protobuf
5854
- name: Build wireshark plugin
5955
run: |
6056
cmake -S wireshark -B build-wireshark
@@ -270,20 +266,11 @@ jobs:
270266
uses: actions/checkout@v3
271267

272268
- name: Install dependencies
273-
run: |
274-
# Install protobuf v21.12
275-
wget https://raw.githubusercontent.com/Homebrew/homebrew-core/2d47ed2eac09d59ffc2c92b1d804f1c232188c88/Formula/protobuf.rb
276-
brew install --formula ./protobuf.rb
277-
brew install openssl boost zstd snappy googletest
269+
run: brew install openssl protobuf boost zstd snappy googletest
278270

279271
- name: Configure (default)
280272
shell: bash
281-
run: |
282-
# The latest GTest requires C++14
283-
cmake \
284-
-B ./build-macos \
285-
-DCMAKE_CXX_STANDARD=14 \
286-
-S .
273+
run: cmake -B ./build-macos -S .
287274

288275
- name: Compile
289276
shell: bash

CMakeLists.txt

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,12 @@ MESSAGE(STATUS "Threads library: " ${CMAKE_THREAD_LIBS_INIT})
8686

8787
set(Boost_NO_BOOST_CMAKE ON)
8888
if (NOT CMAKE_CXX_STANDARD)
89-
set(CMAKE_CXX_STANDARD 11)
89+
if (APPLE)
90+
# The latest Protobuf dependency on macOS requires the C++17 support
91+
set(CMAKE_CXX_STANDARD 17)
92+
else ()
93+
set(CMAKE_CXX_STANDARD 11)
94+
endif ()
9095
endif ()
9196
set(CMAKE_C_STANDARD 11)
9297

@@ -135,7 +140,14 @@ find_package(OpenSSL REQUIRED)
135140
message("OPENSSL_INCLUDE_DIR: " ${OPENSSL_INCLUDE_DIR})
136141
message("OPENSSL_LIBRARIES: " ${OPENSSL_LIBRARIES})
137142

138-
find_package(Protobuf REQUIRED)
143+
if (APPLE)
144+
# See https://github.com/apache/arrow/issues/35987
145+
add_definitions(-DPROTOBUF_USE_DLLS)
146+
# Use Config mode to avoid FindProtobuf.cmake does not find the Abseil library
147+
find_package(Protobuf REQUIRED CONFIG)
148+
else ()
149+
find_package(Protobuf REQUIRED)
150+
endif ()
139151
message("Protobuf_INCLUDE_DIRS: " ${Protobuf_INCLUDE_DIRS})
140152
message("Protobuf_LIBRARIES: " ${Protobuf_LIBRARIES})
141153

@@ -173,7 +185,7 @@ if (LINK_STATIC AND NOT VCPKG_TRIPLET)
173185
add_definitions(-DCURL_STATICLIB)
174186
endif()
175187
elseif (LINK_STATIC AND VCPKG_TRIPLET)
176-
find_package(protobuf REQUIRED)
188+
find_package(Protobuf REQUIRED)
177189
message(STATUS "Found protobuf static library: " ${Protobuf_LIBRARIES})
178190
if (MSVC AND (${CMAKE_BUILD_TYPE} STREQUAL Debug))
179191
find_library(ZLIB_LIBRARIES NAMES zlibd)
@@ -296,14 +308,20 @@ set(COMMON_LIBS
296308
${Boost_REGEX_LIBRARY}
297309
${Boost_SYSTEM_LIBRARY}
298310
${Boost_DATE_TIME_LIBRARY}
299-
${Protobuf_LIBRARIES}
300311
${CURL_LIBRARIES}
301312
${OPENSSL_LIBRARIES}
302313
${ZLIB_LIBRARIES}
303314
${ADDITIONAL_LIBRARIES}
304315
${CMAKE_DL_LIBS}
305316
)
306317

318+
if (APPLE)
319+
# Protobuf_LIBRARIES is empty when finding Protobuf in Config mode
320+
set(COMMON_LIBS ${COMMON_LIBS} protobuf::libprotobuf)
321+
else ()
322+
set(COMMON_LIBS ${COMMON_LIBS} ${Protobuf_LIBRARIES})
323+
endif ()
324+
307325
if (MSVC)
308326
set(COMMON_LIBS
309327
${COMMON_LIBS}

README.md

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,10 @@ The [dependencies.yaml](./dependencies.yaml) file provides the recommended depen
5959
cmake . -DCMAKE_CXX_STANDARD=14
6060
```
6161

62+
> **Note**:
63+
>
64+
> On macOS, the default C++ standard is 17 because the latest Protobuf from Homebrew requires the C++17 support.
65+
6266
## Platforms
6367

6468
Pulsar C++ Client Library has been tested on:
@@ -135,21 +139,14 @@ brew install cmake openssl protobuf boost googletest zstd snappy
135139
#### Compile Pulsar client library:
136140

137141
```shell
138-
cmake . -DCMAKE_CXX_STANDARD=14
139-
make
140-
```
141-
142-
You need to configure `CMAKE_CXX_STANDARD` with 14 because the latest `googletest` dependency from HomeBrew requires the C++14 support. If you don't want to build tests, you can run:
143-
144-
```bash
145-
cmake . -DBUILD_TESTS=OFF
142+
cmake .
146143
make
147144
```
148145

149146
If you want to build performance tools, you need to run:
150147

151148
```shell
152-
cmake . -DBUILD_PERF_TOOLS=ON -DCMAKE_CXX_STANDARD=14
149+
cmake . -DBUILD_PERF_TOOLS=ON
153150
make
154151
```
155152

wireshark/CMakeLists.txt

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,14 @@
2020
cmake_minimum_required(VERSION 3.7)
2121
project(pulsar-cpp-wireshark)
2222

23-
set(CMAKE_CXX_STANDARD 11)
23+
if (NOT CMAKE_CXX_STANDARD)
24+
if (APPLE)
25+
# The latest Protobuf dependency on macOS requires the C++17 support
26+
set(CMAKE_CXX_STANDARD 17)
27+
else ()
28+
set(CMAKE_CXX_STANDARD 11)
29+
endif ()
30+
endif ()
2431

2532
if (CMAKE_SYSTEM_NAME STREQUAL "Darwin" AND CMAKE_SYSTEM_PROCESSOR STREQUAL "arm64")
2633
execute_process(COMMAND sh -c "find $(brew --prefix)/Cellar/wireshark -name 'include' -type d"
@@ -45,7 +52,12 @@ pkg_check_modules(GLIB glib-2.0)
4552
MESSAGE(STATUS "Use WIRESHARK_INCLUDE_PATH: ${WIRESHARK_INCLUDE_PATH}")
4653
MESSAGE(STATUS "Use GLIB_INCLUDE_DIRS: ${GLIB_INCLUDE_DIRS}")
4754

48-
find_package(Protobuf REQUIRED)
55+
set(protobuf_MODULE_COMPATIBLE ON CACHE BOOL "")
56+
if (APPLE)
57+
find_package(Protobuf REQUIRED CONFIG)
58+
else ()
59+
find_package(Protobuf REQUIRED)
60+
endif ()
4961

5062
set(PROTO_SOURCES PulsarApi.pb.cc)
5163
protobuf_generate_cpp(${PROTO_SOURCES}

wireshark/pulsarDissector.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ constexpr int kWiresharkMinorVersion = VERSION_MINOR;
3434
#include <glib.h>
3535
#include <wsutil/nstime.h>
3636

37+
#include <map>
38+
3739
#include "PulsarApi.pb.h"
3840

3941
#ifdef VERSION

0 commit comments

Comments
 (0)