|
#
|
|
# Locate and configure the gRPC library
|
|
#
|
|
# Adds the following targets:
|
|
#
|
|
# gRPC::grpc - gRPC library
|
|
# gRPC::grpc++ - gRPC C++ library
|
|
# gRPC::grpc++_reflection - gRPC C++ reflection library
|
|
# gRPC::grpc_cpp_plugin - C++ generator plugin for Protocol Buffers
|
|
#
|
|
# Generates C++ sources from the .proto files
|
|
#
|
|
# grpc_generate_cpp (<SLIB> <HDRS> <DEST> [<ARGN>...])
|
|
# PLIB - Proto Static Library generated by .proto file
|
|
# HDRS - variable to define with autogenerated source files and header files
|
|
# DEST - directory where the source files will be created
|
|
# ARGN - .proto files
|
|
function(GRPC_GENERATE_CPP PLIB HDRS DEST)
|
|
add_custom_command(
|
|
OUTPUT ${DEST}/${HDRS}.pb.cc
|
|
${DEST}/${HDRS}.pb.h
|
|
${DEST}/${HDRS}.grpc.pb.cc
|
|
${DEST}/${HDRS}.grpc.pb.h
|
|
COMMAND ${GRPC_BINARY_DIR}/protoc
|
|
ARGS --grpc_out "${DEST}"
|
|
--cpp_out "${DEST}"
|
|
-I "${DEST}"
|
|
--plugin=protoc-gen-grpc=${GRPC_BINARY_DIR}/grpc_cpp_plugin
|
|
${ARGN})
|
|
|
|
add_library(${PLIB}
|
|
${DEST}/${HDRS}.pb.cc
|
|
${DEST}/${HDRS}.pb.h
|
|
${DEST}/${HDRS}.grpc.pb.cc
|
|
${DEST}/${HDRS}.grpc.pb.h)
|
|
set_target_properties(${PLIB} PROPERTIES
|
|
ARCHIVE_OUTPUT_DIRECTORY ${DEST})
|
|
target_link_libraries(${PLIB}
|
|
${GRPC_CLIENT_LIBS})
|
|
if (EXISTS ${DEST}/${PLIB})
|
|
message("${BoldGreen} Added ${PLIB} files at ${DEST} successfully!${ColourReset}")
|
|
else ()
|
|
message(FATAL_ERROR "Add ${PLIB} code failed!")
|
|
endif ()
|
|
endfunction()
|
|
|
|
if(NOT DEFINED GRPC_ROOT)
|
|
message(FATAL_ERROR "GRPC_ROOT not set in FindgRPC.cmake")
|
|
else()
|
|
set(CMAKE_CXX_STANDARD 14)
|
|
set(protobuf_MODULE_COMPATIBLE TRUE)
|
|
list(APPEND CMAKE_PREFIX_PATH "${GRPC_ROOT}/lib/cmake/protobuf/")
|
|
find_package(Protobuf CONFIG REQUIRED)
|
|
message("${BoldGreen}Using protobuf ${Protobuf_VERSION}${ColourReset}")
|
|
list(APPEND CMAKE_PREFIX_PATH "${GRPC_ROOT}/lib/cmake/absl/")
|
|
find_package(absl CONFIG REQUIRED)
|
|
message("${BoldGreen}Using absl-cpp ${absl_VERSION}${ColourReset}")
|
|
list(APPEND CMAKE_PREFIX_PATH "${GRPC_ROOT}/lib/cmake/grpc/")
|
|
find_package(gRPC CONFIG REQUIRED)
|
|
message("${BoldGreen}Using gRPC-cpp ${gRPC_VERSION}${ColourReset}")
|
|
find_path(GRPC_BINARY_DIR grpc_cpp_plugin ${GRPC_ROOT}/bin)
|
|
find_path(GRPC_LIBRARY_DIR cmake/grpc/gRPCConfig.cmake ${GRPC_ROOT}/lib)
|
|
find_path(GRPC_INCLUDE_DIR grpc/grpc.h PATHS ${_GRPC_INCLUDE_DIR} )
|
|
mark_as_advanced(
|
|
GRPC_BINARY_DIR
|
|
GRPC_LIBRARY_DIR
|
|
GRPC_INCLUDE_DIR
|
|
)
|
|
message("${BoldGreen}GRPC_INCLUDE_DIR is ${GRPC_INCLUDE_DIR}${ColourReset}")
|
|
endif ()
|
|
find_program(PROTOBUF_PROTOC protoc)
|
|
find_program(GRPC_CPP_PLUGIN_EXECUTABLE grpc_cpp_plugin)
|
|
set(REFLECTION gRPC::grpc++_reflection)
|
|
set(GRPC_GRPCPP gRPC::grpc++)
|
|
include(${CMAKE_ROOT}/Modules/FindPackageHandleStandardArgs.cmake)
|
|
FIND_PACKAGE_HANDLE_STANDARD_ARGS(gRPC DEFAULT_MSG
|
|
PROTOBUF_PROTOC REFLECTION GRPC_GRPCPP GRPC_CPP_PLUGIN_EXECUTABLE)
|