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