• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
20cmake_minimum_required(VERSION 3.16)
21
22project(RouteGuide C CXX)
23
24include(../cmake/common.cmake)
25
26# Find absl package
27find_package(absl CONFIG REQUIRED)
28
29# Proto file
30get_filename_component(rg_proto "../../protos/route_guide.proto" ABSOLUTE)
31get_filename_component(rg_proto_path "${rg_proto}" PATH)
32
33# Generated sources
34set(rg_proto_srcs "${CMAKE_CURRENT_BINARY_DIR}/route_guide.pb.cc")
35set(rg_proto_hdrs "${CMAKE_CURRENT_BINARY_DIR}/route_guide.pb.h")
36set(rg_grpc_srcs "${CMAKE_CURRENT_BINARY_DIR}/route_guide.grpc.pb.cc")
37set(rg_grpc_hdrs "${CMAKE_CURRENT_BINARY_DIR}/route_guide.grpc.pb.h")
38add_custom_command(
39      OUTPUT "${rg_proto_srcs}" "${rg_proto_hdrs}" "${rg_grpc_srcs}" "${rg_grpc_hdrs}"
40      COMMAND ${_PROTOBUF_PROTOC}
41      ARGS --grpc_out "${CMAKE_CURRENT_BINARY_DIR}"
42        --cpp_out "${CMAKE_CURRENT_BINARY_DIR}"
43        -I "${rg_proto_path}"
44        --plugin=protoc-gen-grpc="${_GRPC_CPP_PLUGIN_EXECUTABLE}"
45        "${rg_proto}"
46      DEPENDS "${rg_proto}")
47
48# Include generated *.pb.h files
49include_directories("${CMAKE_CURRENT_BINARY_DIR}")
50
51# rg_grpc_proto
52add_library(rg_grpc_proto
53  ${rg_grpc_srcs}
54  ${rg_grpc_hdrs}
55  ${rg_proto_srcs}
56  ${rg_proto_hdrs})
57target_link_libraries(rg_grpc_proto
58  absl::absl_log
59  ${_REFLECTION}
60  ${_GRPC_GRPCPP}
61  ${_PROTOBUF_LIBPROTOBUF})
62
63# route_guide_helper
64add_library(route_guide_helper
65  "helper.h"
66  "helper.cc")
67target_link_libraries(route_guide_helper
68  rg_grpc_proto
69  ${_REFLECTION}
70  ${_GRPC_GRPCPP}
71  ${_PROTOBUF_LIBPROTOBUF})
72
73# Targets route_guide_(client|server)
74foreach(_target
75  route_guide_client route_guide_server
76  route_guide_callback_client route_guide_callback_server)
77  add_executable(${_target}
78    "${_target}.cc")
79  target_link_libraries(${_target}
80    rg_grpc_proto
81    route_guide_helper
82    absl::flags_parse
83    absl::absl_log
84    absl::log_initialize
85    absl::log_globals
86    ${_REFLECTION}
87    ${_GRPC_GRPCPP}
88    ${_PROTOBUF_LIBPROTOBUF})
89endforeach()
90