| 1 |
# Copyright 2018 gRPC authors. |
| 2 |
# |
| 3 |
# Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 |
# you may not use this file except in compliance with the License. |
| 5 |
# You may obtain a copy of the License at |
| 6 |
# |
| 7 |
# http://www.apache.org/licenses/LICENSE-2.0 |
| 8 |
# |
| 9 |
# Unless required by applicable law or agreed to in writing, software |
| 10 |
# distributed under the License is distributed on an "AS IS" BASIS, |
| 11 |
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 |
# See the License for the specific language governing permissions and |
| 13 |
# limitations under the License. |
| 14 |
# |
| 15 |
# cmake build file for C++ route_guide example. |
| 16 |
# Assumes protobuf and gRPC have been installed using cmake. |
| 17 |
# See cmake_externalproject/CMakeLists.txt for all-in-one cmake build |
| 18 |
# that automatically builds all the dependencies before building route_guide. |
| 19 |
|
| 20 |
cmake_minimum_required(VERSION 3.5.1) |
| 21 |
|
| 22 |
project(RouteGuide C CXX) |
| 23 |
|
| 24 |
include(../cmake/common.cmake) |
| 25 |
|
| 26 |
# Proto file |
| 27 |
get_filename_component(rg_proto "../../protos/route_guide.proto" ABSOLUTE) |
| 28 |
get_filename_component(rg_proto_path "${rg_proto}" PATH) |
| 29 |
|
| 30 |
# Generated sources |
| 31 |
set(rg_proto_srcs "${CMAKE_CURRENT_BINARY_DIR}/route_guide.pb.cc") |
| 32 |
set(rg_proto_hdrs "${CMAKE_CURRENT_BINARY_DIR}/route_guide.pb.h") |
| 33 |
set(rg_grpc_srcs "${CMAKE_CURRENT_BINARY_DIR}/route_guide.grpc.pb.cc") |
| 34 |
set(rg_grpc_hdrs "${CMAKE_CURRENT_BINARY_DIR}/route_guide.grpc.pb.h") |
| 35 |
add_custom_command( |
| 36 |
OUTPUT "${rg_proto_srcs}" "${rg_proto_hdrs}" "${rg_grpc_srcs}" "${rg_grpc_hdrs}" |
| 37 |
COMMAND ${_PROTOBUF_PROTOC} |
| 38 |
ARGS --grpc_out "${CMAKE_CURRENT_BINARY_DIR}" |
| 39 |
--cpp_out "${CMAKE_CURRENT_BINARY_DIR}" |
| 40 |
-I "${rg_proto_path}" |
| 41 |
--plugin=protoc-gen-grpc="${_GRPC_CPP_PLUGIN_EXECUTABLE}" |
| 42 |
"${rg_proto}" |
| 43 |
DEPENDS "${rg_proto}") |
| 44 |
|
| 45 |
# Include generated *.pb.h files |
| 46 |
include_directories("${CMAKE_CURRENT_BINARY_DIR}") |
| 47 |
|
| 48 |
# rg_grpc_proto |
| 49 |
add_library(rg_grpc_proto |
| 50 |
${rg_grpc_srcs} |
| 51 |
${rg_grpc_hdrs} |
| 52 |
${rg_proto_srcs} |
| 53 |
${rg_proto_hdrs}) |
| 54 |
target_link_libraries(rg_grpc_proto |
| 55 |
${_REFLECTION} |
| 56 |
${_GRPC_GRPCPP} |
| 57 |
${_PROTOBUF_LIBPROTOBUF}) |
| 58 |
|
| 59 |
# route_guide_helper |
| 60 |
add_library(route_guide_helper |
| 61 |
"helper.h" |
| 62 |
"helper.cc") |
| 63 |
target_link_libraries(route_guide_helper |
| 64 |
rg_grpc_proto |
| 65 |
${_REFLECTION} |
| 66 |
${_GRPC_GRPCPP} |
| 67 |
${_PROTOBUF_LIBPROTOBUF}) |
| 68 |
|
| 69 |
# Targets route_guide_(client|server) |
| 70 |
foreach(_target |
| 71 |
route_guide_client route_guide_server) |
| 72 |
add_executable(${_target} |
| 73 |
"${_target}.cc") |
| 74 |
target_link_libraries(${_target} |
| 75 |
rg_grpc_proto |
| 76 |
route_guide_helper |
| 77 |
${_REFLECTION} |
| 78 |
${_GRPC_GRPCPP} |
| 79 |
${_PROTOBUF_LIBPROTOBUF}) |
| 80 |
endforeach() |