Skip to content

Commit ddc19fa

Browse files
lidavidmkou
authored andcommitted
ARROW-14585: [C++] Find libgrpc++_reflection via pkg-config
gRPC does not ship a pkg-config file for the reflection library, so assume it's next to the discovered gRPC library. Also, gRPC's pkg-config file neglects to include pthreads, so manually specify that as well, when doing gRPC feature detection. (Otherwise we incorrectly conclude that gRPC doesn't support advanced TLS options.) Closes apache#11605 from lidavidm/arrow-14585 Authored-by: David Li <li.davidm96@gmail.com> Signed-off-by: Sutou Kouhei <kou@clear-code.com>
1 parent fdc6a79 commit ddc19fa

2 files changed

Lines changed: 23 additions & 1 deletion

File tree

cpp/cmake_modules/FindgRPCAlt.cmake

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,20 @@ if(GRPCPP_PC_FOUND)
5656
list(APPEND gRPCAlt_FIND_PACKAGE_ARGS VERSION_VAR gRPCAlt_VERSION)
5757
endif()
5858
find_package_handle_standard_args(${gRPCAlt_FIND_PACKAGE_ARGS})
59+
60+
# gRPC does not expose the reflection library via pkg-config, but it should be alongside the main library
61+
get_filename_component(GRPCPP_IMPORTED_DIRECTORY ${GRPCPP_IMPORTED_LOCATION} DIRECTORY)
62+
if(ARROW_GRPC_USE_SHARED)
63+
set(GRPCPP_REFLECTION_LIB_NAME
64+
"${CMAKE_SHARED_LIBRARY_PREFIX}grpc++_reflection${CMAKE_SHARED_LIBRARY_SUFFIX}")
65+
else()
66+
set(GRPCPP_REFLECTION_LIB_NAME
67+
"${CMAKE_STATIC_LIBRARY_PREFIX}grpc++_reflection${CMAKE_STATIC_LIBRARY_SUFFIX}")
68+
endif()
69+
find_library(GRPCPP_REFLECTION_IMPORTED_LOCATION
70+
NAMES grpc++_reflection ${GRPCPP_REFLECTION_LIB_NAME}
71+
PATHS ${GRPCPP_IMPORTED_DIRECTORY}
72+
NO_DEFAULT_PATH)
5973
else()
6074
set(gRPCAlt_FOUND FALSE)
6175
endif()
@@ -70,6 +84,12 @@ if(gRPCAlt_FOUND)
7084
INTERFACE_LINK_LIBRARIES "${GRPCPP_LINK_LIBRARIES}"
7185
INTERFACE_LINK_OPTIONS "${GRPCPP_LINK_OPTIONS}")
7286

87+
add_library(gRPC::grpc++_reflection UNKNOWN IMPORTED)
88+
set_target_properties(gRPC::grpc++_reflection
89+
PROPERTIES IMPORTED_LOCATION
90+
"${GRPCPP_REFLECTION_IMPORTED_LOCATION}"
91+
INTERFACE_LINK_LIBRARIES gRPC::grpc++)
92+
7393
add_executable(gRPC::grpc_cpp_plugin IMPORTED)
7494
set_target_properties(gRPC::grpc_cpp_plugin PROPERTIES IMPORTED_LOCATION
7595
${GRPC_CPP_PLUGIN})

cpp/src/arrow/flight/CMakeLists.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ string(REPLACE "-Werror " " " CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
6767

6868
# Probe the version of gRPC being used to see if it supports disabling server
6969
# verification when using TLS.
70+
# gRPC's pkg-config file neglects to specify pthreads.
71+
find_package(Threads REQUIRED)
7072
function(test_grpc_version DST_VAR DETECT_VERSION TEST_FILE)
7173
if(NOT DEFINED ${DST_VAR})
7274
message(STATUS "Checking support for TlsCredentialsOptions (gRPC >= ${DETECT_VERSION})..."
@@ -80,7 +82,7 @@ function(test_grpc_version DST_VAR DETECT_VERSION TEST_FILE)
8082
try_compile(HAS_GRPC_VERSION ${CMAKE_CURRENT_BINARY_DIR}/try_compile
8183
SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/try_compile/${TEST_FILE}"
8284
CMAKE_FLAGS "-DINCLUDE_DIRECTORIES=${CURRENT_INCLUDE_DIRECTORIES}"
83-
LINK_LIBRARIES gRPC::grpc++
85+
LINK_LIBRARIES gRPC::grpc++ Threads::Threads
8486
OUTPUT_VARIABLE TLS_CREDENTIALS_OPTIONS_CHECK_OUTPUT CXX_STANDARD 11)
8587
if(HAS_GRPC_VERSION)
8688
set(${DST_VAR}

0 commit comments

Comments
 (0)