- I want to use CMake to use protoc to generate the RPC files for cpp
- I am generating make files
- I enable various tracing outputs
- I can see the CMake flags --grpc_out and --plugin in the CMake putput
- The CMake generated build.make file does not contain these flags
- Below are relevant snippets from CMake and FindProtobuf.cmake
- I made a project specific copy of FindProtobuf.cmake because the one
in the kitware repo contains a way to enable --grpc_out. - I need both the generated gRPC client and server code
Does anyone have any suggestions?
// CMakeLists.txt
# =============================================================
# Protobuf
# =============================================================
list(APPEND CMAKE_PREFIX_PATH "/usr/local/protobuf-3.3.0/")
set(Protobuf_USE_STATIC_LIBS ON)
set(Protobuf_DEBUG 1)
set(protobuf_generate_PLUGIN "${GRPC_CPP_PLUGIN_EXECUTABLE}")
include(cmake/FindProtobuf.cmake)
FIND_PACKAGE(Protobuf 3.3.0 REQUIRED)
set(GENERATED_PROTOS_DIR ${CMAKE_CURRENT_BINARY_DIR}/generated)
file(MAKE_DIRECTORY ${GENERATED_PROTOS_DIR})
include_directories(${GENERATED_PROTOS_DIR})
protobuf_generate_cpp( GEN_PROTO_SRCS_CPP GEN_PROTO_HDRS_CPP
IMPORT_DIRS ${PROTO_PATHS}
PROTOS ${PROTO_FILE}
)
add_library(${PROJECT_NAME} SHARED
${GEN_PROTO_SRCS_CPP} ${GEN_PROTO_HDRS_CPP}
src/FooInterface.cpp
)
// FindProtobuf.cmake found here
// https://github.com/Kitware/CMake/blob/master/Modules/FindProtobuf.cmake
// Latest from the repo contains
if(protobuf_generate_PLUGIN)
set(_plugin "--plugin=${protobuf_generate_PLUGIN}")
endif()
// then
add_custom_command(
OUTPUT ${_generated_srcs}
COMMAND protobuf::protoc
ARGS --${protobuf_generate_LANGUAGE}_out ${_dll_export_decl}${protobuf_generate_PROTOC_OUT_DIR} ${_plugin} ${_dll_desc_out} ${_protobuf_include_path} ${_abs_file}
DEPENDS ${_abs_file} protobuf::protoc
COMMENT "Running ${protobuf_generate_LANGUAGE} protocol buffer compiler on ${_proto}"
VERBATIM )
// running cmake3 output
-- OUTPUT FooServices.grpc.pb.cc FooServices.grpc.pb.h
-- COMMAND /usr/local/protobuf-3.3.0/bin/protoc --grpc_out /user/me/ProjectFoo/build/default --cpp_out /user/me/ProjectFoo/build/default -I /user/me/ProjectFoo/src --plugin=protoc-gen-grpc=/usr/local/bin/grpc_cpp_plugin
-- DEPENDS /user/me/ProjectFoo/src/FooServices.proto
-- GEN_PROTO_SRCS_CPP=/user/me/ProjectFoo/build/default/FooServices.pb.cc GEN_PROTO_SRCS_PY=
-- UTIL_LIB_PATH=/build
-- Protobuf_LIBRARIES=/usr/local/protobuf-3.3.0/lib/libprotobuf.a;-lpthread
// running make output
[ 25%] Running cpp protocol buffer compiler on /user/me/ProjectFoo/foo-interface/src/FooServices.proto
/usr/local/protobuf-3.3.0/bin/protoc --cpp_out /user/me/ProjectFoo/foo-interface/build/default -I /user/me/ProjectFoo/foo-interface/src /user/me/ProjectFoo/foo-interface/src/FooServices.proto
// from generated build.make
CMakeFiles/foo-interface.dir/build.make: /usr/local/protobuf-3.3.0/bin/protoc --cpp_out /user/me/ProjectFoo/foo-interface/build/default -I /user/me/ProjectFoo/foo-interface/src /user/me/ProjectFoo/foo-interface/src/FooServices.proto