TODO epan/dissectors/asn1/kerberos/packet-kerberos-template.c new GSS flags
[wireshark-sm.git] / cmake / modules / FindCARES.cmake
blob5d005b50d4e4eacd3154ad8e8004cbba4e83ec9a
2 # - Find cares
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
21   NAMES ares.h
22   PATH_SUFFIXES
23         include
24   HINTS
25     "${CARES_INCLUDEDIR}"
26     "${CARES_HINTS}"
29 find_library( CARES_LIBRARY
30   NAMES cares libcares-2
31   PATH_SUFFIXES
32         lib64 lib
33   HINTS
34     "${CARES_LIBDIR}"
35     "${CARES_HINTS}"
38 # Try to retrieve version from header if found
39 # Adapted from https://stackoverflow.com/a/47084079/82195
40 if(CARES_INCLUDE_DIR)
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)
55 endif()
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)
64 IF(CARES_FOUND)
65   SET( CARES_LIBRARIES ${CARES_LIBRARY} )
66   SET( CARES_INCLUDE_DIRS ${CARES_INCLUDE_DIR} )
67   if (WIN32)
68     set ( CARES_DLL_DIR "${CARES_HINTS}/bin"
69       CACHE PATH "Path to C-Ares DLL"
70     )
71     file( GLOB _cares_dll RELATIVE "${CARES_DLL_DIR}"
72       "${CARES_DLL_DIR}/cares.dll"
73     )
74     set ( CARES_DLL ${_cares_dll}
75       CACHE FILEPATH "C-Ares DLL file name"
76     )
77     file( GLOB _cares_pdb RELATIVE "${CARES_DLL_DIR}"
78       "${CARES_DLL_DIR}/cares.pdb"
79     )
80     set ( CARES_PDB ${_cares_pdb}
81       CACHE FILEPATH "C-Ares PDB file name"
82     )
83     mark_as_advanced( CARES_DLL_DIR CARES_DLL CARES_PDB )
84   endif()
85 ELSE(CARES_FOUND)
86   SET( CARES_LIBRARIES )
87   SET( CARES_INCLUDE_DIRS )
88   SET( CARES_DLL_DIR )
89   SET( CARES_DLL )
90 ENDIF(CARES_FOUND)
92 MARK_AS_ADVANCED( CARES_LIBRARIES CARES_INCLUDE_DIRS )