diff --git a/llvm/cmake/modules/FindGRPC.cmake b/llvm/cmake/modules/FindGRPC.cmake --- a/llvm/cmake/modules/FindGRPC.cmake +++ b/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)