quickjs-tart

quickjs-based runtime for wallet-core logic
Log | Files | Refs | README | LICENSE

FindCares.cmake (3730B)


      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_LIBRARY_DIRS`:  The c-ares library directories.
     37 # - `CARES_PC_REQUIRES`:   The c-ares pkg-config packages.
     38 # - `CARES_CFLAGS`:        Required compiler flags.
     39 # - `CARES_VERSION`:       Version of c-ares.
     40 
     41 set(CARES_PC_REQUIRES "libcares")
     42 
     43 if(CURL_USE_PKGCONFIG AND
     44    NOT DEFINED CARES_INCLUDE_DIR AND
     45    NOT DEFINED CARES_LIBRARY)
     46   find_package(PkgConfig QUIET)
     47   pkg_check_modules(CARES ${CARES_PC_REQUIRES})
     48 endif()
     49 
     50 if(CARES_FOUND)
     51   set(Cares_FOUND TRUE)
     52   string(REPLACE ";" " " CARES_CFLAGS "${CARES_CFLAGS}")
     53   message(STATUS "Found Cares (via pkg-config): ${CARES_INCLUDE_DIRS} (found version \"${CARES_VERSION}\")")
     54 else()
     55   find_path(CARES_INCLUDE_DIR NAMES "ares.h")
     56   find_library(CARES_LIBRARY NAMES ${CARES_NAMES} "cares")
     57 
     58   unset(CARES_VERSION CACHE)
     59   if(CARES_INCLUDE_DIR AND EXISTS "${CARES_INCLUDE_DIR}/ares_version.h")
     60     set(_version_regex1 "#[\t ]*define[\t ]+ARES_VERSION_MAJOR[\t ]+([0-9]+).*")
     61     set(_version_regex2 "#[\t ]*define[\t ]+ARES_VERSION_MINOR[\t ]+([0-9]+).*")
     62     set(_version_regex3 "#[\t ]*define[\t ]+ARES_VERSION_PATCH[\t ]+([0-9]+).*")
     63     file(STRINGS "${CARES_INCLUDE_DIR}/ares_version.h" _version_str1 REGEX "${_version_regex1}")
     64     file(STRINGS "${CARES_INCLUDE_DIR}/ares_version.h" _version_str2 REGEX "${_version_regex2}")
     65     file(STRINGS "${CARES_INCLUDE_DIR}/ares_version.h" _version_str3 REGEX "${_version_regex3}")
     66     string(REGEX REPLACE "${_version_regex1}" "\\1" _version_str1 "${_version_str1}")
     67     string(REGEX REPLACE "${_version_regex2}" "\\1" _version_str2 "${_version_str2}")
     68     string(REGEX REPLACE "${_version_regex3}" "\\1" _version_str3 "${_version_str3}")
     69     set(CARES_VERSION "${_version_str1}.${_version_str2}.${_version_str3}")
     70     unset(_version_regex1)
     71     unset(_version_regex2)
     72     unset(_version_regex3)
     73     unset(_version_str1)
     74     unset(_version_str2)
     75     unset(_version_str3)
     76   endif()
     77 
     78   include(FindPackageHandleStandardArgs)
     79   find_package_handle_standard_args(Cares
     80     REQUIRED_VARS
     81       CARES_INCLUDE_DIR
     82       CARES_LIBRARY
     83     VERSION_VAR
     84       CARES_VERSION
     85   )
     86 
     87   if(CARES_FOUND)
     88     set(CARES_INCLUDE_DIRS ${CARES_INCLUDE_DIR})
     89     set(CARES_LIBRARIES    ${CARES_LIBRARY})
     90   endif()
     91 
     92   mark_as_advanced(CARES_INCLUDE_DIR CARES_LIBRARY)
     93 endif()
     94 
     95 if(CARES_FOUND AND WIN32)
     96   list(APPEND CARES_LIBRARIES "iphlpapi")  # for if_indextoname and others
     97 endif()