blob: bd57c45712c062a4d542d4012cb92e530931d6e3 [file] [log] [blame]
Jan Tattermuschf38b1522017-12-19 14:05:41 -08001# 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")
Hao Chenb89d5832020-05-04 23:00:24 +000021 add_subdirectory(${CARES_ROOT_DIR} third_party/cares/cares)
Jan Tattermusch586f7192018-01-16 17:57:17 +010022
Jan Tattermuschf38b1522017-12-19 14:05:41 -080023 if(TARGET c-ares)
24 set(_gRPC_CARES_LIBRARIES c-ares)
Jan Tattermusch586f7192018-01-16 17:57:17 +010025 set(_gRPC_CARES_INCLUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/third_party/cares/cares" "${CMAKE_CURRENT_BINARY_DIR}/third_party/cares/cares")
Jan Tattermuschf38b1522017-12-19 14:05:41 -080026 endif()
Jan Tattermusch586f7192018-01-16 17:57:17 +010027
Jan Tattermuschf38b1522017-12-19 14:05:41 -080028 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")
Jan Tattermusch6750d422018-02-07 15:57:23 +010033 # Use "CONFIG" as there is no built-in cmake module for c-ares.
Jan Tattermuschf38b1522017-12-19 14:05:41 -080034 find_package(c-ares REQUIRED CONFIG)
35 if(TARGET c-ares::cares)
36 set(_gRPC_CARES_LIBRARIES c-ares::cares)
Jan Tattermusch586f7192018-01-16 17:57:17 +010037 set(_gRPC_CARES_INCLUDE_DIR ${c-ares_INCLUDE_DIR})
Jan Tattermuschf38b1522017-12-19 14:05:41 -080038 endif()
39 set(_gRPC_FIND_CARES "if(NOT c-ares_FOUND)\n find_package(c-ares CONFIG)\nendif()")
40endif()