1# Copyright 2018 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.16) 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) 29 30# Generated sources 31set(hw_proto_srcs "${CMAKE_CURRENT_BINARY_DIR}/helloworld.pb.cc") 32set(hw_proto_hdrs "${CMAKE_CURRENT_BINARY_DIR}/helloworld.pb.h") 33set(hw_grpc_srcs "${CMAKE_CURRENT_BINARY_DIR}/helloworld.grpc.pb.cc") 34set(hw_grpc_hdrs "${CMAKE_CURRENT_BINARY_DIR}/helloworld.grpc.pb.h") 35add_custom_command( 36 OUTPUT "${hw_proto_srcs}" "${hw_proto_hdrs}" "${hw_grpc_srcs}" "${hw_grpc_hdrs}" 37 COMMAND ${_PROTOBUF_PROTOC} 38 ARGS --grpc_out "${CMAKE_CURRENT_BINARY_DIR}" 39 --cpp_out "${CMAKE_CURRENT_BINARY_DIR}" 40 -I "${hw_proto_path}" 41 --plugin=protoc-gen-grpc="${_GRPC_CPP_PLUGIN_EXECUTABLE}" 42 "${hw_proto}" 43 DEPENDS "${hw_proto}") 44 45# Include generated *.pb.h files 46include_directories("${CMAKE_CURRENT_BINARY_DIR}") 47 48# hw_grpc_proto 49add_library(hw_grpc_proto 50 ${hw_grpc_srcs} 51 ${hw_grpc_hdrs} 52 ${hw_proto_srcs} 53 ${hw_proto_hdrs}) 54target_link_libraries(hw_grpc_proto 55 absl::check 56 ${_REFLECTION} 57 ${_GRPC_GRPCPP} 58 ${_PROTOBUF_LIBPROTOBUF}) 59 60# Targets greeter_[async_](client|server) 61foreach(_target 62 greeter_client greeter_server 63 greeter_callback_client greeter_callback_server 64 greeter_async_client greeter_async_client2 greeter_async_server) 65 add_executable(${_target} "${_target}.cc") 66 target_link_libraries(${_target} 67 hw_grpc_proto 68 absl::check 69 absl::flags 70 absl::flags_parse 71 absl::log 72 ${_REFLECTION} 73 ${_GRPC_GRPCPP} 74 ${_PROTOBUF_LIBPROTOBUF}) 75endforeach() 76