[PATCH] D135712: [CMake] Fix FindGRPC cmake module to allow different layering

Steven Wu via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Oct 12 11:49:39 PDT 2022


steven_wu updated this revision to Diff 467217.
steven_wu added a comment.

Was missing the latest feedback. Bump FindGRPC module to top layer.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135712

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


Index: cmake/Modules/FindGRPC.cmake
===================================================================
--- cmake/Modules/FindGRPC.cmake
+++ cmake/Modules/FindGRPC.cmake
@@ -108,7 +108,7 @@
 # If the "GRPC" argument is given, services are also generated.
 # The DEPENDS list should name *.proto source files that are imported.
 # They may be relative to the source dir or absolute (for generated protos).
-function(generate_protos LibraryName ProtoFile)
+macro(generate_protos_source GeneratedSource ProtoFile)
   cmake_parse_arguments(PARSE_ARGV 2 PROTO "GRPC" "" "DEPENDS")
   get_filename_component(ProtoSourceAbsolutePath "${CMAKE_CURRENT_SOURCE_DIR}/${ProtoFile}" ABSOLUTE)
   get_filename_component(ProtoSourcePath ${ProtoSourceAbsolutePath} PATH)
@@ -132,9 +132,7 @@
         ARGS ${Flags} "${ProtoSourceAbsolutePath}"
         DEPENDS "${ProtoSourceAbsolutePath}")
 
-  add_llvm_library(${LibraryName} ${GeneratedProtoSource}
-    PARTIAL_SOURCES_INTENDED
-    LINK_LIBS PUBLIC grpc++ protobuf)
+  set(${GeneratedSource} ${GeneratedProtoSource})
 
   # Ensure dependency headers are generated before dependent protos are built.
   # DEPENDS arg is a list of "Foo.proto". While they're logically relative to
@@ -154,4 +152,4 @@
         PROPERTIES OBJECT_DEPENDS "${ImportedHeader}")
     endforeach(Generated)
   endforeach(ImportedProto)
-endfunction()
+endmacro()
Index: clang/cmake/modules/AddGRPC.cmake
===================================================================
--- /dev/null
+++ clang/cmake/modules/AddGRPC.cmake
@@ -0,0 +1,9 @@
+include(FindGRPC)
+
+function(generate_clang_protos_library LibraryName ProtoFile)
+  generate_protos_source(ProtoSource ${ProtoFile})
+
+  add_clang_library(${LibraryName} ${ProtoSource}
+    PARTIAL_SOURCES_INTENDED
+    LINK_LIBS PUBLIC 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,8 +1,8 @@
 if (CLANGD_ENABLE_REMOTE)
-  generate_protos(clangdRemoteIndexProto "Index.proto")
-  generate_protos(clangdMonitoringServiceProto "MonitoringService.proto"
+  generate_clang_protos_library(clangdRemoteIndexProto "Index.proto")
+  generate_clang_protos_library(clangdMonitoringServiceProto "MonitoringService.proto"
     GRPC)
-  generate_protos(clangdRemoteIndexServiceProto "Service.proto"
+  generate_clang_protos_library(clangdRemoteIndexServiceProto "Service.proto"
     DEPENDS "Index.proto"
     GRPC)
   # FIXME: Move this into generate_protos. Currently we only mention proto
Index: clang-tools-extra/clangd/CMakeLists.txt
===================================================================
--- clang-tools-extra/clangd/CMakeLists.txt
+++ clang-tools-extra/clangd/CMakeLists.txt
@@ -194,7 +194,7 @@
 endif ()
 
 if (CLANGD_ENABLE_REMOTE)
-  include(FindGRPC)
+  include(AddGRPC)
 endif()
 
 if(CLANG_INCLUDE_TESTS)


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D135712.467217.patch
Type: text/x-patch
Size: 3007 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20221012/74a7c9a0/attachment-0001.bin>


More information about the cfe-commits mailing list