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 | |
Claus Klein | 2209191 | 2020-01-20 13:45:47 +0100 | [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) |
Claus Klein | 2209191 | 2020-01-20 13:45:47 +0100 | [diff] [blame^] | 37 | else() |
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 | |
Claus Klein | 2209191 | 2020-01-20 13:45:47 +0100 | [diff] [blame^] | 51 | find_library(LIBSSH_LIBRARY |
Radek Krejci | 4f2d40d | 2015-10-08 12:55:01 +0200 | [diff] [blame] | 52 | NAMES |
Michal Vasko | 75441e7 | 2017-09-27 13:57:00 +0200 | [diff] [blame] | 53 | ssh.so |
| 54 | libssh.so |
Claus Klein | 2209191 | 2020-01-20 13:45:47 +0100 | [diff] [blame^] | 55 | libssh.dylib |
Radek Krejci | 4f2d40d | 2015-10-08 12:55:01 +0200 | [diff] [blame] | 56 | PATHS |
| 57 | /usr/lib |
| 58 | /usr/local/lib |
| 59 | /opt/local/lib |
| 60 | /sw/lib |
| 61 | ${CMAKE_LIBRARY_PATH} |
| 62 | ${CMAKE_INSTALL_PREFIX}/lib |
| 63 | ) |
| 64 | |
Claus Klein | 2209191 | 2020-01-20 13:45:47 +0100 | [diff] [blame^] | 65 | if(LIBSSH_INCLUDE_DIR AND LIBSSH_LIBRARY) |
| 66 | set(LIBSSH_FOUND TRUE) |
| 67 | message(STATUS "LIBSSH Found: ${LIBSSH_LIBRARY}") |
| 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}) |
| 71 | message(STATUS "LIBSSH_INCLUDE_DIR: ${LIBSSH_INCLUDE_DIR}") |
Radek Krejci | 4f2d40d | 2015-10-08 12:55:01 +0200 | [diff] [blame] | 72 | |
Claus Klein | 2209191 | 2020-01-20 13:45:47 +0100 | [diff] [blame^] | 73 | if(LIBSSH_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 | ) |
Claus Klein | 2209191 | 2020-01-20 13:45:47 +0100 | [diff] [blame^] | 86 | message(STATUS "LIBSSH_LIBRARY_DIR: ${LIBSSH_LIBRARY_DIR}") |
Radek Krejci | 4f2d40d | 2015-10-08 12:55:01 +0200 | [diff] [blame] | 87 | |
Claus Klein | 2209191 | 2020-01-20 13:45:47 +0100 | [diff] [blame^] | 88 | if(LIBSSH_FIND_VERSION) |
Radek Krejci | 4f2d40d | 2015-10-08 12:55:01 +0200 | [diff] [blame] | 89 | file(STRINGS ${LIBSSH_INCLUDE_DIR}/libssh/libssh.h LIBSSH_VERSION_MAJOR |
| 90 | REGEX "#define[ ]+LIBSSH_VERSION_MAJOR[ ]+[0-9]+") |
| 91 | # Older versions of libssh like libssh-0.2 have LIBSSH_VERSION but not LIBSSH_VERSION_MAJOR |
Claus Klein | 2209191 | 2020-01-20 13:45:47 +0100 | [diff] [blame^] | 92 | if(LIBSSH_VERSION_MAJOR) |
Radek Krejci | 4f2d40d | 2015-10-08 12:55:01 +0200 | [diff] [blame] | 93 | string(REGEX MATCH "[0-9]+" LIBSSH_VERSION_MAJOR ${LIBSSH_VERSION_MAJOR}) |
Claus Klein | 2209191 | 2020-01-20 13:45:47 +0100 | [diff] [blame^] | 94 | file(STRINGS ${LIBSSH_INCLUDE_DIR}/libssh/libssh.h LIBSSH_VERSION_MINOR |
Radek Krejci | 4f2d40d | 2015-10-08 12:55:01 +0200 | [diff] [blame] | 95 | REGEX "#define[ ]+LIBSSH_VERSION_MINOR[ ]+[0-9]+") |
Claus Klein | 2209191 | 2020-01-20 13:45:47 +0100 | [diff] [blame^] | 96 | string(REGEX MATCH "[0-9]+" LIBSSH_VERSION_MINOR ${LIBSSH_VERSION_MINOR}) |
| 97 | file(STRINGS ${LIBSSH_INCLUDE_DIR}/libssh/libssh.h LIBSSH_VERSION_PATCH |
Radek Krejci | 4f2d40d | 2015-10-08 12:55:01 +0200 | [diff] [blame] | 98 | REGEX "#define[ ]+LIBSSH_VERSION_MICRO[ ]+[0-9]+") |
Claus Klein | 2209191 | 2020-01-20 13:45:47 +0100 | [diff] [blame^] | 99 | string(REGEX MATCH "[0-9]+" LIBSSH_VERSION_PATCH ${LIBSSH_VERSION_PATCH}) |
Radek Krejci | 4f2d40d | 2015-10-08 12:55:01 +0200 | [diff] [blame] | 100 | |
Claus Klein | 2209191 | 2020-01-20 13:45:47 +0100 | [diff] [blame^] | 101 | set(LIBSSH_VERSION ${LIBSSH_VERSION_MAJOR}.${LIBSSH_VERSION_MINOR}.${LIBSSH_VERSION_PATCH}) |
Radek Krejci | 4f2d40d | 2015-10-08 12:55:01 +0200 | [diff] [blame] | 102 | |
Claus Klein | 2209191 | 2020-01-20 13:45:47 +0100 | [diff] [blame^] | 103 | include(FindPackageVersionCheck) |
| 104 | find_package_version_check(LIBSSH DEFAULT_MSG) |
| 105 | else() |
Radek Krejci | 4f2d40d | 2015-10-08 12:55:01 +0200 | [diff] [blame] | 106 | message(STATUS "LIBSSH_VERSION_MAJOR not found in ${LIBSSH_INCLUDE_DIR}/libssh/libssh.h, assuming libssh is too old") |
| 107 | set(LIBSSH_FOUND FALSE) |
Claus Klein | 2209191 | 2020-01-20 13:45:47 +0100 | [diff] [blame^] | 108 | endif() |
| 109 | endif() |
| 110 | endif() |
Radek Krejci | 4f2d40d | 2015-10-08 12:55:01 +0200 | [diff] [blame] | 111 | |
| 112 | # If the version is too old, but libs and includes are set, |
| 113 | # find_package_handle_standard_args will set LIBSSH_FOUND to TRUE again, |
| 114 | # so we need this if() here. |
Claus Klein | 2209191 | 2020-01-20 13:45:47 +0100 | [diff] [blame^] | 115 | if(LIBSSH_FOUND) |
Radek Krejci | 4f2d40d | 2015-10-08 12:55:01 +0200 | [diff] [blame] | 116 | include(FindPackageHandleStandardArgs) |
Claus Klein | 2209191 | 2020-01-20 13:45:47 +0100 | [diff] [blame^] | 117 | find_package_handle_standard_args(LIBSSH DEFAULT_MSG LIBSSH_LIBRARY_DIR LIBSSH_INCLUDE_DIRS) |
| 118 | endif() |
Radek Krejci | 4f2d40d | 2015-10-08 12:55:01 +0200 | [diff] [blame] | 119 | |
Michal Vasko | 75441e7 | 2017-09-27 13:57:00 +0200 | [diff] [blame] | 120 | # show the LIBSSH_INCLUDE_DIRS and LIBSSH_LIBRARY_DIR variables only in the advanced view |
| 121 | mark_as_advanced(LIBSSH_INCLUDE_DIRS LIBSSH_LIBRARY_DIR) |
Radek Krejci | 4f2d40d | 2015-10-08 12:55:01 +0200 | [diff] [blame] | 122 | |
Claus Klein | 2209191 | 2020-01-20 13:45:47 +0100 | [diff] [blame^] | 123 | endif() |
Radek Krejci | 4f2d40d | 2015-10-08 12:55:01 +0200 | [diff] [blame] | 124 | |