aboutsummaryrefslogtreecommitdiff
path: root/cmake/modules/FindSSH.cmake
blob: b88e769fe5021ea806b873e971294f20375b3550 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#.rst:
# FindSSH
# -------
# Finds the SSH library
#
# This will define the following variables::
#
# SSH_FOUND - system has SSH
# SSH_INCLUDE_DIRS - the SSH include directory
# SSH_LIBRARIES - the SSH libraries
# SSH_DEFINITIONS - the SSH definitions
#
# and the following imported targets::
#
#   SSH::SSH   - The SSH library

if(PKG_CONFIG_FOUND)
  pkg_check_modules(PC_SSH libssh>=0.6 QUIET)
endif()

find_path(SSH_INCLUDE_DIR NAMES libssh/libssh.h
                          PATHS ${PC_SSH_INCLUDEDIR})
find_library(SSH_LIBRARY NAMES ssh
                         PATHS ${PC_SSH_LIBDIR})

set(SSH_VERSION ${PC_SSH_VERSION})

include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(SSH
                                  REQUIRED_VARS SSH_LIBRARY SSH_INCLUDE_DIR
                                  VERSION_VAR SSH_VERSION)

if(SSH_FOUND)
  set(SSH_LIBRARIES ${SSH_LIBRARY})
  set(SSH_INCLUDE_DIRS ${SSH_INCLUDE_DIR})
  set(SSH_DEFINITIONS -DHAS_FILESYSTEM_SFTP=1)

  if(NOT TARGET SSH::SSH)
    add_library(SSH::SSH UNKNOWN IMPORTED)
    set_target_properties(SSH::SSH PROPERTIES
                                   IMPORTED_LOCATION "${SSH_LIBRARY}"
                                   INTERFACE_INCLUDE_DIRECTORIES "${SSH_INCLUDE_DIR}"
                                   INTERFACE_COMPILE_DEFINITIONS HAS_FILESYSTEM_SFTP=1)
  endif()
endif()

mark_as_advanced(SSH_INCLUDE_DIR SSH_LIBRARY)