| 1 |
cmake_minimum_required(VERSION 3.4.1) |
| 2 |
|
| 3 |
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14") |
| 4 |
|
| 5 |
# https://github.com/abseil/abseil-cpp/issues/626 |
| 6 |
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DABSL_NO_XRAY_ATTRIBUTES=1") |
| 7 |
|
| 8 |
set(PROTOBUF_PROTOC_EXECUTABLE "/usr/local/bin/protoc" CACHE STRING "Protoc binary on host") |
| 9 |
set(gRPC_CPP_PLUGIN_EXECUTABLE "/usr/local/bin/grpc_cpp_plugin" CACHE STRING "gRPC CPP plugin binary on host") |
| 10 |
|
| 11 |
set(GRPC_SRC_DIR ../../../../../) |
| 12 |
|
| 13 |
set(GRPC_BUILD_DIR ../grpc/outputs/${ANDROID_ABI}) |
| 14 |
file(MAKE_DIRECTORY ${GRPC_BUILD_DIR}) |
| 15 |
|
| 16 |
add_subdirectory(${GRPC_SRC_DIR} ${GRPC_BUILD_DIR}) |
| 17 |
|
| 18 |
#include_directories(${GRPC_SRC_DIR}/include) |
| 19 |
include_directories(${GRPC_SRC_DIR}) |
| 20 |
include_directories(${_gRPC_ABSL_INCLUDE_DIR}) |
| 21 |
|
| 22 |
set(GRPC_PROTO_GENS_DIR ${CMAKE_BINARY_DIR}/gens) |
| 23 |
file(MAKE_DIRECTORY ${GRPC_PROTO_GENS_DIR}) |
| 24 |
include_directories(${GRPC_PROTO_GENS_DIR}) |
| 25 |
|
| 26 |
function(android_protobuf_grpc_generate_cpp SRC_FILES HDR_FILES INCLUDE_ROOT) |
| 27 |
if(NOT ARGN) |
| 28 |
message(SEND_ERROR "Error: android_protobuf_grpc_generate_cpp() called without any proto files") |
| 29 |
return() |
| 30 |
endif() |
| 31 |
|
| 32 |
set(${SRC_FILES}) |
| 33 |
set(${HDR_FILES}) |
| 34 |
set(PROTOBUF_INCLUDE_PATH -I ${INCLUDE_ROOT}) |
| 35 |
foreach(FIL ${ARGN}) |
| 36 |
get_filename_component(ABS_FIL ${FIL} ABSOLUTE) |
| 37 |
get_filename_component(FIL_WE ${FIL} NAME_WE) |
| 38 |
file(RELATIVE_PATH REL_FIL ${CMAKE_CURRENT_SOURCE_DIR}/${INCLUDE_ROOT} ${ABS_FIL}) |
| 39 |
get_filename_component(REL_DIR ${REL_FIL} DIRECTORY) |
| 40 |
set(RELFIL_WE "${REL_DIR}/${FIL_WE}") |
| 41 |
|
| 42 |
list(APPEND ${SRC_FILES} "${GRPC_PROTO_GENS_DIR}/${RELFIL_WE}.pb.cc") |
| 43 |
list(APPEND ${HDR_FILES} "${GRPC_PROTO_GENS_DIR}/${RELFIL_WE}.pb.h") |
| 44 |
list(APPEND ${SRC_FILES} "${GRPC_PROTO_GENS_DIR}/${RELFIL_WE}.grpc.pb.cc") |
| 45 |
list(APPEND ${HDR_FILES} "${GRPC_PROTO_GENS_DIR}/${RELFIL_WE}.grpc.pb.h") |
| 46 |
|
| 47 |
add_custom_command( |
| 48 |
OUTPUT "${GRPC_PROTO_GENS_DIR}/${RELFIL_WE}.grpc.pb.cc" |
| 49 |
"${GRPC_PROTO_GENS_DIR}/${RELFIL_WE}.grpc.pb.h" |
| 50 |
"${GRPC_PROTO_GENS_DIR}/${RELFIL_WE}.pb.cc" |
| 51 |
"${GRPC_PROTO_GENS_DIR}/${RELFIL_WE}.pb.h" |
| 52 |
COMMAND ${PROTOBUF_PROTOC_EXECUTABLE} |
| 53 |
ARGS --grpc_out=${GRPC_PROTO_GENS_DIR} |
| 54 |
--cpp_out=${GRPC_PROTO_GENS_DIR} |
| 55 |
--plugin=protoc-gen-grpc=${gRPC_CPP_PLUGIN_EXECUTABLE} |
| 56 |
${PROTOBUF_INCLUDE_PATH} |
| 57 |
${REL_FIL} |
| 58 |
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} |
| 59 |
DEPENDS ${PROTOBUF_PROTOC_EXECUTABLE} ${gRPC_CPP_PLUGIN_EXECUTABLE} ${ABS_FIL} ) |
| 60 |
endforeach() |
| 61 |
|
| 62 |
set_source_files_properties(${${SRC_FILES}} ${${HDR_FILES}} PROPERTIES GENERATED TRUE) |
| 63 |
set(${SRC_FILES} ${${SRC_FILES}} PARENT_SCOPE) |
| 64 |
set(${HDR_FILES} ${${HDR_FILES}} PARENT_SCOPE) |
| 65 |
endfunction() |
| 66 |
|
| 67 |
set(PROTO_BASE_DIR ${GRPC_SRC_DIR}/examples/protos) |
| 68 |
|
| 69 |
android_protobuf_grpc_generate_cpp( |
| 70 |
MESSAGES_PROTO_SRCS MESSAGES_PROTO_HDRS |
| 71 |
${GRPC_SRC_DIR} ${GRPC_SRC_DIR}/src/proto/grpc/testing/messages.proto) |
| 72 |
|
| 73 |
add_library(messages_proto_lib |
| 74 |
SHARED ${MESSAGES_PROTO_SRCS} ${MESSAGES_PROTO_HDRS}) |
| 75 |
|
| 76 |
target_link_libraries(messages_proto_lib |
| 77 |
libprotobuf |
| 78 |
grpc++ |
| 79 |
android |
| 80 |
log) |
| 81 |
|
| 82 |
android_protobuf_grpc_generate_cpp( |
| 83 |
EMPTY_PROTO_SRCS EMPTY_PROTO_HDRS |
| 84 |
${GRPC_SRC_DIR} ${GRPC_SRC_DIR}/src/proto/grpc/testing/empty.proto) |
| 85 |
|
| 86 |
add_library(empty_proto_lib |
| 87 |
SHARED ${EMPTY_PROTO_SRCS} ${EMPTY_PROTO_HDRS}) |
| 88 |
|
| 89 |
target_link_libraries(empty_proto_lib |
| 90 |
libprotobuf |
| 91 |
grpc++ |
| 92 |
android |
| 93 |
log) |
| 94 |
|
| 95 |
android_protobuf_grpc_generate_cpp( |
| 96 |
TEST_PROTO_SRCS TEST_PROTO_HDRS ${GRPC_SRC_DIR} ${GRPC_SRC_DIR}/src/proto/grpc/testing/test.proto) |
| 97 |
|
| 98 |
add_library(test_proto_lib |
| 99 |
SHARED ${TEST_PROTO_SRCS} ${TEST_PROTO_HDRS}) |
| 100 |
|
| 101 |
target_link_libraries(test_proto_lib |
| 102 |
libprotobuf |
| 103 |
grpc++ |
| 104 |
empty_proto_lib |
| 105 |
messages_proto_lib |
| 106 |
android |
| 107 |
log) |
| 108 |
|
| 109 |
find_library(log-lib |
| 110 |
log) |
| 111 |
|
| 112 |
add_library(grpc-interop |
| 113 |
SHARED |
| 114 |
src/main/cpp/grpc-interop.cc |
| 115 |
${GRPC_SRC_DIR}/test/cpp/interop/interop_client.h |
| 116 |
${GRPC_SRC_DIR}/test/cpp/interop/interop_client.cc |
| 117 |
${GRPC_SRC_DIR}/test/core/util/histogram.h |
| 118 |
${GRPC_SRC_DIR}/test/core/util/histogram.cc) |
| 119 |
|
| 120 |
target_link_libraries(grpc-interop |
| 121 |
messages_proto_lib |
| 122 |
empty_proto_lib |
| 123 |
test_proto_lib |
| 124 |
android |
| 125 |
${log-lib}) |