xref: /aosp_15_r20/external/grpc-grpc/examples/cpp/health/CMakeLists.txt (revision cc02d7e222339f7a4f6ba5f422e6413f4bd931f2)
1# Copyright 2024 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(HelloWorld C CXX)
23
24include(../cmake/common.cmake)
25
26# Proto file
27get_filename_component(hw_proto "../../protos/helloworld.proto" ABSOLUTE)
28get_filename_component(hw_proto_path "${hw_proto}" PATH)
29get_filename_component(health_proto "../../../src/proto/grpc/health/v1/health.proto" ABSOLUTE)
30get_filename_component(health_proto_path "${health_proto}" PATH)
31
32# Generated sources
33set(hw_proto_srcs "${CMAKE_CURRENT_BINARY_DIR}/helloworld.pb.cc")
34set(hw_proto_hdrs "${CMAKE_CURRENT_BINARY_DIR}/helloworld.pb.h")
35set(hw_grpc_srcs "${CMAKE_CURRENT_BINARY_DIR}/helloworld.grpc.pb.cc")
36set(hw_grpc_hdrs "${CMAKE_CURRENT_BINARY_DIR}/helloworld.grpc.pb.h")
37add_custom_command(
38      OUTPUT "${hw_proto_srcs}" "${hw_proto_hdrs}" "${hw_grpc_srcs}" "${hw_grpc_hdrs}"
39      COMMAND ${_PROTOBUF_PROTOC}
40      ARGS --grpc_out "${CMAKE_CURRENT_BINARY_DIR}"
41        --cpp_out "${CMAKE_CURRENT_BINARY_DIR}"
42        -I "${hw_proto_path}"
43        --plugin=protoc-gen-grpc="${_GRPC_CPP_PLUGIN_EXECUTABLE}"
44        "${hw_proto}"
45      DEPENDS "${hw_proto}")
46
47# Health protos
48set(health_proto_srcs "${CMAKE_CURRENT_BINARY_DIR}/health.pb.cc")
49set(health_proto_hdrs "${CMAKE_CURRENT_BINARY_DIR}/health.pb.h")
50set(health_grpc_srcs "${CMAKE_CURRENT_BINARY_DIR}/health.grpc.pb.cc")
51set(health_grpc_hdrs "${CMAKE_CURRENT_BINARY_DIR}/health.grpc.pb.h")
52add_custom_command(
53      OUTPUT "${health_proto_srcs}" "${health_proto_hdrs}" "${health_grpc_srcs}" "${health_grpc_hdrs}"
54      COMMAND ${_PROTOBUF_PROTOC}
55      ARGS --grpc_out "${CMAKE_CURRENT_BINARY_DIR}"
56        --cpp_out "${CMAKE_CURRENT_BINARY_DIR}"
57        -I "${health_proto_path}"
58        --plugin=protoc-gen-grpc="${_GRPC_CPP_PLUGIN_EXECUTABLE}"
59        "${health_proto}"
60      DEPENDS "${health_proto}")
61
62# Include generated *.pb.h files
63include_directories("${CMAKE_CURRENT_BINARY_DIR}")
64
65# hw_grpc_proto
66add_library(hw_grpc_proto
67  ${hw_grpc_srcs}
68  ${hw_grpc_hdrs}
69  ${hw_proto_srcs}
70  ${hw_proto_hdrs})
71target_link_libraries(hw_grpc_proto
72  ${_REFLECTION}
73  ${_GRPC_GRPCPP}
74  ${_PROTOBUF_LIBPROTOBUF})
75
76#health_grpc_proto
77add_library(health_grpc_proto
78  ${health_grpc_srcs}
79  ${health_grpc_hdrs}
80  ${health_proto_srcs}
81  ${health_proto_hdrs})
82target_link_libraries(health_grpc_proto
83  ${_PROTOBUF_LIBPROTOBUF})
84
85
86# Targets greeter_[async_](client|server)
87foreach(_target
88  health_client health_server)
89  add_executable(${_target} "${_target}.cc")
90  target_link_libraries(${_target}
91    hw_grpc_proto
92    health_grpc_proto
93    absl::flags
94    absl::flags_parse
95    ${_REFLECTION}
96    ${_GRPC_GRPCPP}
97    ${_PROTOBUF_LIBPROTOBUF})
98endforeach()
99