Skip to content

Commit

Permalink
ARROW-14585: [C++] Find libgrpc++_reflection via pkg-config
Browse files Browse the repository at this point in the history
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 #11605 from lidavidm/arrow-14585

Authored-by: David Li <li.davidm96@gmail.com>
Signed-off-by: Sutou Kouhei <kou@clear-code.com>
  • Loading branch information
lidavidm authored and kou committed Nov 4, 2021
1 parent fdc6a79 commit ddc19fa
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
20 changes: 20 additions & 0 deletions cpp/cmake_modules/FindgRPCAlt.cmake
Expand Up @@ -56,6 +56,20 @@ if(GRPCPP_PC_FOUND)
list(APPEND gRPCAlt_FIND_PACKAGE_ARGS VERSION_VAR gRPCAlt_VERSION)
endif()
find_package_handle_standard_args(${gRPCAlt_FIND_PACKAGE_ARGS})

# gRPC does not expose the reflection library via pkg-config, but it should be alongside the main library
get_filename_component(GRPCPP_IMPORTED_DIRECTORY ${GRPCPP_IMPORTED_LOCATION} DIRECTORY)
if(ARROW_GRPC_USE_SHARED)
set(GRPCPP_REFLECTION_LIB_NAME
"${CMAKE_SHARED_LIBRARY_PREFIX}grpc++_reflection${CMAKE_SHARED_LIBRARY_SUFFIX}")
else()
set(GRPCPP_REFLECTION_LIB_NAME
"${CMAKE_STATIC_LIBRARY_PREFIX}grpc++_reflection${CMAKE_STATIC_LIBRARY_SUFFIX}")
endif()
find_library(GRPCPP_REFLECTION_IMPORTED_LOCATION
NAMES grpc++_reflection ${GRPCPP_REFLECTION_LIB_NAME}
PATHS ${GRPCPP_IMPORTED_DIRECTORY}
NO_DEFAULT_PATH)
else()
set(gRPCAlt_FOUND FALSE)
endif()
Expand All @@ -70,6 +84,12 @@ if(gRPCAlt_FOUND)
INTERFACE_LINK_LIBRARIES "${GRPCPP_LINK_LIBRARIES}"
INTERFACE_LINK_OPTIONS "${GRPCPP_LINK_OPTIONS}")

add_library(gRPC::grpc++_reflection UNKNOWN IMPORTED)
set_target_properties(gRPC::grpc++_reflection
PROPERTIES IMPORTED_LOCATION
"${GRPCPP_REFLECTION_IMPORTED_LOCATION}"
INTERFACE_LINK_LIBRARIES gRPC::grpc++)

add_executable(gRPC::grpc_cpp_plugin IMPORTED)
set_target_properties(gRPC::grpc_cpp_plugin PROPERTIES IMPORTED_LOCATION
${GRPC_CPP_PLUGIN})
Expand Down
4 changes: 3 additions & 1 deletion cpp/src/arrow/flight/CMakeLists.txt
Expand Up @@ -67,6 +67,8 @@ string(REPLACE "-Werror " " " CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")

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

0 comments on commit ddc19fa

Please sign in to comment.