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++ gRPC OpenTelemetry example. 16# Assumes absl, protobuf, prometheus-cpp, opentelemetry-cpp and gRPC (with -DgRPC_BUILD_OPENTELEMETRY_PLUGIN=ON) 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.13) 21 22project(grpc_opentelemetry_example C CXX) 23 24include(../../cmake/common.cmake) 25 26# Find opentelemetry-cpp package 27find_package(opentelemetry-cpp CONFIG REQUIRED) 28 29# Proto file 30get_filename_component(hw_proto "../../../protos/helloworld.proto" ABSOLUTE) 31get_filename_component(hw_proto_path "${hw_proto}" PATH) 32 33# Generated sources 34set(hw_proto_srcs "${CMAKE_CURRENT_BINARY_DIR}/helloworld.pb.cc") 35set(hw_proto_hdrs "${CMAKE_CURRENT_BINARY_DIR}/helloworld.pb.h") 36set(hw_grpc_srcs "${CMAKE_CURRENT_BINARY_DIR}/helloworld.grpc.pb.cc") 37set(hw_grpc_hdrs "${CMAKE_CURRENT_BINARY_DIR}/helloworld.grpc.pb.h") 38add_custom_command( 39 OUTPUT "${hw_proto_srcs}" "${hw_proto_hdrs}" "${hw_grpc_srcs}" "${hw_grpc_hdrs}" 40 COMMAND ${_PROTOBUF_PROTOC} 41 ARGS --grpc_out "${CMAKE_CURRENT_BINARY_DIR}" 42 --cpp_out "${CMAKE_CURRENT_BINARY_DIR}" 43 -I "${hw_proto_path}" 44 --plugin=protoc-gen-grpc="${_GRPC_CPP_PLUGIN_EXECUTABLE}" 45 "${hw_proto}" 46 DEPENDS "${hw_proto}") 47 48# Include generated *.pb.h files 49include_directories("${CMAKE_CURRENT_BINARY_DIR}") 50include_directories("${CMAKE_SOURCE_DIR}") 51 52# hw_grpc_proto 53add_library(hw_grpc_proto 54 ${hw_grpc_srcs} 55 ${hw_grpc_hdrs} 56 ${hw_proto_srcs} 57 ${hw_proto_hdrs}) 58target_link_libraries(hw_grpc_proto 59 ${_REFLECTION} 60 ${_GRPC_GRPCPP} 61 ${_PROTOBUF_LIBPROTOBUF}) 62 63# util 64add_library(util 65 "../util.cc") 66target_link_libraries(util 67 hw_grpc_proto 68 opentelemetry-cpp::metrics 69 ${_GRPC_GRPCPP} 70 ${_REFLECTION} 71 ${_PROTOBUF_LIBPROTOBUF}) 72 73# Targets greeter_callback_(client|server) 74foreach(_target 75 greeter_callback_client greeter_callback_server) 76 add_executable(${_target} "${_target}.cc") 77 target_link_libraries(${_target} 78 absl::flags 79 absl::flags_parse 80 opentelemetry-cpp::metrics 81 opentelemetry-cpp::ostream_metrics_exporter 82 gRPC::grpcpp_otel_plugin 83 util 84 ${_PROTOBUF_LIBPROTOBUF}) 85endforeach() 86