From e77845974c06a694be84689671c4f2f2a5b64592 Mon Sep 17 00:00:00 2001 From: Sutou Kouhei Date: Fri, 28 Mar 2025 10:52:19 +0900 Subject: [PATCH] GH-45959: [C++][CMake] Fix Protobuf dependency in Arrow::arrow_static If Protobuf is used only for Flight, Arrow::arrow_static must not depend on Protobuf. Instead, ArrowFlight::arrow_flight_static must depend on Protobuf. --- cpp/src/arrow/CMakeLists.txt | 4 +--- cpp/src/arrow/flight/CMakeLists.txt | 9 ++++++++- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/cpp/src/arrow/CMakeLists.txt b/cpp/src/arrow/CMakeLists.txt index a77ac4abfbf..404e2a03501 100644 --- a/cpp/src/arrow/CMakeLists.txt +++ b/cpp/src/arrow/CMakeLists.txt @@ -126,9 +126,7 @@ if(ARROW_WITH_RE2) endif() endif() -# This should be done after if(ARROW_ORC) and if(ARROW_WITH_OPENTELEMETRY) -# because they depend on Protobuf. -if(ARROW_WITH_PROTOBUF) +if(ARROW_PROTOBUF_ARROW_CMAKE_PACKAGE_NAME STREQUAL "Arrow") if(Protobuf_SOURCE STREQUAL "SYSTEM") list(APPEND ARROW_STATIC_INSTALL_INTERFACE_LIBS ${ARROW_PROTOBUF_LIBPROTOBUF}) endif() diff --git a/cpp/src/arrow/flight/CMakeLists.txt b/cpp/src/arrow/flight/CMakeLists.txt index 7f86d51e200..47085f1c4a9 100644 --- a/cpp/src/arrow/flight/CMakeLists.txt +++ b/cpp/src/arrow/flight/CMakeLists.txt @@ -33,6 +33,13 @@ if(APPLE AND ARROW_USE_OPENSSL) list(APPEND ARROW_FLIGHT_LINK_LIBS ${ARROW_OPENSSL_LIBS}) endif() +set(ARROW_FLIGHT_STATIC_INSTALL_INTERFACE_LIBS Arrow::arrow_static) +if(ARROW_PROTOBUF_ARROW_CMAKE_PACKAGE_NAME STREQUAL "ArrowFlight") + if(Protobuf_SOURCE STREQUAL "SYSTEM") + list(APPEND ARROW_FLIGHT_STATIC_INSTALL_INTERFACE_LIBS ${ARROW_PROTOBUF_LIBPROTOBUF}) + endif() +endif() + set(ARROW_FLIGHT_TEST_LINKAGE "${ARROW_TEST_LINKAGE}") if(Protobuf_USE_STATIC_LIBS) message(STATUS "Linking Arrow Flight tests statically due to static Protobuf") @@ -204,7 +211,7 @@ add_arrow_lib(arrow_flight ${ARROW_FLIGHT_LINK_LIBS} arrow_static STATIC_INSTALL_INTERFACE_LIBS - Arrow::arrow_static) + ${ARROW_FLIGHT_STATIC_INSTALL_INTERFACE_LIBS}) if(ARROW_BUILD_STATIC AND WIN32) target_compile_definitions(arrow_flight_static PUBLIC ARROW_FLIGHT_STATIC)