1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
| find_package(gRPC CONFIG REQUIRED)
get_target_property(PROTOC protobuf::protoc LOCATION) get_target_property(GRPC_PLUGIN gRPC::grpc_cpp_plugin LOCATION)
set(PROTO_SRCS "") set(PROTO_HDRS "") set(GRPC_SRCS "") set(GRPC_HDRS "")
file(MAKE_DIRECTORY messages)
file(GLOB PROTO_FILES "${CMAKE_SOURCE_DIR}/protos/*.proto")
foreach(PROTO_FILE ${PROTO_FILES}) get_filename_component(PROTO_NAME ${PROTO_FILE} NAME) get_filename_component(PROTO_NAME_WE ${PROTO_FILE} NAME_WE)
add_custom_command( OUTPUT "${CMAKE_SOURCE_DIR}/messages/${PROTO_NAME_WE}.pb.h" "${CMAKE_SOURCE_DIR}/messages/${PROTO_NAME_WE}.pb.cc" COMMAND ${PROTOC} ARGS -I${CMAKE_SOURCE_DIR}/protos --cpp_out=${CMAKE_SOURCE_DIR}/messages ${PROTO_NAME} DEPENDS ${PROTO_FILE} COMMENT "Generating proroto sources for ${PROTO_NAME}" ) list(APPEND PROTO_SRCS "${CMAKE_SOURCE_DIR}/messages/${PROTO_NAME_WE}.pb.cc") list(APPEND PROTO_HDRS "${CMAKE_SOURCE_DIR}/messages/${PROTO_NAME_WE}.pb.h")
add_custom_command( OUTPUT "${CMAKE_SOURCE_DIR}/messages/${PROTO_NAME_WE}.grpc.pb.h" "${CMAKE_SOURCE_DIR}/messages/${PROTO_NAME_WE}.grpc.pb.cc" COMMAND ${PROTOC} ARGS -I${CMAKE_CURRENT_SOURCE_DIR}/protos --cpp_out=${CMAKE_SOURCE_DIR}/messages --plugin=protoc-gen-grpc=${GRPC_PLUGIN} --grpc_out=${CMAKE_SOURCE_DIR}/messages ${PROTO_NAME} DEPENDS ${PROTO_FILE} COMMENT "Generating gRPC sources for ${PROTO_NAME}" )
list(APPEND GRPC_SRCS "${CMAKE_SOURCE_DIR}/messages/${PROTO_NAME_WE}.grpc.pb.cc") list(APPEND GRPC_HDRS "${CMAKE_SOURCE_DIR}/messages/${PROTO_NAME_WE}.grpc.pb.h") endforeach()
|