cmake integration

27 views
Skip to first unread message

Stéphane Ancelot

unread,
Jun 1, 2023, 10:25:44 AM6/1/23
to grpc.io
Hi !

From my viewpoint cmake integration is really a pain !

I used the quickstart to build and deploy grpc ... fine ...

Now I want to use it in my project to build proto files.

I used this cmake snippet to build it :

find_package(absl CONFIG REQUIRED PATHS /opt/grpc)
find_package(utf8_range CONFIG HINTS /opt/grpc REQUIRED)
find_package(protobuf CONFIG HINTS /opt/grpc REQUIRED)
find_package(gRPC CONFIG REQUIRED PATHS /opt/grpc)
find_package(Threads)

add_library(myproto ${PROTO_FILES})
target_link_libraries(myproto
PUBLIC
protobuf::libprotobuf
gRPC::grpc
gRPC::grpc++
)
target_include_directories(myproto PUBLIC ${CMAKE_CURRENT_BINARY_DIR})

#
# Compile protobuf and grpc files in myproto target to cpp
get_target_property(grpc_cpp_plugin_location gRPC::grpc_cpp_plugin IMPORTED)
message("status cpp plugin ${grpc_cpp_plugin_location}")
protobuf_generate(TARGET myproto LANGUAGE cpp)
protobuf_generate(TARGET myproto LANGUAGE grpc GENERATE_EXTENSIONS .grpc.pb.h .grpc.pb.cc PLUGIN "protoc-gen-grpc=${grpc_cpp_plugin_location}")

unfortunately the grpc_cpp_plugin_location variable is equal to TRUE ....

and thus it does not work.

What is the straight way to use cmake with gRPC ??

Regards
Steph
Reply all
Reply to author
Forward
0 new messages