• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright 2023 the 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++ helloworld 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 helloworld.
19
20cmake_minimum_required(VERSION 3.8)
21
22project(ErrorDetails C CXX)
23
24include(../cmake/common.cmake)
25
26# Proto files
27get_filename_component(hw_proto "../../protos/helloworld.proto" ABSOLUTE)
28get_filename_component(hw_proto_path "${hw_proto}" PATH)
29get_filename_component(status_proto "../../../third_party/googleapis/google/rpc/status.proto" ABSOLUTE)
30get_filename_component(status_proto_path "${status_proto}" PATH)
31get_filename_component(error_details_proto "../../../third_party/googleapis/google/rpc/error_details.proto" ABSOLUTE)
32get_filename_component(error_details_proto_path "${error_details_proto}" PATH)
33get_filename_component(protobuf_proto_path "../../../third_party/protobuf/src" ABSOLUTE)
34
35# Generated sources
36set(hw_proto_srcs "${CMAKE_CURRENT_BINARY_DIR}/helloworld.pb.cc")
37set(hw_proto_hdrs "${CMAKE_CURRENT_BINARY_DIR}/helloworld.pb.h")
38set(hw_grpc_srcs "${CMAKE_CURRENT_BINARY_DIR}/helloworld.grpc.pb.cc")
39set(hw_grpc_hdrs "${CMAKE_CURRENT_BINARY_DIR}/helloworld.grpc.pb.h")
40add_custom_command(
41      OUTPUT "${hw_proto_srcs}" "${hw_proto_hdrs}" "${hw_grpc_srcs}" "${hw_grpc_hdrs}"
42      COMMAND ${_PROTOBUF_PROTOC}
43      ARGS --grpc_out "${CMAKE_CURRENT_BINARY_DIR}"
44        --cpp_out "${CMAKE_CURRENT_BINARY_DIR}"
45        -I "${hw_proto_path}"
46        --plugin=protoc-gen-grpc="${_GRPC_CPP_PLUGIN_EXECUTABLE}"
47        "${hw_proto}"
48      DEPENDS "${hw_proto}")
49set(status_proto_srcs "${CMAKE_CURRENT_BINARY_DIR}/status.pb.cc")
50set(status_proto_hdrs "${CMAKE_CURRENT_BINARY_DIR}/status.pb.h")
51add_custom_command(
52      OUTPUT "${status_proto_srcs}" "${status_proto_hdrs}"
53      COMMAND ${_PROTOBUF_PROTOC}
54      ARGS
55        --cpp_out "${CMAKE_CURRENT_BINARY_DIR}"
56        -I "${status_proto_path}"
57        -I "${protobuf_proto_path}"
58        "${status_proto}"
59      DEPENDS "${status_proto}")
60set(error_details_proto_srcs "${CMAKE_CURRENT_BINARY_DIR}/error_details.pb.cc")
61set(error_details_proto_hdrs "${CMAKE_CURRENT_BINARY_DIR}/error_details.pb.h")
62add_custom_command(
63      OUTPUT "${error_details_proto_srcs}" "${error_details_proto_hdrs}"
64      COMMAND ${_PROTOBUF_PROTOC}
65      ARGS
66          --cpp_out "${CMAKE_CURRENT_BINARY_DIR}"
67          -I "${error_details_proto_path}"
68          -I "${protobuf_proto_path}"
69          "${error_details_proto}"
70      DEPENDS "${error_details_proto}")
71
72# Include generated *.pb.h files
73include_directories("${CMAKE_CURRENT_BINARY_DIR}")
74
75# hw_grpc_proto
76add_library(hw_grpc_proto
77  ${hw_grpc_srcs}
78  ${hw_grpc_hdrs}
79  ${hw_proto_srcs}
80  ${hw_proto_hdrs})
81target_link_libraries(hw_grpc_proto
82  ${_REFLECTION}
83  ${_GRPC_GRPCPP}
84  ${_PROTOBUF_LIBPROTOBUF})
85
86# status_proto
87add_library(status_proto
88  ${status_proto_srcs}
89  ${status_proto_hdrs})
90target_link_libraries(status_proto
91  ${_PROTOBUF_LIBPROTOBUF})
92
93# error_details_proto
94add_library(error_details_proto
95  ${error_details_proto_srcs}
96  ${error_details_proto_hdrs})
97target_link_libraries(error_details_proto
98  ${_PROTOBUF_LIBPROTOBUF})
99
100# Targets greeter_(client|server)
101foreach(_target
102  greeter_client greeter_server)
103  add_executable(${_target} "${_target}.cc")
104  target_link_libraries(${_target}
105    hw_grpc_proto
106    status_proto
107    error_details_proto
108    absl::flags
109    absl::flags_parse
110    ${_REFLECTION}
111    ${_GRPC_GRPCPP}
112    ${_PROTOBUF_LIBPROTOBUF})
113endforeach()
114