Imported Upstream version 1.27.0
[platform/upstream/grpc.git] / cmake / cares.cmake
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")
21   if(gRPC_BACKWARDS_COMPATIBILITY_MODE)
22     # See https://github.com/grpc/grpc/issues/17255
23     set(HAVE_LIBNSL OFF CACHE BOOL "avoid cares dependency on libnsl")
24   endif()
25   add_subdirectory("${CARES_ROOT_DIR}" third_party/cares/cares)
26
27   if(TARGET c-ares)
28     set(_gRPC_CARES_LIBRARIES c-ares)
29     if(gRPC_INSTALL AND _gRPC_INSTALL_SUPPORTED_FROM_MODULE)
30       install(TARGETS c-ares EXPORT gRPCTargets
31         RUNTIME DESTINATION ${gRPC_INSTALL_BINDIR}
32         LIBRARY DESTINATION ${gRPC_INSTALL_LIBDIR}
33         ARCHIVE DESTINATION ${gRPC_INSTALL_LIBDIR})
34     endif()
35   endif()
36
37   if(gRPC_INSTALL AND NOT _gRPC_INSTALL_SUPPORTED_FROM_MODULE)
38     message(WARNING "gRPC_INSTALL will be forced to FALSE because gRPC_CARES_PROVIDER is \"module\" and CMake version (${CMAKE_VERSION}) is less than 3.13.")
39     set(gRPC_INSTALL FALSE)
40   endif()
41 elseif(gRPC_CARES_PROVIDER STREQUAL "package")
42   find_package(c-ares 1.13.0 REQUIRED)
43   if(TARGET c-ares::cares)
44     set(_gRPC_CARES_LIBRARIES c-ares::cares)
45   endif()
46   set(_gRPC_FIND_CARES "if(NOT c-ares_FOUND)\n  find_package(c-ares)\nendif()")
47 endif()