Move gRPC build configuration to FindGrpc.cmake

This commit is contained in:
David Li authored and Wes McKinney committed 2019-01-19 19:23:38 -06:00
1 parent d3074ac5f3
commit ee85e86747
2 files changed
+102 -14

No files matched your search

+96
View File
@@ -0,0 +1,96 @@
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# PROTOBUF_HOME environmental variable is used to check for Protobuf headers and static library
# PROTOBUF_INCLUDE_DIR: directory containing headers
# PROTOBUF_LIBS: directory containing Protobuf libraries
# PROTOBUF_STATIC_LIB: location of protobuf.a
# PROTOC_STATIC_LIB: location of protoc.a
# PROTOBUF_EXECUTABLE: location of protoc
# PROTOBUF_FOUND is set if Protobuf is found
if( NOT "${GRPC_HOME}" STREQUAL "")
file (TO_CMAKE_PATH "${GRPC_HOME}" _grpc_path)
endif()
message (STATUS "GRPC_HOME: ${GRPC_HOME}")
find_path (GRPC_INCLUDE_DIR grpc/grpc.h HINTS
${_grpc_path}
NO_DEFAULT_PATH
PATH_SUFFIXES "include")
set (lib_dirs "lib")
if (EXISTS "${_grpc_path}/lib64")
set (lib_dirs "lib64" ${lib_dirs})
endif ()
if (EXISTS "${_grpc_path}/lib/${CMAKE_LIBRARY_ARCHITECTURE}")
set (lib_dirs "lib/${CMAKE_LIBRARY_ARCHITECTURE}" ${lib_dirs})
endif ()
find_library (GPR_STATIC_LIB
NAMES "${CMAKE_STATIC_LIBRARY_PREFIX}gpr${CMAKE_STATIC_LIBRARY_SUFFIX}"
PATHS ${_grpc_path}
NO_DEFAULT_PATH
PATH_SUFFIXES ${lib_dirs})
find_library (GRPC_ADDRESS_SORTING_STATIC_LIB
NAMES "${CMAKE_STATIC_LIBRARY_PREFIX}address_sorting${CMAKE_STATIC_LIBRARY_SUFFIX}"
PATHS ${_grpc_path}
NO_DEFAULT_PATH
PATH_SUFFIXES ${lib_dirs})
find_library (GRPC_STATIC_LIB
NAMES "${CMAKE_STATIC_LIBRARY_PREFIX}grpc${CMAKE_STATIC_LIBRARY_SUFFIX}"
PATHS ${_grpc_path}
NO_DEFAULT_PATH
PATH_SUFFIXES ${lib_dirs})
find_library (GRPCPP_STATIC_LIB
NAMES "${CMAKE_STATIC_LIBRARY_PREFIX}grpc++${CMAKE_STATIC_LIBRARY_SUFFIX}"
PATHS ${_grpc_path}
NO_DEFAULT_PATH
PATH_SUFFIXES ${lib_dirs})
find_program(GRPC_CPP_PLUGIN grpc_cpp_plugin protoc-gen-grpc-cpp
HINTS ${_grpc_path}
NO_DEFAULT_PATH
PATH_SUFFIXES "bin")
if (GRPC_INCLUDE_DIR AND GPR_STATIC_LIB AND GRPC_ADDRESS_SORTING_STATIC_LIB AND
GRPC_STATIC_LIB AND GRPCPP_STATIC_LIB AND GRPC_CPP_PLUGIN)
set (gRPC_FOUND TRUE)
else ()
set (gRPC_FOUND FALSE)
endif ()
if (gRPC_FOUND)
message (STATUS "Found the gRPC headers: ${GRPC_INCLUDE_DIR}")
else()
if (_grpc_path)
set (GRPC_ERR_MSG "Could not find gRPC. Looked in ${_grpc_path}.")
else ()
set (GRPC_ERR_MSG "Could not find gRPC in system search paths.")
endif()
if (gRPC_FIND_REQUIRED)
message (FATAL_ERROR "${GRPC_ERR_MSG}")
else ()
message (STATUS "${GRPC_ERR_MSG}")
endif ()
endif()
mark_as_advanced (
GRPC_INCLUDE_DIR
)
+6 -14
View File
@@ -1244,12 +1244,7 @@ if (ARROW_FLIGHT)
CMAKE_ARGS ${GRPC_CMAKE_ARGS}
${EP_LOG_OPTIONS})
include_directories(SYSTEM ${GRPC_INCLUDE_DIR})
else()
find_package(gRPC CONFIG)
set(GRPC_VENDORED 0)
endif()
if (GRPC_VENDORED OR gRPC_FOUND)
get_property(GPR_STATIC_LIB TARGET gRPC::gpr PROPERTY LOCATION)
get_property(GRPC_STATIC_LIB TARGET gRPC::grpc_unsecure PROPERTY LOCATION)
get_property(GRPCPP_STATIC_LIB TARGET gRPC::grpc++_unsecure PROPERTY LOCATION)
@@ -1260,15 +1255,8 @@ if (ARROW_FLIGHT)
# Get location of grpc_cpp_plugin so we can pass it to protoc
get_property(GRPC_CPP_PLUGIN TARGET gRPC::grpc_cpp_plugin PROPERTY LOCATION)
else()
# This is a non-CMake installation of gRPC
set(GPR_STATIC_LIB "${GRPC_HOME}/lib/${CMAKE_STATIC_LIBRARY_PREFIX}gpr${CMAKE_STATIC_LIBRARY_SUFFIX}")
set(GRPC_STATIC_LIB "${GRPC_HOME}/lib/${CMAKE_STATIC_LIBRARY_PREFIX}grpc${CMAKE_STATIC_LIBRARY_SUFFIX}")
set(GRPCPP_STATIC_LIB "${GRPC_HOME}/lib/${CMAKE_STATIC_LIBRARY_PREFIX}grpc++${CMAKE_STATIC_LIBRARY_SUFFIX}")
set(GRPC_ADDRESS_SORTING_STATIC_LIB "${GRPC_HOME}/lib/${CMAKE_STATIC_LIBRARY_PREFIX}address_sorting${CMAKE_STATIC_LIBRARY_SUFFIX}")
if ("${GRPC_CPP_PLUGIN}" STREQUAL "")
message(SEND_ERROR "Please set GRPC_CPP_PLUGIN.")
endif()
find_package(gRPC REQUIRED)
set(GRPC_VENDORED 0)
# If gRPC is built with CMake, it installs its own c-ares, so use
# that; otherwise, see if the user provided a c-ares installation
@@ -1277,6 +1265,10 @@ if (ARROW_FLIGHT)
endif()
endif()
if ("${GRPC_CPP_PLUGIN}" STREQUAL "")
message(SEND_ERROR "Please set GRPC_CPP_PLUGIN.")
endif()
ADD_THIRDPARTY_LIB(grpc_gpr
STATIC_LIB ${GPR_STATIC_LIB})