[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 13:24:55 PDT 2022
akyrtzi updated this revision to Diff 437315.
akyrtzi added a comment.
Use `target_include_directories()` to add include search paths only for the targets the depend on `gRPC`
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D127893/new/
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
@@ -48,6 +48,7 @@
# the system path.
set(GRPC_OPTS "")
set(PROTOBUF_OPTS "")
+ set(GRPC_INCLUDE_PATHS "")
if (${APPLE})
find_program(HOMEBREW brew)
# If Homebrew is not found, the user might have installed libraries
@@ -61,31 +62,41 @@
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")
- include_directories(${GRPC_HOMEBREW_PATH}/include)
+ list(APPEND GRPC_INCLUDE_PATHS ${GRPC_HOMEBREW_PATH}/include)
list(APPEND GRPC_OPTS PATHS ${GRPC_HOMEBREW_PATH}/lib NO_DEFAULT_PATH)
endif()
if (PROTOBUF_HOMEBREW_RETURN_CODE EQUAL "0")
- include_directories(${PROTOBUF_HOMEBREW_PATH}/include)
+ list(APPEND GRPC_INCLUDE_PATHS ${PROTOBUF_HOMEBREW_PATH}/include)
list(APPEND PROTOBUF_OPTS PATHS ${PROTOBUF_HOMEBREW_PATH}/lib NO_DEFAULT_PATH)
endif()
+ if (ABSL_HOMEBREW_RETURN_CODE EQUAL "0")
+ list(APPEND GRPC_INCLUDE_PATHS ${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})
+ target_include_directories(grpc++ INTERFACE ${GRPC_INCLUDE_PATHS})
+ 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.437315.patch
Type: text/x-patch
Size: 3333 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220615/e0d7c54e/attachment.bin>
More information about the llvm-commits
mailing list