This is an automated email from the ASF dual-hosted git repository.

wasphin pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/brpc.git


The following commit(s) were added to refs/heads/master by this push:
     new 4dff8eddf Fix CMake protobuf include order (#3612)
4dff8eddf is described below

commit 4dff8eddf3d2c376c71bf62d42f2c96cf6bc5c2e
Author: nkysg <[email protected]>
AuthorDate: Sun Nov 1 13:18:30 2026 +0800

    Fix CMake protobuf include order (#3612)
---
 src/brpc/CMakeLists.txt  | 3 ++-
 src/butil/CMakeLists.txt | 7 +++++--
 test/CMakeLists.txt      | 4 +++-
 3 files changed, 10 insertions(+), 4 deletions(-)

diff --git a/src/brpc/CMakeLists.txt b/src/brpc/CMakeLists.txt
index 03e45da46..552e3ce99 100644
--- a/src/brpc/CMakeLists.txt
+++ b/src/brpc/CMakeLists.txt
@@ -216,7 +216,8 @@ if(WITH_URMA AND URMA_USE_MOCK_ENABLED)
     target_compile_features(brpc_build_config INTERFACE cxx_std_17)
 endif()
 target_include_directories(brpc_build_config BEFORE INTERFACE
-    ${CMAKE_CURRENT_BINARY_DIR})
+    ${CMAKE_CURRENT_BINARY_DIR}
+    ${Protobuf_INCLUDE_DIRS})
 target_compile_definitions(brpc_build_config INTERFACE ${BRPC_DEFINITIONS})
 target_include_directories(brpc_build_config INTERFACE ${BRPC_INCLUDE_DIRS})
 
diff --git a/src/butil/CMakeLists.txt b/src/butil/CMakeLists.txt
index 901bc1954..3aebb38ed 100644
--- a/src/butil/CMakeLists.txt
+++ b/src/butil/CMakeLists.txt
@@ -52,7 +52,9 @@ configure_file(${CMAKE_CURRENT_SOURCE_DIR}/config.h.in
 get_filename_component(butil_generated_include_dir
     "${CMAKE_CURRENT_BINARY_DIR}/.." ABSOLUTE)
 
-set(BUTIL_INCLUDE_DIRS ${GFLAGS_INCLUDE_PATH} ${PROTOBUF_INCLUDE_DIRS})
+# Keep generic dependency prefixes after the selected Protobuf installation.
+# Otherwise a shared prefix can supply incompatible google/protobuf headers.
+set(BUTIL_INCLUDE_DIRS ${GFLAGS_INCLUDE_PATH})
 if(WITH_GLOG)
     find_path(GLOG_INCLUDE_PATH NAMES glog/logging.h)
     find_library(GLOG_LIB NAMES glog)
@@ -91,7 +93,8 @@ add_library(butil_build_config INTERFACE)
 target_link_libraries(butil_build_config INTERFACE brpc_common_config)
 target_compile_definitions(butil_build_config INTERFACE ${BUTIL_DEFINITIONS})
 target_include_directories(butil_build_config BEFORE INTERFACE
-    ${butil_generated_include_dir})
+    ${butil_generated_include_dir}
+    ${Protobuf_INCLUDE_DIRS})
 target_include_directories(butil_build_config INTERFACE ${BUTIL_INCLUDE_DIRS})
 
 set(butil_crc32c_options)
diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt
index d4348027a..8800daeb4 100644
--- a/test/CMakeLists.txt
+++ b/test/CMakeLists.txt
@@ -23,7 +23,9 @@ find_package(Gperftools)
 
 add_library(brpc_test_config INTERFACE)
 target_link_libraries(brpc_test_config INTERFACE brpc_build_config)
-target_include_directories(brpc_test_config INTERFACE 
${CMAKE_CURRENT_BINARY_DIR})
+target_include_directories(brpc_test_config BEFORE INTERFACE
+    ${CMAKE_CURRENT_BINARY_DIR}
+    ${Protobuf_INCLUDE_DIRS})
 target_compile_definitions(brpc_test_config INTERFACE
     UNIT_TEST
     BVAR_NOT_LINK_DEFAULT_VARIABLES


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to