| 1 |
#*************************************************************************** |
| 2 |
# _ _ ____ _ |
| 3 |
# Project ___| | | | _ \| | |
| 4 |
# / __| | | | |_) | | |
| 5 |
# | (__| |_| | _ <| |___ |
| 6 |
# \___|\___/|_| \_\_____| |
| 7 |
# |
| 8 |
# Copyright (C) Daniel Stenberg, <[email protected]>, et al. |
| 9 |
# |
| 10 |
# This software is licensed as described in the file COPYING, which |
| 11 |
# you should have received as part of this distribution. The terms |
| 12 |
# are also available at https://curl.se/docs/copyright.html. |
| 13 |
# |
| 14 |
# You may opt to use, copy, modify, merge, publish, distribute and/or sell |
| 15 |
# copies of the Software, and permit persons to whom the Software is |
| 16 |
# furnished to do so, under the terms of the COPYING file. |
| 17 |
# |
| 18 |
# This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY |
| 19 |
# KIND, either express or implied. |
| 20 |
# |
| 21 |
# SPDX-License-Identifier: curl |
| 22 |
# |
| 23 |
########################################################################### |
| 24 |
# Find the libssh2 library |
| 25 |
# |
| 26 |
# Input variables: |
| 27 |
# |
| 28 |
# - `LIBSSH2_INCLUDE_DIR`: The libssh2 include directory. |
| 29 |
# - `LIBSSH2_LIBRARY`: Path to `libssh2` library. |
| 30 |
# |
| 31 |
# Result variables: |
| 32 |
# |
| 33 |
# - `LIBSSH2_FOUND`: System has libssh2. |
| 34 |
# - `LIBSSH2_INCLUDE_DIRS`: The libssh2 include directories. |
| 35 |
# - `LIBSSH2_LIBRARIES`: The libssh2 library names. |
| 36 |
# - `LIBSSH2_LIBRARY_DIRS`: The libssh2 library directories. |
| 37 |
# - `LIBSSH2_PC_REQUIRES`: The libssh2 pkg-config packages. |
| 38 |
# - `LIBSSH2_CFLAGS`: Required compiler flags. |
| 39 |
# - `LIBSSH2_VERSION`: Version of libssh2. |
| 40 |
|
| 41 |
set(LIBSSH2_PC_REQUIRES "libssh2") |
| 42 |
|
| 43 |
if(CURL_USE_PKGCONFIG AND |
| 44 |
NOT DEFINED LIBSSH2_INCLUDE_DIR AND |
| 45 |
NOT DEFINED LIBSSH2_LIBRARY) |
| 46 |
find_package(PkgConfig QUIET) |
| 47 |
pkg_check_modules(LIBSSH2 ${LIBSSH2_PC_REQUIRES}) |
| 48 |
endif() |
| 49 |
|
| 50 |
if(LIBSSH2_FOUND AND LIBSSH2_INCLUDE_DIRS) |
| 51 |
set(Libssh2_FOUND TRUE) |
| 52 |
string(REPLACE ";" " " LIBSSH2_CFLAGS "${LIBSSH2_CFLAGS}") |
| 53 |
message(STATUS "Found Libssh2 (via pkg-config): ${LIBSSH2_INCLUDE_DIRS} (found version \"${LIBSSH2_VERSION}\")") |
| 54 |
else() |
| 55 |
find_path(LIBSSH2_INCLUDE_DIR NAMES "libssh2.h") |
| 56 |
find_library(LIBSSH2_LIBRARY NAMES "ssh2" "libssh2") |
| 57 |
|
| 58 |
unset(LIBSSH2_VERSION CACHE) |
| 59 |
if(LIBSSH2_INCLUDE_DIR AND EXISTS "${LIBSSH2_INCLUDE_DIR}/libssh2.h") |
| 60 |
set(_version_regex "#[\t ]*define[\t ]+LIBSSH2_VERSION[\t ]+\"([^\"]*)\"") |
| 61 |
file(STRINGS "${LIBSSH2_INCLUDE_DIR}/libssh2.h" _version_str REGEX "${_version_regex}") |
| 62 |
string(REGEX REPLACE "${_version_regex}" "\\1" _version_str "${_version_str}") |
| 63 |
set(LIBSSH2_VERSION "${_version_str}") |
| 64 |
unset(_version_regex) |
| 65 |
unset(_version_str) |
| 66 |
endif() |
| 67 |
|
| 68 |
include(FindPackageHandleStandardArgs) |
| 69 |
find_package_handle_standard_args(Libssh2 |
| 70 |
REQUIRED_VARS |
| 71 |
LIBSSH2_INCLUDE_DIR |
| 72 |
LIBSSH2_LIBRARY |
| 73 |
VERSION_VAR |
| 74 |
LIBSSH2_VERSION |
| 75 |
) |
| 76 |
|
| 77 |
if(LIBSSH2_FOUND) |
| 78 |
set(LIBSSH2_INCLUDE_DIRS ${LIBSSH2_INCLUDE_DIR}) |
| 79 |
set(LIBSSH2_LIBRARIES ${LIBSSH2_LIBRARY}) |
| 80 |
endif() |
| 81 |
|
| 82 |
mark_as_advanced(LIBSSH2_INCLUDE_DIR LIBSSH2_LIBRARY) |
| 83 |
endif() |