[PATCH] D127893: [CMake] Fix `FindGRPC.cmake` for setting up gRPC related libraries for macOS+homebrew context

Argyrios Kyrtzidis via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Jun 15 12:12:13 PDT 2022


akyrtzi created this revision.
Herald added a subscriber: mgorny.
Herald added a project: All.
akyrtzi requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

- Switch `$GRPC_OPTS` references to `${GRPC_OPTS}`
- Also find and include the search path for `abseil` headers
- Only setup the gRPC related targets once, so that `include(FindGRPC)` can be called from multiple tools


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D127893

Files:
  llvm/cmake/modules/FindGRPC.cmake


Index: llvm/cmake/modules/FindGRPC.cmake
===================================================================
--- llvm/cmake/modules/FindGRPC.cmake
+++ llvm/cmake/modules/FindGRPC.cmake
@@ -61,6 +61,10 @@
         OUTPUT_VARIABLE PROTOBUF_HOMEBREW_PATH
         RESULT_VARIABLE PROTOBUF_HOMEBREW_RETURN_CODE
         OUTPUT_STRIP_TRAILING_WHITESPACE)
+      execute_process(COMMAND ${HOMEBREW} --prefix abseil
+        OUTPUT_VARIABLE ABSL_HOMEBREW_PATH
+        RESULT_VARIABLE ABSL_HOMEBREW_RETURN_CODE
+        OUTPUT_STRIP_TRAILING_WHITESPACE)
       # If either library is not installed via Homebrew, fall back to the
       # system path.
       if (GRPC_HOMEBREW_RETURN_CODE EQUAL "0")
@@ -71,21 +75,26 @@
         include_directories(${PROTOBUF_HOMEBREW_PATH}/include)
         list(APPEND PROTOBUF_OPTS PATHS ${PROTOBUF_HOMEBREW_PATH}/lib NO_DEFAULT_PATH)
       endif()
+      if (ABSL_HOMEBREW_RETURN_CODE EQUAL "0")
+        include_directories(${ABSL_HOMEBREW_PATH}/include)
+      endif()
     endif()
   endif()
-  find_library(GRPC_LIBRARY grpc++ $GRPC_OPTS REQUIRED)
-  add_library(grpc++ UNKNOWN IMPORTED GLOBAL)
-  message(STATUS "Using grpc++: " ${GRPC_LIBRARY})
-  set_target_properties(grpc++ PROPERTIES IMPORTED_LOCATION ${GRPC_LIBRARY})
-  if (ENABLE_GRPC_REFLECTION)
-    find_library(GRPC_REFLECTION_LIBRARY grpc++_reflection $GRPC_OPTS REQUIRED)
-    add_library(grpc++_reflection UNKNOWN IMPORTED GLOBAL)
-    set_target_properties(grpc++_reflection PROPERTIES IMPORTED_LOCATION ${GRPC_REFLECTION_LIBRARY})
+  if(NOT TARGET grpc++)
+    find_library(GRPC_LIBRARY grpc++ ${GRPC_OPTS} REQUIRED)
+    add_library(grpc++ UNKNOWN IMPORTED GLOBAL)
+    message(STATUS "Using grpc++: " ${GRPC_LIBRARY})
+    set_target_properties(grpc++ PROPERTIES IMPORTED_LOCATION ${GRPC_LIBRARY})
+    if (ENABLE_GRPC_REFLECTION)
+      find_library(GRPC_REFLECTION_LIBRARY grpc++_reflection ${GRPC_OPTS} REQUIRED)
+      add_library(grpc++_reflection UNKNOWN IMPORTED GLOBAL)
+      set_target_properties(grpc++_reflection PROPERTIES IMPORTED_LOCATION ${GRPC_REFLECTION_LIBRARY})
+    endif()
+    find_library(PROTOBUF_LIBRARY protobuf ${PROTOBUF_OPTS} REQUIRED)
+    message(STATUS "Using protobuf: " ${PROTOBUF_LIBRARY})
+    add_library(protobuf UNKNOWN IMPORTED GLOBAL)
+    set_target_properties(protobuf PROPERTIES IMPORTED_LOCATION ${PROTOBUF_LIBRARY})
   endif()
-  find_library(PROTOBUF_LIBRARY protobuf $PROTOBUF_OPTS REQUIRED)
-  message(STATUS "Using protobuf: " ${PROTOBUF_LIBRARY})
-  add_library(protobuf UNKNOWN IMPORTED GLOBAL)
-  set_target_properties(protobuf PROPERTIES IMPORTED_LOCATION ${PROTOBUF_LIBRARY})
 endif()
 
 if (ENABLE_GRPC_REFLECTION)


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D127893.437293.patch
Type: text/x-patch
Size: 2677 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220615/2d38e3cc/attachment.bin>


More information about the llvm-commits mailing list