1cmake_minimum_required(VERSION 3.4.1) 2 3set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11") 4 5# https://github.com/abseil/abseil-cpp/issues/626 6set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DABSL_NO_XRAY_ATTRIBUTES=1") 7 8set(PROTOBUF_PROTOC_EXECUTABLE "/usr/local/bin/protoc" CACHE STRING "Protoc binary on host") 9set(gRPC_CPP_PLUGIN_EXECUTABLE "/usr/local/bin/grpc_cpp_plugin" CACHE STRING "gRPC CPP plugin binary on host") 10 11set(GRPC_SRC_DIR ../../../../../) 12 13set(GRPC_BUILD_DIR ../grpc/outputs/${ANDROID_ABI}) 14file(MAKE_DIRECTORY ${GRPC_BUILD_DIR}) 15 16add_subdirectory(${GRPC_SRC_DIR} ${GRPC_BUILD_DIR}) 17 18#include_directories(${GRPC_SRC_DIR}/include) 19include_directories(${GRPC_SRC_DIR}) 20include_directories(${_gRPC_ABSL_INCLUDE_DIR}) 21 22set(GRPC_PROTO_GENS_DIR ${CMAKE_BINARY_DIR}/gens) 23file(MAKE_DIRECTORY ${GRPC_PROTO_GENS_DIR}) 24include_directories(${GRPC_PROTO_GENS_DIR}) 25 26function(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) 65endfunction() 66 67set(PROTO_BASE_DIR ${GRPC_SRC_DIR}/examples/protos) 68 69android_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 73add_library(messages_proto_lib 74 SHARED ${MESSAGES_PROTO_SRCS} ${MESSAGES_PROTO_HDRS}) 75 76target_link_libraries(messages_proto_lib 77 libprotobuf 78 grpc++ 79 android 80 log) 81 82android_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 86add_library(empty_proto_lib 87 SHARED ${EMPTY_PROTO_SRCS} ${EMPTY_PROTO_HDRS}) 88 89target_link_libraries(empty_proto_lib 90 libprotobuf 91 grpc++ 92 android 93 log) 94 95android_protobuf_grpc_generate_cpp( 96 TEST_PROTO_SRCS TEST_PROTO_HDRS ${GRPC_SRC_DIR} ${GRPC_SRC_DIR}/src/proto/grpc/testing/test.proto) 97 98add_library(test_proto_lib 99 SHARED ${TEST_PROTO_SRCS} ${TEST_PROTO_HDRS}) 100 101target_link_libraries(test_proto_lib 102 libprotobuf 103 grpc++ 104 empty_proto_lib 105 messages_proto_lib 106 android 107 log) 108 109find_library(log-lib 110 log) 111 112add_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 120target_link_libraries(grpc-interop 121 messages_proto_lib 122 empty_proto_lib 123 test_proto_lib 124 android 125 ${log-lib}) 126