3 # Find the native CARES includes and library
5 # CARES_INCLUDE_DIRS - where to find cares.h, etc.
6 # CARES_LIBRARIES - List of libraries when using cares.
7 # CARES_FOUND - True if cares found.
8 # CARES_DLL_DIR - (Windows) Path to the c-ares DLL.
9 # CARES_DLL - (Windows) Name of the c-ares DLL.
12 IF (CARES_INCLUDE_DIRS)
13 # Already in cache, be silent
14 SET(CARES_FIND_QUIETLY TRUE)
15 ENDIF (CARES_INCLUDE_DIRS)
17 INCLUDE(FindWSWinLibs)
18 FindWSWinLibs("c-ares-.*" "CARES_HINTS")
20 find_path( CARES_INCLUDE_DIR
29 find_library( CARES_LIBRARY
30 NAMES cares libcares-2
38 # Try to retrieve version from header if found
39 # Adapted from https://stackoverflow.com/a/47084079/82195
41 file(READ "${CARES_INCLUDE_DIR}/ares_version.h" _ares_version_h)
43 string(REGEX MATCH "#[\t ]*define[ \t]+ARES_VERSION_MAJOR[ \t]+([0-9]+)" _ ${_ares_version_h})
44 set(_ares_version_major ${CMAKE_MATCH_1})
45 string(REGEX MATCH "#[\t ]*define[ \t]+ARES_VERSION_MINOR[ \t]+([0-9]+)" _ ${_ares_version_h})
46 set(_ares_version_minor ${CMAKE_MATCH_1})
47 string(REGEX MATCH "#[\t ]*define[ \t]+ARES_VERSION_PATCH[ \t]+([0-9]+)" _ ${_ares_version_h})
48 set(_ares_version_patch ${CMAKE_MATCH_1})
49 set(CARES_VERSION ${_ares_version_major}.${_ares_version_minor}.${_ares_version_patch})
51 unset(_ares_version_h)
52 unset(_ares_version_major)
53 unset(_ares_version_minor)
54 unset(_ares_version_patch)
57 # handle the QUIETLY and REQUIRED arguments and set CARES_FOUND to TRUE if
58 # all listed variables are TRUE
59 INCLUDE(FindPackageHandleStandardArgs)
60 FIND_PACKAGE_HANDLE_STANDARD_ARGS(CARES
61 REQUIRED_VARS CARES_LIBRARY CARES_INCLUDE_DIR
62 VERSION_VAR CARES_VERSION)
65 SET( CARES_LIBRARIES ${CARES_LIBRARY} )
66 SET( CARES_INCLUDE_DIRS ${CARES_INCLUDE_DIR} )
68 set ( CARES_DLL_DIR "${CARES_HINTS}/bin"
69 CACHE PATH "Path to C-Ares DLL"
71 file( GLOB _cares_dll RELATIVE "${CARES_DLL_DIR}"
72 "${CARES_DLL_DIR}/cares.dll"
74 set ( CARES_DLL ${_cares_dll}
75 CACHE FILEPATH "C-Ares DLL file name"
77 file( GLOB _cares_pdb RELATIVE "${CARES_DLL_DIR}"
78 "${CARES_DLL_DIR}/cares.pdb"
80 set ( CARES_PDB ${_cares_pdb}
81 CACHE FILEPATH "C-Ares PDB file name"
83 mark_as_advanced( CARES_DLL_DIR CARES_DLL CARES_PDB )
86 SET( CARES_LIBRARIES )
87 SET( CARES_INCLUDE_DIRS )
92 MARK_AS_ADVANCED( CARES_LIBRARIES CARES_INCLUDE_DIRS )