cares.cmake 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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. if(gRPC_CARES_PROVIDER STREQUAL "module")
  15. if(NOT CARES_ROOT_DIR)
  16. set(CARES_ROOT_DIR ${CMAKE_CURRENT_SOURCE_DIR}/third_party/cares/cares)
  17. endif()
  18. set(CARES_SHARED OFF CACHE BOOL "disable shared library")
  19. set(CARES_STATIC ON CACHE BOOL "link cares statically")
  20. if(gRPC_BACKWARDS_COMPATIBILITY_MODE)
  21. # See https://github.com/grpc/grpc/issues/17255
  22. set(HAVE_LIBNSL OFF CACHE BOOL "avoid cares dependency on libnsl")
  23. endif()
  24. add_subdirectory("${CARES_ROOT_DIR}" third_party/cares/cares)
  25. if(TARGET c-ares)
  26. set(_gRPC_CARES_LIBRARIES c-ares)
  27. if(gRPC_INSTALL AND _gRPC_INSTALL_SUPPORTED_FROM_MODULE)
  28. install(TARGETS c-ares EXPORT gRPCTargets
  29. RUNTIME DESTINATION ${gRPC_INSTALL_BINDIR}
  30. LIBRARY DESTINATION ${gRPC_INSTALL_LIBDIR}
  31. ARCHIVE DESTINATION ${gRPC_INSTALL_LIBDIR})
  32. endif()
  33. endif()
  34. if(gRPC_INSTALL AND NOT _gRPC_INSTALL_SUPPORTED_FROM_MODULE)
  35. 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.")
  36. set(gRPC_INSTALL FALSE)
  37. endif()
  38. elseif(gRPC_CARES_PROVIDER STREQUAL "package")
  39. find_package(c-ares 1.13.0 REQUIRED)
  40. if(TARGET c-ares::cares)
  41. set(_gRPC_CARES_LIBRARIES c-ares::cares)
  42. endif()
  43. set(_gRPC_FIND_CARES "if(NOT c-ares_FOUND)\n find_package(c-ares)\nendif()")
  44. endif()