Radek Krejci | 4f2d40d | 2015-10-08 12:55:01 +0200 | [diff] [blame] | 1 | # - Try to find LibSSH |
| 2 | # Once done this will define |
| 3 | # |
| 4 | # LIBSSH_FOUND - system has LibSSH |
| 5 | # LIBSSH_INCLUDE_DIRS - the LibSSH include directory |
Michal Vasko | 75441e7 | 2017-09-27 13:57:00 +0200 | [diff] [blame] | 6 | # LIBSSH_LIBRARY_DIR - the LibSSH library directory |
Radek Krejci | 4f2d40d | 2015-10-08 12:55:01 +0200 | [diff] [blame] | 7 | # |
| 8 | # Copyright (c) 2009 Andreas Schneider <asn@cryptomilk.org> |
| 9 | # |
| 10 | # Redistribution and use in source and binary forms, with or without |
| 11 | # modification, are permitted provided that the following conditions |
| 12 | # are met: |
| 13 | # |
| 14 | # 1. Redistributions of source code must retain the copyright |
| 15 | # notice, this list of conditions and the following disclaimer. |
| 16 | # 2. Redistributions in binary form must reproduce the copyright |
| 17 | # notice, this list of conditions and the following disclaimer in the |
| 18 | # documentation and/or other materials provided with the distribution. |
Michal Vasko | 75441e7 | 2017-09-27 13:57:00 +0200 | [diff] [blame] | 19 | # 3. The name of the author may not be used to endorse or promote products |
Radek Krejci | 4f2d40d | 2015-10-08 12:55:01 +0200 | [diff] [blame] | 20 | # derived from this software without specific prior written permission. |
| 21 | # |
| 22 | # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
| 23 | # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
| 24 | # OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
| 25 | # IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
| 26 | # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
| 27 | # NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 28 | # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 29 | # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 30 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
| 31 | # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 32 | # |
| 33 | |
Michal Vasko | 75441e7 | 2017-09-27 13:57:00 +0200 | [diff] [blame] | 34 | if (LIBSSH_LIBRARY_DIR AND LIBSSH_INCLUDE_DIRS) |
Radek Krejci | 4f2d40d | 2015-10-08 12:55:01 +0200 | [diff] [blame] | 35 | # in cache already |
| 36 | set(LIBSSH_FOUND TRUE) |
Michal Vasko | 75441e7 | 2017-09-27 13:57:00 +0200 | [diff] [blame] | 37 | else (LIBSSH_LIBRARY_DIR AND LIBSSH_INCLUDE_DIRS) |
Radek Krejci | 4f2d40d | 2015-10-08 12:55:01 +0200 | [diff] [blame] | 38 | |
| 39 | find_path(LIBSSH_INCLUDE_DIR |
| 40 | NAMES |
| 41 | libssh/libssh.h |
| 42 | PATHS |
| 43 | /usr/include |
| 44 | /usr/local/include |
| 45 | /opt/local/include |
| 46 | /sw/include |
| 47 | ${CMAKE_INCLUDE_PATH} |
| 48 | ${CMAKE_INSTALL_PREFIX}/include |
| 49 | ) |
Michal Vasko | 75441e7 | 2017-09-27 13:57:00 +0200 | [diff] [blame] | 50 | |
Radek Krejci | 4f2d40d | 2015-10-08 12:55:01 +0200 | [diff] [blame] | 51 | find_library(SSH_LIBRARY |
| 52 | NAMES |
Michal Vasko | 75441e7 | 2017-09-27 13:57:00 +0200 | [diff] [blame] | 53 | ssh.so |
| 54 | libssh.so |
Radek Krejci | 4f2d40d | 2015-10-08 12:55:01 +0200 | [diff] [blame] | 55 | PATHS |
| 56 | /usr/lib |
| 57 | /usr/local/lib |
| 58 | /opt/local/lib |
| 59 | /sw/lib |
| 60 | ${CMAKE_LIBRARY_PATH} |
| 61 | ${CMAKE_INSTALL_PREFIX}/lib |
| 62 | ) |
| 63 | |
| 64 | if (LIBSSH_INCLUDE_DIR AND SSH_LIBRARY) |
| 65 | set(SSH_FOUND TRUE) |
| 66 | endif (LIBSSH_INCLUDE_DIR AND SSH_LIBRARY) |
| 67 | |
| 68 | set(LIBSSH_INCLUDE_DIRS |
| 69 | ${LIBSSH_INCLUDE_DIR} |
| 70 | ) |
| 71 | |
| 72 | if (SSH_FOUND) |
Chaitanya Tata | f2a28fc | 2019-04-23 13:46:40 +0530 | [diff] [blame] | 73 | string(REPLACE "libssh.so" "" |
Michal Vasko | 75441e7 | 2017-09-27 13:57:00 +0200 | [diff] [blame] | 74 | LIBSSH_LIBRARY_DIR |
Radek Krejci | 4f2d40d | 2015-10-08 12:55:01 +0200 | [diff] [blame] | 75 | ${SSH_LIBRARY} |
| 76 | ) |
Chaitanya Tata | f2a28fc | 2019-04-23 13:46:40 +0530 | [diff] [blame] | 77 | string(REPLACE "ssh.so" "" |
Michal Vasko | 75441e7 | 2017-09-27 13:57:00 +0200 | [diff] [blame] | 78 | LIBSSH_LIBRARY_DIR |
| 79 | ${LIBSSH_LIBRARY_DIR} |
| 80 | ) |
Radek Krejci | 4f2d40d | 2015-10-08 12:55:01 +0200 | [diff] [blame] | 81 | |
| 82 | if (LibSSH_FIND_VERSION) |
| 83 | file(STRINGS ${LIBSSH_INCLUDE_DIR}/libssh/libssh.h LIBSSH_VERSION_MAJOR |
| 84 | REGEX "#define[ ]+LIBSSH_VERSION_MAJOR[ ]+[0-9]+") |
| 85 | # Older versions of libssh like libssh-0.2 have LIBSSH_VERSION but not LIBSSH_VERSION_MAJOR |
| 86 | if (LIBSSH_VERSION_MAJOR) |
| 87 | string(REGEX MATCH "[0-9]+" LIBSSH_VERSION_MAJOR ${LIBSSH_VERSION_MAJOR}) |
| 88 | file(STRINGS ${LIBSSH_INCLUDE_DIR}/libssh/libssh.h LIBSSH_VERSION_MINOR |
| 89 | REGEX "#define[ ]+LIBSSH_VERSION_MINOR[ ]+[0-9]+") |
| 90 | string(REGEX MATCH "[0-9]+" LIBSSH_VERSION_MINOR ${LIBSSH_VERSION_MINOR}) |
| 91 | file(STRINGS ${LIBSSH_INCLUDE_DIR}/libssh/libssh.h LIBSSH_VERSION_PATCH |
| 92 | REGEX "#define[ ]+LIBSSH_VERSION_MICRO[ ]+[0-9]+") |
| 93 | string(REGEX MATCH "[0-9]+" LIBSSH_VERSION_PATCH ${LIBSSH_VERSION_PATCH}) |
| 94 | |
| 95 | set(LibSSH_VERSION ${LIBSSH_VERSION_MAJOR}.${LIBSSH_VERSION_MINOR}.${LIBSSH_VERSION_PATCH}) |
| 96 | |
| 97 | include(FindPackageVersionCheck) |
| 98 | find_package_version_check(LibSSH DEFAULT_MSG) |
| 99 | else (LIBSSH_VERSION_MAJOR) |
| 100 | message(STATUS "LIBSSH_VERSION_MAJOR not found in ${LIBSSH_INCLUDE_DIR}/libssh/libssh.h, assuming libssh is too old") |
| 101 | set(LIBSSH_FOUND FALSE) |
| 102 | endif (LIBSSH_VERSION_MAJOR) |
| 103 | endif (LibSSH_FIND_VERSION) |
| 104 | endif (SSH_FOUND) |
| 105 | |
| 106 | # If the version is too old, but libs and includes are set, |
| 107 | # find_package_handle_standard_args will set LIBSSH_FOUND to TRUE again, |
| 108 | # so we need this if() here. |
| 109 | if (LIBSSH_FOUND) |
| 110 | include(FindPackageHandleStandardArgs) |
Michal Vasko | 75441e7 | 2017-09-27 13:57:00 +0200 | [diff] [blame] | 111 | find_package_handle_standard_args(LibSSH DEFAULT_MSG LIBSSH_LIBRARY_DIR LIBSSH_INCLUDE_DIRS) |
Radek Krejci | 4f2d40d | 2015-10-08 12:55:01 +0200 | [diff] [blame] | 112 | endif (LIBSSH_FOUND) |
| 113 | |
Michal Vasko | 75441e7 | 2017-09-27 13:57:00 +0200 | [diff] [blame] | 114 | # show the LIBSSH_INCLUDE_DIRS and LIBSSH_LIBRARY_DIR variables only in the advanced view |
| 115 | mark_as_advanced(LIBSSH_INCLUDE_DIRS LIBSSH_LIBRARY_DIR) |
Radek Krejci | 4f2d40d | 2015-10-08 12:55:01 +0200 | [diff] [blame] | 116 | |
Michal Vasko | 75441e7 | 2017-09-27 13:57:00 +0200 | [diff] [blame] | 117 | endif (LIBSSH_LIBRARY_DIR AND LIBSSH_INCLUDE_DIRS) |
Radek Krejci | 4f2d40d | 2015-10-08 12:55:01 +0200 | [diff] [blame] | 118 | |