[clang-tools-extra] 81f7b2a - [CMake] generate_grpc_protos -> generate_protos(... GRPC). NFC
Sam McCall via cfe-commits
cfe-commits at lists.llvm.org
Fri Oct 23 05:28:34 PDT 2020
Author: Sam McCall
Date: 2020-10-23T14:28:07+02:00
New Revision: 81f7b2ac0fdc84906d31f6824e34103798d3306c
URL: https://github.com/llvm/llvm-project/commit/81f7b2ac0fdc84906d31f6824e34103798d3306c
DIFF: https://github.com/llvm/llvm-project/commit/81f7b2ac0fdc84906d31f6824e34103798d3306c.diff
LOG: [CMake] generate_grpc_protos -> generate_protos(... GRPC). NFC
Differential Revision: https://reviews.llvm.org/D90027
Added:
Modified:
clang-tools-extra/clangd/index/remote/CMakeLists.txt
llvm/cmake/modules/FindGRPC.cmake
Removed:
################################################################################
diff --git a/clang-tools-extra/clangd/index/remote/CMakeLists.txt b/clang-tools-extra/clangd/index/remote/CMakeLists.txt
index 81287b58afa5..8bd5db543921 100644
--- a/clang-tools-extra/clangd/index/remote/CMakeLists.txt
+++ b/clang-tools-extra/clangd/index/remote/CMakeLists.txt
@@ -1,5 +1,5 @@
if (CLANGD_ENABLE_REMOTE)
- generate_grpc_protos(RemoteIndexProtos "Index.proto")
+ generate_protos(RemoteIndexProtos "Index.proto" GRPC)
include_directories(${CMAKE_CURRENT_BINARY_DIR})
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../../)
diff --git a/llvm/cmake/modules/FindGRPC.cmake b/llvm/cmake/modules/FindGRPC.cmake
index 3e33c2ed8a93..757b16adefac 100644
--- a/llvm/cmake/modules/FindGRPC.cmake
+++ b/llvm/cmake/modules/FindGRPC.cmake
@@ -83,27 +83,31 @@ endif()
# Proto headers are generated in ${CMAKE_CURRENT_BINARY_DIR}.
# Libraries that use these headers should adjust the include path.
-# FIXME(kirillbobyrev): Allow optional generation of gRPC code and give callers
-# control over it via additional parameters.
-function(generate_grpc_protos LibraryName ProtoFile)
+# If the "GRPC" argument is given, services are also generated.
+function(generate_protos LibraryName ProtoFile)
+ cmake_parse_arguments(PARSE_ARGV 2 PROTO "GRPC" "" "")
get_filename_component(ProtoSourceAbsolutePath "${CMAKE_CURRENT_SOURCE_DIR}/${ProtoFile}" ABSOLUTE)
get_filename_component(ProtoSourcePath ${ProtoSourceAbsolutePath} PATH)
set(GeneratedProtoSource "${CMAKE_CURRENT_BINARY_DIR}/Index.pb.cc")
set(GeneratedProtoHeader "${CMAKE_CURRENT_BINARY_DIR}/Index.pb.h")
- set(GeneratedGRPCSource "${CMAKE_CURRENT_BINARY_DIR}/Index.grpc.pb.cc")
- set(GeneratedGRPCHeader "${CMAKE_CURRENT_BINARY_DIR}/Index.grpc.pb.h")
+ set(Flags
+ --cpp_out="${CMAKE_CURRENT_BINARY_DIR}"
+ --proto_path="${ProtoSourcePath}")
+ if (PROTO_GRPC)
+ list(APPEND Flags
+ --grpc_out="${CMAKE_CURRENT_BINARY_DIR}"
+ --plugin=protoc-gen-grpc="${GRPC_CPP_PLUGIN}")
+ list(APPEND GeneratedProtoSource "${CMAKE_CURRENT_BINARY_DIR}/Index.grpc.pb.cc")
+ list(APPEND GeneratedProtoHeader "${CMAKE_CURRENT_BINARY_DIR}/Index.grpc.pb.h")
+ endif()
add_custom_command(
- OUTPUT "${GeneratedProtoSource}" "${GeneratedProtoHeader}" "${GeneratedGRPCSource}" "${GeneratedGRPCHeader}"
+ OUTPUT ${GeneratedProtoSource} ${GeneratedProtoHeader}
COMMAND ${PROTOC}
- ARGS --grpc_out="${CMAKE_CURRENT_BINARY_DIR}"
- --cpp_out="${CMAKE_CURRENT_BINARY_DIR}"
- --proto_path="${ProtoSourcePath}"
- --plugin=protoc-gen-grpc="${GRPC_CPP_PLUGIN}"
- "${ProtoSourceAbsolutePath}"
- DEPENDS "${ProtoSourceAbsolutePath}")
+ ARGS ${Flags} "${ProtoSourceAbsolutePath}"
+ DEPENDS "${ProtoSourceAbsolutePath}")
- add_clang_library(${LibraryName} ${GeneratedProtoSource} ${GeneratedGRPCSource}
+ add_clang_library(${LibraryName} ${GeneratedProtoSource}
PARTIAL_SOURCES_INTENDED
LINK_LIBS grpc++ protobuf)
endfunction()
More information about the cfe-commits
mailing list