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