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