Start work on protobuf files and code generation
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
cmake_minimum_required(VERSION 3.23)
|
cmake_minimum_required(VERSION 3.23)
|
||||||
project(chat LANGUAGES CXX)
|
project(chat LANGUAGES CXX)
|
||||||
|
|
||||||
|
add_subdirectory(proto)
|
||||||
add_subdirectory(server)
|
add_subdirectory(server)
|
||||||
add_subdirectory(client)
|
add_subdirectory(client)
|
||||||
|
|||||||
50
proto/CMakeLists.txt
Normal file
50
proto/CMakeLists.txt
Normal file
@@ -0,0 +1,50 @@
|
|||||||
|
cmake_minimum_required(VERSION 3.23)
|
||||||
|
project(proto LANGUAGES CXX)
|
||||||
|
|
||||||
|
find_program(PROTOC_EXECUTABLE protoc)
|
||||||
|
find_program(GRPC_CPP_PLUGIN_EXECUTABLE grpc_cpp_plugin)
|
||||||
|
|
||||||
|
if(NOT PROTOC_EXECUTABLE)
|
||||||
|
message(FATAL_ERROR "protoc not found! Install protobuf compiler")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if(NOT GRPC_CPP_PLUGIN_EXECUTABLE)
|
||||||
|
message(FATAL_ERROR "grpc_cpp_plugin not found! Install gRPC with C++ plugin")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
set(PROTO_FILES
|
||||||
|
${CMAKE_CURRENT_SOURCE_DIR}/messages.proto
|
||||||
|
${CMAKE_CURRENT_SOURCE_DIR}/services.proto
|
||||||
|
)
|
||||||
|
|
||||||
|
set(PROTO_OUT ${CMAKE_CURRENT_BINARY_DIR})
|
||||||
|
|
||||||
|
set(GENERATED_FILES
|
||||||
|
${PROTO_OUT}/messages.pb.h ${PROTO_OUT}/messages.pb.cc
|
||||||
|
${PROTO_OUT}/services.pb.h ${PROTO_OUT}/services.pb.cc
|
||||||
|
${PROTO_OUT}/services.grpc.pb.h ${PROTO_OUT}/services.grpc.pb.cc
|
||||||
|
)
|
||||||
|
|
||||||
|
set(PROTO_INCLUDES
|
||||||
|
"-I${CMAKE_CURRENT_LIST_DIR}"
|
||||||
|
)
|
||||||
|
|
||||||
|
add_custom_command(
|
||||||
|
OUTPUT ${GENERATED_FILES}
|
||||||
|
COMMAND ${PROTOC_EXECUTABLE}
|
||||||
|
ARGS
|
||||||
|
--cpp_out=${PROTO_OUT}
|
||||||
|
--grpc_out=${PROTO_OUT}
|
||||||
|
--plugin=protoc-gen-grpc=${GRPC_CPP_PLUGIN_EXECUTABLE}
|
||||||
|
${PROTO_INCLUDES}
|
||||||
|
${PROTO_FILES}
|
||||||
|
WORKING_DIRECTORY ${PROTO_OUT}
|
||||||
|
DEPENDS ${PROTO_FILES}
|
||||||
|
COMMENT "Generating protobuf files"
|
||||||
|
COMMAND_EXPAND_LISTS
|
||||||
|
VERBATIM
|
||||||
|
)
|
||||||
|
|
||||||
|
set_source_files_properties(${GENERATED_FILES} PROPERTIES GENERATED TRUE)
|
||||||
|
|
||||||
|
add_library(proto_interface INTERFACE ${GENERATED_FILES})
|
||||||
8
proto/messages.proto
Normal file
8
proto/messages.proto
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
syntax = "proto3";
|
||||||
|
|
||||||
|
package chat;
|
||||||
|
|
||||||
|
message chatMsg {
|
||||||
|
string userid = 1;
|
||||||
|
string message = 2;
|
||||||
|
}
|
||||||
9
proto/services.proto
Normal file
9
proto/services.proto
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
syntax = "proto3";
|
||||||
|
|
||||||
|
package chat;
|
||||||
|
|
||||||
|
import "messages.proto";
|
||||||
|
|
||||||
|
service Chat {
|
||||||
|
rpc sendMsg(stream chatMsg) returns (stream chatMsg) {}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user