xref: /aosp_15_r20/external/grpc-grpc/examples/cpp/multiplex/CMakeLists.txt (revision cc02d7e222339f7a4f6ba5f422e6413f4bd931f2)
1# Copyright 2023 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(Multiplex 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(rg_proto "../../protos/route_guide.proto" ABSOLUTE)
30get_filename_component(rg_proto_path "${rg_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")
37set(rg_proto_srcs "${CMAKE_CURRENT_BINARY_DIR}/route_guide.pb.cc")
38set(rg_proto_hdrs "${CMAKE_CURRENT_BINARY_DIR}/route_guide.pb.h")
39set(rg_grpc_srcs "${CMAKE_CURRENT_BINARY_DIR}/route_guide.grpc.pb.cc")
40set(rg_grpc_hdrs "${CMAKE_CURRENT_BINARY_DIR}/route_guide.grpc.pb.h")
41add_custom_command(
42      OUTPUT "${hw_proto_srcs}" "${hw_proto_hdrs}" "${hw_grpc_srcs}" "${hw_grpc_hdrs}"
43        "${rg_proto_srcs}" "${rg_proto_hdrs}" "${rg_grpc_srcs}" "${rg_grpc_hdrs}"
44      COMMAND ${_PROTOBUF_PROTOC}
45      ARGS --grpc_out "${CMAKE_CURRENT_BINARY_DIR}"
46        --cpp_out "${CMAKE_CURRENT_BINARY_DIR}"
47        -I "${rg_proto_path}"
48        --plugin=protoc-gen-grpc="${_GRPC_CPP_PLUGIN_EXECUTABLE}"
49        "${hw_proto}" "${rg_proto}"
50      DEPENDS "${hw_proto}" "${rg_proto}")
51
52# Include generated *.pb.h files
53include_directories("${CMAKE_CURRENT_BINARY_DIR}")
54
55# example_grpc_proto
56add_library(example_grpc_proto
57  ${hw_grpc_srcs}
58  ${hw_grpc_hdrs}
59  ${hw_proto_srcs}
60  ${hw_proto_hdrs}
61  ${rg_grpc_srcs}
62  ${rg_grpc_hdrs}
63  ${rg_proto_srcs}
64  ${rg_proto_hdrs}
65)
66target_link_libraries(
67  example_grpc_proto
68  ${_REFLECTION}
69  ${_GRPC_GRPCPP}
70  ${_PROTOBUF_LIBPROTOBUF})
71
72# Targets multiplex_(client|server)
73foreach(_target multiplex_client multiplex_server)
74  add_executable(${_target} "${_target}.cc")
75  target_link_libraries(${_target}
76    example_grpc_proto
77    absl::flags
78    absl::flags_parse
79    ${_REFLECTION}
80    ${_GRPC_GRPCPP}
81    ${_PROTOBUF_LIBPROTOBUF})
82endforeach()
83