TODO netlogon_user_flags_ntlmv2_enabled
[wireshark-sm.git] / cmake / modules / FindLIBSSH.cmake
blob31346a3979f56e8e90fe9092a777e7057ed1ffb8
1 # - Try to find LibSSH
2 # Once done this will define
4 #  LIBSSH_FOUND - system has LibSSH
5 #  LIBSSH_INCLUDE_DIRS - the LibSSH include directory
6 #  LIBSSH_LIBRARIES - Link these to use LibSSH
8 #  Copyright (c) 2009 Andreas Schneider <mail@cynapses.org>
9 #  Modified by Peter Wu <peter@lekensteyn.nl> to use standard
10 #  find_package(LIBSSH ...) without external module.
12 #  Redistribution and use is allowed according to the terms of the New
13 #  BSD license.
14 #  For details see the accompanying COPYING-CMAKE-SCRIPTS file.
17 if(LIBSSH_LIBRARIES AND LIBSSH_INCLUDE_DIRS)
18   # in cache already
19   set(LIBSSH_FOUND TRUE)
20 else ()
22   include(FindWSWinLibs)
23   FindWSWinLibs("libssh-.*" "LIBSSH_HINTS")
25   find_path(LIBSSH_INCLUDE_DIR
26     NAMES
27       libssh/libssh.h
28     HINTS
29       "${LIBSSH_HINTS}/include"
30     PATHS
31       /usr/include
32       /usr/local/include
33       /opt/local/include
34       /sw/include
35       ${CMAKE_INCLUDE_PATH}
36       ${CMAKE_INSTALL_PREFIX}/include
37   )
39   find_library(LIBSSH_LIBRARY
40     NAMES
41       ssh
42       libssh
43     HINTS
44       "${LIBSSH_HINTS}/lib"
45     PATHS
46       /usr/lib
47       /usr/local/lib
48       /opt/local/lib
49       /sw/lib
50       ${CMAKE_LIBRARY_PATH}
51       ${CMAKE_INSTALL_PREFIX}/lib
52   )
54   if(LIBSSH_INCLUDE_DIR AND LIBSSH_LIBRARY)
55     include(CheckSymbolExists)
57     set(LIBSSH_INCLUDE_DIRS
58       ${LIBSSH_INCLUDE_DIR}
59     )
60     set(LIBSSH_LIBRARIES
61       ${LIBSSH_LIBRARY}
62     )
64     # libssh >= 0.9.5 has libssh_version.h
65     set(_libssh_version_header "${LIBSSH_INCLUDE_DIR}/libssh/libssh_version.h")
66     if(NOT EXISTS "${_libssh_version_header}")
67         set(_libssh_version_header "${LIBSSH_INCLUDE_DIR}/libssh/libssh.h")
68     endif()
70     file(STRINGS "${_libssh_version_header}" LIBSSH_VERSION_MAJOR
71       REGEX "#define[ ]+LIBSSH_VERSION_MAJOR[ ]+[0-9]+")
72     # Older versions of libssh like libssh-0.2 have LIBSSH_VERSION but not LIBSSH_VERSION_MAJOR
73     if(LIBSSH_VERSION_MAJOR)
74       string(REGEX MATCH "[0-9]+" LIBSSH_VERSION_MAJOR ${LIBSSH_VERSION_MAJOR})
75       file(STRINGS "${_libssh_version_header}" LIBSSH_VERSION_MINOR
76         REGEX "#define[ ]+LIBSSH_VERSION_MINOR[ ]+[0-9]+")
77       string(REGEX MATCH "[0-9]+" LIBSSH_VERSION_MINOR ${LIBSSH_VERSION_MINOR})
78       file(STRINGS "${_libssh_version_header}" LIBSSH_VERSION_PATCH
79         REGEX "#define[ ]+LIBSSH_VERSION_MICRO[ ]+[0-9]+")
80       string(REGEX MATCH "[0-9]+" LIBSSH_VERSION_PATCH ${LIBSSH_VERSION_PATCH})
81       set(LIBSSH_VERSION ${LIBSSH_VERSION_MAJOR}.${LIBSSH_VERSION_MINOR}.${LIBSSH_VERSION_PATCH})
82     endif()
83   endif()
85   # handle the QUIETLY and REQUIRED arguments and set LIBSSH_FOUND to TRUE if
86   # all listed variables are TRUE and the requested version matches.
87   include(FindPackageHandleStandardArgs)
88   find_package_handle_standard_args(LIBSSH
89     REQUIRED_VARS   LIBSSH_LIBRARIES LIBSSH_INCLUDE_DIRS LIBSSH_VERSION
90     VERSION_VAR     LIBSSH_VERSION)
92   if(WIN32)
93     set(LIBSSH_DLL_DIR "${LIBSSH_HINTS}/bin"
94       CACHE PATH "Path to libssh DLLs"
95     )
96     file(GLOB _libssh_dlls RELATIVE "${LIBSSH_DLL_DIR}"
97       "${LIBSSH_DLL_DIR}/libssh.dll"
98     )
99     set(LIBSSH_DLLS ${_libssh_dlls}
100       # We're storing filenames only. Should we use STRING instead?
101       CACHE FILEPATH "libssh DLL file name"
102     )
103     mark_as_advanced(LIBSSH_DLL_DIR LIBSSH_DLL)
104   endif()
106   # show the LIBSSH_INCLUDE_DIRS and LIBSSH_LIBRARIES variables only in the advanced view
107   mark_as_advanced(LIBSSH_INCLUDE_DIRS LIBSSH_LIBRARIES)
109 endif()