Код: Выделить всё
FetchContent_Declare(
abseil
GIT_REPOSITORY https://github.com/abseil/abseil-cpp.git
GIT_TAG 20250512.1
)
FetchContent_Declare(
gRPC
GIT_REPOSITORY https://github.com/grpc/grpc.git
GIT_TAG v1.74.1
)
FetchContent_MakeAvailable(abseil gRPC)
Код: Выделить всё
file(GLOB proto_files "${CMAKE_CURRENT_SOURCE_DIR}/proto/*.proto")
set(proto_srcs "${CMAKE_CURRENT_SOURCE_DIR}/test.pb.cc")
set(proto_hdrs "${CMAKE_CURRENT_SOURCE_DIR}/test.pb.h")
set(grpc_srcs "${CMAKE_CURRENT_SOURCE_DIR}/test.grpc.pb.cc")
set(grpc_hdrs "${CMAKE_CURRENT_SOURCE_DIR}/test.grpc.pb.h")
set(protobuf_loc "absolute/path/to/v31.1/protoc")
set(grpc_cpp_plugin_loc "/absolute/path/to/v1.74.1/grpc_cpp_plugin")
add_custom_command(
OUTPUT "${proto_srcs}" "${proto_hdrs}" "${grpc_srcs}" "${grpc_hdrs}"
COMMAND ${protobuf_loc}
ARGS --grpc_out "${CMAKE_CURRENT_SOURCE_DIR}"
--cpp_out "${CMAKE_CURRENT_SOURCE_DIR}"
-I "${CMAKE_CURRENT_SOURCE_DIR}/proto"
--plugin=protoc-gen-grpc="${grpc_cpp_plugin_loc}"
"${proto_files}"
DEPENDS "${proto_files}")
Подробнее здесь: https://stackoverflow.com/questions/797 ... n-in-cmake