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
14 # For details see the accompanying COPYING-CMAKE-SCRIPTS file.
17 if(LIBSSH_LIBRARIES AND LIBSSH_INCLUDE_DIRS)
19 set(LIBSSH_FOUND TRUE)
22 include(FindWSWinLibs)
23 FindWSWinLibs("libssh-.*" "LIBSSH_HINTS")
25 find_path(LIBSSH_INCLUDE_DIR
29 "${LIBSSH_HINTS}/include"
36 ${CMAKE_INSTALL_PREFIX}/include
39 find_library(LIBSSH_LIBRARY
51 ${CMAKE_INSTALL_PREFIX}/lib
54 if(LIBSSH_INCLUDE_DIR AND LIBSSH_LIBRARY)
55 include(CheckSymbolExists)
57 set(LIBSSH_INCLUDE_DIRS
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")
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})
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)
93 set(LIBSSH_DLL_DIR "${LIBSSH_HINTS}/bin"
94 CACHE PATH "Path to libssh DLLs"
96 file(GLOB _libssh_dlls RELATIVE "${LIBSSH_DLL_DIR}"
97 "${LIBSSH_DLL_DIR}/libssh.dll"
99 set(LIBSSH_DLLS ${_libssh_dlls}
100 # We're storing filenames only. Should we use STRING instead?
101 CACHE FILEPATH "libssh DLL file name"
103 mark_as_advanced(LIBSSH_DLL_DIR LIBSSH_DLL)
106 # show the LIBSSH_INCLUDE_DIRS and LIBSSH_LIBRARIES variables only in the advanced view
107 mark_as_advanced(LIBSSH_INCLUDE_DIRS LIBSSH_LIBRARIES)