@@ -12,19 +12,35 @@ set(example_proto_hdrs "${CMAKE_CURRENT_BINARY_DIR}/messages.pb.h")
1212set (example_grpc_srcs "${CMAKE_CURRENT_BINARY_DIR} /messages.grpc.pb.cc" )
1313set (example_grpc_hdrs "${CMAKE_CURRENT_BINARY_DIR} /messages.grpc.pb.h" )
1414
15+ if (NOT TARGET gRPC::grpc_cpp_plugin)
16+ message (
17+ FATAL_ERROR
18+ "gRPC::grpc_cpp_plugin target not found. Please ensure that gRPC is installed and found with find_package."
19+ )
20+ endif ()
21+
22+ if (NOT DEFINED PROTOBUF_PROTOC_EXECUTABLE)
23+ if (NOT TARGET protobuf::protoc)
24+ message (
25+ FATAL_ERROR
26+ "protobuf::protoc target not found. Please ensure that Protobuf is installed and found with find_package."
27+ )
28+ endif ()
29+ set (PROTOBUF_PROTOC_EXECUTABLE protobuf::protoc)
30+ endif ()
31+
1532add_custom_command (
1633 OUTPUT "${example_proto_srcs} " "${example_proto_hdrs} " "${example_grpc_srcs} "
1734 "${example_grpc_hdrs} "
1835 COMMAND
1936 ${PROTOBUF_PROTOC_EXECUTABLE} ARGS "--grpc_out=${CMAKE_CURRENT_BINARY_DIR} "
2037 "--cpp_out=${CMAKE_CURRENT_BINARY_DIR} " "--proto_path=${proto_file_path} "
21- "--plugin=protoc-gen-grpc=${gRPC_CPP_PLUGIN_EXECUTABLE} " "${proto_file} " )
38+ "--plugin=protoc-gen-grpc=$<TARGET_FILE:gRPC::grpc_cpp_plugin>"
39+ "${proto_file} " )
2240
2341add_library (example_grpc_proto ${example_grpc_srcs} ${example_grpc_hdrs}
2442 ${example_proto_srcs} ${example_proto_hdrs} )
2543
26- patch_protobuf_targets(example_grpc_proto)
27-
2844# Disable include-what-you-use on generated code.
2945set_target_properties (example_grpc_proto PROPERTIES CXX_INCLUDE_WHAT_YOU_USE "" )
3046
@@ -45,5 +61,4 @@ foreach(_target client server)
4561 target_link_libraries (
4662 ${_target} PRIVATE example_grpc_proto
4763 opentelemetry-cpp::ostream_span_exporter)
48- patch_protobuf_targets(${_target} )
4964endforeach ()
0 commit comments