[PATCH] D90027: [CMake] generate_grpc_protos -> generate_protos(... GRPC). NFC

Sam McCall via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Oct 23 05:28:45 PDT 2020


This revision was not accepted when it landed; it landed in state "Needs Review".
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG81f7b2ac0fdc: [CMake] generate_grpc_protos -> generate_protos(... GRPC). NFC (authored by sammccall).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D90027/new/

https://reviews.llvm.org/D90027

Files:
  clang-tools-extra/clangd/index/remote/CMakeLists.txt
  llvm/cmake/modules/FindGRPC.cmake


Index: llvm/cmake/modules/FindGRPC.cmake
===================================================================
--- llvm/cmake/modules/FindGRPC.cmake
+++ llvm/cmake/modules/FindGRPC.cmake
@@ -83,27 +83,31 @@
 
 # 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()
Index: clang-tools-extra/clangd/index/remote/CMakeLists.txt
===================================================================
--- clang-tools-extra/clangd/index/remote/CMakeLists.txt
+++ 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}/../../)
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D90027.300248.patch
Type: text/x-patch
Size: 2947 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20201023/8d0037dc/attachment.bin>


More information about the llvm-commits mailing list