Hi all,
I use the below CMake script to automatically generate C++ files from a
list of proto files using pre-installed gRPC libraries. My approach does
not work if grpc is built using CMake's FetchContent, i.e as a sub-module,
because CMake could not find the gRPCTargets.cmake file.
How do you handle this issue in your CMake build?
Thanks,
Hung
f# Use local build gRPC and protobuf libraries
set(EXTERNAL_DIR "${ROOT_DIR}/3p")
if(UNIX AND NOT APPLE)
set(protobuf_DIR "${EXTERNAL_DIR}/lib64/cmake/protobuf/")
elseif(APPLE)
set(protobuf_DIR "${EXTERNAL_DIR}/lib/cmake/protobuf/")
elseif(MSVC)
set(protobuf_DIR "${EXTERNAL_DIR}/cmake/")
else()
message(FATAL_ERROR "This platform is unsupported. CMake will exit.")
endif()
set(gRPC_DIR "${EXTERNAL_DIR}/lib/cmake/grpc")
find_package(protobuf CONFIG REQUIRED NO_DEFAULT_PATH)
find_package(gRPC CONFIG REQUIRED NO_DEFAULT_PATH)
find_package(Threads)
set(PROTO_FILES address.proto addressbook.proto healthcheck.proto
helloworld.proto keyvaluestore.proto)
# Add Library target with protobuf sources
add_library(address ${PROTO_FILES})
target_link_libraries(address PUBLIC protobuf::libprotobuf gRPC::grpc
gRPC::grpc++)
target_include_directories(address PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
# Generate protobuf and grpc C++ files
get_target_property(grpc_cpp_plugin_location gRPC::grpc_cpp_plugin LOCATION)
protobuf_generate(TARGET address LANGUAGE cpp)
protobuf_generate(
TARGET
address
LANGUAGE
grpc
GENERATE_EXTENSIONS
.grpc.pb.h
.grpc.pb.cc
PLUGIN
"protoc-gen-grpc=${grpc_cpp_plugin_location}")
--
You received this message because you are subscribed to the Google Groups
"Protocol Buffers" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/protobuf/CAJkfh3q4i4z%3D%2B0Vfv-xByxn%2B_oGn1a2%2BX-LdumGh93d%3DPdyJtQ%40mail.gmail.com.