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# Assumes protobuf and gRPC have been installed using cmake. 16# See cmake_externalproject/CMakeLists.txt for all-in-one cmake build 17# that automatically builds all the dependencies before building this example. 18 19cmake_minimum_required(VERSION 3.8) 20 21project(Deadline C CXX) 22 23include(../cmake/common.cmake) 24 25# Proto files 26get_filename_component(hw_proto "../../protos/helloworld.proto" ABSOLUTE) 27get_filename_component(hw_proto_path "${hw_proto}" PATH) 28 29# Generated sources 30set(hw_proto_srcs "${CMAKE_CURRENT_BINARY_DIR}/helloworld.pb.cc") 31set(hw_proto_hdrs "${CMAKE_CURRENT_BINARY_DIR}/helloworld.pb.h") 32set(hw_grpc_srcs "${CMAKE_CURRENT_BINARY_DIR}/helloworld.grpc.pb.cc") 33set(hw_grpc_hdrs "${CMAKE_CURRENT_BINARY_DIR}/helloworld.grpc.pb.h") 34add_custom_command( 35 OUTPUT "${hw_proto_srcs}" "${hw_proto_hdrs}" "${hw_grpc_srcs}" "${hw_grpc_hdrs}" 36 COMMAND ${_PROTOBUF_PROTOC} 37 ARGS --grpc_out "${CMAKE_CURRENT_BINARY_DIR}" 38 --cpp_out "${CMAKE_CURRENT_BINARY_DIR}" 39 -I "${hw_proto_path}" 40 --plugin=protoc-gen-grpc="${_GRPC_CPP_PLUGIN_EXECUTABLE}" 41 "${hw_proto}" 42 DEPENDS "${hw_proto}") 43 44# Include generated *.pb.h files 45include_directories("${CMAKE_CURRENT_BINARY_DIR}") 46 47# hw_grpc_proto 48add_library(hw_grpc_proto 49 ${hw_grpc_srcs} 50 ${hw_grpc_hdrs} 51 ${hw_proto_srcs} 52 ${hw_proto_hdrs}) 53target_link_libraries(hw_grpc_proto 54 ${_REFLECTION} 55 ${_GRPC_GRPCPP} 56 ${_PROTOBUF_LIBPROTOBUF}) 57 58# Targets greeter_(client|server) 59foreach(_target 60 client server) 61 add_executable(${_target} "${_target}.cc") 62 target_link_libraries(${_target} 63 hw_grpc_proto 64 absl::flags 65 absl::flags_parse 66 absl::strings 67 ${_REFLECTION} 68 ${_GRPC_GRPCPP} 69 ${_PROTOBUF_LIBPROTOBUF}) 70endforeach() 71