2
0

FindCares.cmake 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. #***************************************************************************
  2. # _ _ ____ _
  3. # Project ___| | | | _ \| |
  4. # / __| | | | |_) | |
  5. # | (__| |_| | _ <| |___
  6. # \___|\___/|_| \_\_____|
  7. #
  8. # Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
  9. #
  10. # This software is licensed as described in the file COPYING, which
  11. # you should have received as part of this distribution. The terms
  12. # are also available at https://curl.se/docs/copyright.html.
  13. #
  14. # You may opt to use, copy, modify, merge, publish, distribute and/or sell
  15. # copies of the Software, and permit persons to whom the Software is
  16. # furnished to do so, under the terms of the COPYING file.
  17. #
  18. # This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
  19. # KIND, either express or implied.
  20. #
  21. # SPDX-License-Identifier: curl
  22. #
  23. ###########################################################################
  24. # Find the c-ares library
  25. #
  26. # Input variables:
  27. #
  28. # - `CARES_INCLUDE_DIR`: The c-ares include directory.
  29. # - `CARES_LIBRARY`: Path to `cares` library.
  30. #
  31. # Result variables:
  32. #
  33. # - `CARES_FOUND`: System has c-ares.
  34. # - `CARES_INCLUDE_DIRS`: The c-ares include directories.
  35. # - `CARES_LIBRARIES`: The c-ares library names.
  36. # - `CARES_VERSION`: Version of c-ares.
  37. if(CURL_USE_PKGCONFIG)
  38. find_package(PkgConfig QUIET)
  39. pkg_check_modules(PC_CARES "libcares")
  40. endif()
  41. find_path(CARES_INCLUDE_DIR NAMES "ares.h"
  42. HINTS
  43. ${PC_CARES_INCLUDEDIR}
  44. ${PC_CARES_INCLUDE_DIRS}
  45. )
  46. find_library(CARES_LIBRARY NAMES ${CARES_NAMES} "cares"
  47. HINTS
  48. ${PC_CARES_LIBDIR}
  49. ${PC_CARES_LIBRARY_DIRS}
  50. )
  51. if(PC_CARES_VERSION)
  52. set(CARES_VERSION ${PC_CARES_VERSION})
  53. elseif(CARES_INCLUDE_DIR AND EXISTS "${CARES_INCLUDE_DIR}/ares_version.h")
  54. set(_version_regex1 "#[\t ]*define[\t ]+ARES_VERSION_MAJOR[\t ]+([0-9]+).*")
  55. set(_version_regex2 "#[\t ]*define[\t ]+ARES_VERSION_MINOR[\t ]+([0-9]+).*")
  56. set(_version_regex3 "#[\t ]*define[\t ]+ARES_VERSION_PATCH[\t ]+([0-9]+).*")
  57. file(STRINGS "${CARES_INCLUDE_DIR}/ares_version.h" _version_str1 REGEX "${_version_regex1}")
  58. file(STRINGS "${CARES_INCLUDE_DIR}/ares_version.h" _version_str2 REGEX "${_version_regex2}")
  59. file(STRINGS "${CARES_INCLUDE_DIR}/ares_version.h" _version_str3 REGEX "${_version_regex3}")
  60. string(REGEX REPLACE "${_version_regex1}" "\\1" _version_str1 "${_version_str1}")
  61. string(REGEX REPLACE "${_version_regex2}" "\\1" _version_str2 "${_version_str2}")
  62. string(REGEX REPLACE "${_version_regex3}" "\\1" _version_str3 "${_version_str3}")
  63. set(CARES_VERSION "${_version_str1}.${_version_str2}.${_version_str3}")
  64. unset(_version_regex1)
  65. unset(_version_regex2)
  66. unset(_version_regex3)
  67. unset(_version_str1)
  68. unset(_version_str2)
  69. unset(_version_str3)
  70. endif()
  71. include(FindPackageHandleStandardArgs)
  72. find_package_handle_standard_args(Cares
  73. REQUIRED_VARS
  74. CARES_INCLUDE_DIR
  75. CARES_LIBRARY
  76. VERSION_VAR
  77. CARES_VERSION
  78. )
  79. if(CARES_FOUND)
  80. set(CARES_INCLUDE_DIRS ${CARES_INCLUDE_DIR})
  81. set(CARES_LIBRARIES ${CARES_LIBRARY})
  82. endif()
  83. mark_as_advanced(CARES_INCLUDE_DIR CARES_LIBRARY)