1# Copyright 2017 gRPC authors. 2# 3# Licensed under the Apache License, Version 2.0 (the "License"); 4# you may not use this file except in compliance with the License. 5# You may obtain a copy of the License at 6# 7# http://www.apache.org/licenses/LICENSE-2.0 8# 9# Unless required by applicable law or agreed to in writing, software 10# distributed under the License is distributed on an "AS IS" BASIS, 11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12# See the License for the specific language governing permissions and 13# limitations under the License. 14 15if("${gRPC_CARES_PROVIDER}" STREQUAL "module") 16 if(NOT CARES_ROOT_DIR) 17 set(CARES_ROOT_DIR ${CMAKE_CURRENT_SOURCE_DIR}/third_party/cares/cares) 18 endif() 19 set(CARES_SHARED OFF CACHE BOOL "disable shared library") 20 set(CARES_STATIC ON CACHE BOOL "link cares statically") 21 add_subdirectory(${CARES_ROOT_DIR} third_party/cares/cares) 22 23 if(TARGET c-ares) 24 set(_gRPC_CARES_LIBRARIES c-ares) 25 set(_gRPC_CARES_INCLUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/third_party/cares/cares" "${CMAKE_CURRENT_BINARY_DIR}/third_party/cares/cares") 26 endif() 27 28 if(gRPC_INSTALL) 29 message(WARNING "gRPC_INSTALL will be forced to FALSE because gRPC_CARES_PROVIDER is \"module\"") 30 set(gRPC_INSTALL FALSE) 31 endif() 32elseif("${gRPC_CARES_PROVIDER}" STREQUAL "package") 33 # Use "CONFIG" as there is no built-in cmake module for c-ares. 34 find_package(c-ares REQUIRED CONFIG) 35 if(TARGET c-ares::cares) 36 set(_gRPC_CARES_LIBRARIES c-ares::cares) 37 set(_gRPC_CARES_INCLUDE_DIR ${c-ares_INCLUDE_DIR}) 38 endif() 39 set(_gRPC_FIND_CARES "if(NOT c-ares_FOUND)\n find_package(c-ares CONFIG)\nendif()") 40endif() 41