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