[PATCH] D85285: [clangd] WIP experimentation with finding static grpc++ libraries

Kirill Bobyrev via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Aug 5 01:44:28 PDT 2020


kbobyrev created this revision.
Herald added subscribers: llvm-commits, cfe-commits, usaxena95, kadircet, arphaman, jkorous, mgorny.
Herald added projects: clang, LLVM.
kbobyrev requested review of this revision.
Herald added subscribers: MaskRay, ilya-biryukov.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D85285

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


Index: llvm/cmake/modules/FindGRPC.cmake
===================================================================
--- llvm/cmake/modules/FindGRPC.cmake
+++ llvm/cmake/modules/FindGRPC.cmake
@@ -26,9 +26,9 @@
   if (GRPC_CPP_PLUGIN-NOTFOUND OR PROTOC-NOTFOUND)
     message(FATAL_ERROR "gRPC C++ Plugin and Protoc must be on $PATH for Clangd remote index build")
   endif()
-  # On macOS the libraries are typically installed via Homebrew and are not on
-  # the system path.
   if (${APPLE})
+    # On macOS the libraries are typically installed via Homebrew and are not on
+    # the system path.
     find_program(HOMEBREW brew)
     # If Homebrew is not found, the user might have installed libraries
     # manually. Fall back to the system path.
@@ -66,6 +66,51 @@
                               IMPORTED_LOCATION ${PROTOBUF_LIBRARY})
       endif()
     endif()
+  elseif(${UNIX} AND NOT BUILD_SHARED_LIBS)
+    # Use dpkg on Debian-like Linux distributions to find static libraries.
+    find_program(DPKG dpkg)
+    if (NOT DPKG-NOTFOUND)
+      execute_process(COMMAND ${DPKG} -L libgrpc++-dev
+        OUTPUT_VARIABLE GRPC_DPKG_PATHS
+        RESULT_VARIABLE GRPC_DPKG_RETURN_CODE
+        OUTPUT_STRIP_TRAILING_WHITESPACE)
+      if (GRPC_DPKG_RETURN_CODE EQUAL "0")
+        # Split the output into CMake list.
+        string(REPLACE "\n" ";" GRPC_DPKG_LINES ${GRPC_DPKG_PATHS})
+        foreach(GRPC_PATH ${GRPC_DPKG_LINES})
+          string(FIND ${GRPC_PATH} "libgrpc++.a" LIBGRPCPP_SUBSTR_IDX)
+          if (NOT LIBGRPCPP_SUBSTR_IDX EQUAL "-1")
+            add_library(grpc++ STATIC IMPORTED GLOBAL)
+            set_target_properties(grpc++ PROPERTIES
+                                  IMPORTED_LOCATION ${GRPC_PATH})
+            message("grpc++ lib ${GRPC_PATH}")
+          endif()
+          string(FIND ${GRPC_PATH} "libgrpc++_unsecure.a" LIBGRRPC_UNSECURE_SUBSTR_IDX)
+          if (NOT LIBGRRPC_UNSECURE_SUBSTR_IDX EQUAL "-1")
+            add_library(libgrpc++_unsecure STATIC IMPORTED GLOBAL)
+            set_target_properties(libgrpc++_unsecure PROPERTIES
+                                  IMPORTED_LOCATION ${GRPC_PATH})
+            message("grpc+++_unsecure lib ${GRPC_PATH}")
+          endif()
+        endforeach()
+      endif()
+      execute_process(COMMAND ${DPKG} -L libprotobuf-dev
+        OUTPUT_VARIABLE PROTOBUF_DPKG_PATHS
+        RESULT_VARIABLE PROTOBUF_DPKG_RETURN_CODE
+        OUTPUT_STRIP_TRAILING_WHITESPACE)
+      if (PROTOBUF_DPKG_RETURN_CODE EQUAL "0")
+        # Split the output into CMake list.
+        string(REPLACE "\n" ";" PROTOBUF_DPKG_LINES ${PROTOBUF_DPKG_PATHS})
+        foreach(PROTOBUF_PATH ${PROTOBUF_DPKG_LINES})
+          string(FIND ${PROTOBUF_PATH} "libprotobuf.a" LIBPROTOBUF_SUBSTR_IDX)
+          if (NOT LIBPROTOBUF_SUBSTR_IDX EQUAL "-1")
+            add_library(protobuf STATIC IMPORTED GLOBAL)
+            set_target_properties(protobuf PROPERTIES
+                                  IMPORTED_LOCATION ${PROTOBUF_PATH})
+          endif()
+        endforeach()
+      endif()
+    endif()
   endif()
 endif()
 
Index: clang-tools-extra/clangd/index/remote/server/CMakeLists.txt
===================================================================
--- clang-tools-extra/clangd/index/remote/server/CMakeLists.txt
+++ clang-tools-extra/clangd/index/remote/server/CMakeLists.txt
@@ -15,5 +15,8 @@
   RemoteIndexProtos
   clangdRemoteMarshalling
 
-  grpc++
+  /usr/local/google/home/kbobyrev/software/grpc-latest/lib/libgrpc++.a
+  /usr/local/google/home/kbobyrev/software/grpc-latest/lib/libgrpc.a
+  /usr/local/google/home/kbobyrev/software/grpc-latest/lib/libgrpc++_unsecure.a
+  /usr/local/google/home/kbobyrev/software/grpc-latest/lib/libgrpc_unsecure.a
   )


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D85285.283165.patch
Type: text/x-patch
Size: 3743 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200805/c4a8b756/attachment.bin>


More information about the llvm-commits mailing list