xref: /aosp_15_r20/external/grpc-grpc/examples/cpp/interceptors/CMakeLists.txt (revision cc02d7e222339f7a4f6ba5f422e6413f4bd931f2)
1# Copyright 2021 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++ keyvaluestore 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 keyvaluestore.
19
20cmake_minimum_required(VERSION 3.8)
21
22project(KeyValueStore C CXX)
23
24include(../cmake/common.cmake)
25
26# Proto file
27get_filename_component(kvs_proto "../../protos/keyvaluestore.proto" ABSOLUTE)
28get_filename_component(kvs_proto_path "${kvs_proto}" PATH)
29
30# Generated sources
31set(kvs_proto_srcs "${CMAKE_CURRENT_BINARY_DIR}/keyvaluestore.pb.cc")
32set(kvs_proto_hdrs "${CMAKE_CURRENT_BINARY_DIR}/keyvaluestore.pb.h")
33set(kvs_grpc_srcs "${CMAKE_CURRENT_BINARY_DIR}/keyvaluestore.grpc.pb.cc")
34set(kvs_grpc_hdrs "${CMAKE_CURRENT_BINARY_DIR}/keyvaluestore.grpc.pb.h")
35add_custom_command(
36      OUTPUT "${kvs_proto_srcs}" "${kvs_proto_hdrs}" "${kvs_grpc_srcs}" "${kvs_grpc_hdrs}"
37      COMMAND ${_PROTOBUF_PROTOC}
38      ARGS --grpc_out "${CMAKE_CURRENT_BINARY_DIR}"
39        --cpp_out "${CMAKE_CURRENT_BINARY_DIR}"
40        -I "${kvs_proto_path}"
41        --plugin=protoc-gen-grpc="${_GRPC_CPP_PLUGIN_EXECUTABLE}"
42        "${kvs_proto}"
43      DEPENDS "${kvs_proto}")
44
45# Include generated *.pb.h files
46include_directories("${CMAKE_CURRENT_BINARY_DIR}")
47
48# kvs_grpc_proto
49add_library(kvs_grpc_proto
50  ${kvs_grpc_srcs}
51  ${kvs_grpc_hdrs}
52  ${kvs_proto_srcs}
53  ${kvs_proto_hdrs})
54target_link_libraries(kvs_grpc_proto
55  ${_REFLECTION}
56  ${_GRPC_GRPCPP}
57  ${_PROTOBUF_LIBPROTOBUF})
58
59# client
60add_executable(client "client.cc" "caching_interceptor.h")
61target_link_libraries(client
62  kvs_grpc_proto
63  ${_REFLECTION}
64  ${_GRPC_GRPCPP}
65  ${_PROTOBUF_LIBPROTOBUF})
66
67# server
68add_executable(server "server.cc")
69target_link_libraries(server
70  kvs_grpc_proto
71  ${_REFLECTION}
72  ${_GRPC_GRPCPP}
73  ${_PROTOBUF_LIBPROTOBUF})
74