Jan Tattermusch | f38b152 | 2017-12-19 14:05:41 -0800 | [diff] [blame] | 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 | |
| 15 | if("${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") |
Hao Chen | 00c1189 | 2020-05-04 13:17:43 -0700 | [diff] [blame] | 21 | add_subdirectory(${CARES_ROOT_DIR} third_party/cares/cares) |
Jan Tattermusch | 586f719 | 2018-01-16 17:57:17 +0100 | [diff] [blame] | 22 | |
Jan Tattermusch | f38b152 | 2017-12-19 14:05:41 -0800 | [diff] [blame] | 23 | if(TARGET c-ares) |
| 24 | set(_gRPC_CARES_LIBRARIES c-ares) |
Jan Tattermusch | 586f719 | 2018-01-16 17:57:17 +0100 | [diff] [blame] | 25 | set(_gRPC_CARES_INCLUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/third_party/cares/cares" "${CMAKE_CURRENT_BINARY_DIR}/third_party/cares/cares") |
Jan Tattermusch | f38b152 | 2017-12-19 14:05:41 -0800 | [diff] [blame] | 26 | endif() |
Jan Tattermusch | 586f719 | 2018-01-16 17:57:17 +0100 | [diff] [blame] | 27 | |
Jan Tattermusch | f38b152 | 2017-12-19 14:05:41 -0800 | [diff] [blame] | 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() |
| 32 | elseif("${gRPC_CARES_PROVIDER}" STREQUAL "package") |
Jan Tattermusch | 6750d42 | 2018-02-07 15:57:23 +0100 | [diff] [blame] | 33 | # Use "CONFIG" as there is no built-in cmake module for c-ares. |
Jan Tattermusch | f38b152 | 2017-12-19 14:05:41 -0800 | [diff] [blame] | 34 | find_package(c-ares REQUIRED CONFIG) |
| 35 | if(TARGET c-ares::cares) |
| 36 | set(_gRPC_CARES_LIBRARIES c-ares::cares) |
Jan Tattermusch | 586f719 | 2018-01-16 17:57:17 +0100 | [diff] [blame] | 37 | set(_gRPC_CARES_INCLUDE_DIR ${c-ares_INCLUDE_DIR}) |
Jan Tattermusch | f38b152 | 2017-12-19 14:05:41 -0800 | [diff] [blame] | 38 | endif() |
| 39 | set(_gRPC_FIND_CARES "if(NOT c-ares_FOUND)\n find_package(c-ares CONFIG)\nendif()") |
| 40 | endif() |