2
0

FindLibssh.cmake 3.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. #***************************************************************************
  2. # _ _ ____ _
  3. # Project ___| | | | _ \| |
  4. # / __| | | | |_) | |
  5. # | (__| |_| | _ <| |___
  6. # \___|\___/|_| \_\_____|
  7. #
  8. # Copyright (C) Daniel Stenberg, <daniel@haxx.se>, 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 libssh library
  25. #
  26. # Input variables:
  27. #
  28. # LIBSSH_INCLUDE_DIR The libssh include directory
  29. # LIBSSH_LIBRARY Path to libssh library
  30. #
  31. # Result variables:
  32. #
  33. # LIBSSH_FOUND System has libssh
  34. # LIBSSH_INCLUDE_DIRS The libssh include directories
  35. # LIBSSH_LIBRARIES The libssh library names
  36. # LIBSSH_LIBRARY_DIRS The libssh library directories
  37. # LIBSSH_CFLAGS Required compiler flags
  38. # LIBSSH_VERSION Version of libssh
  39. if(CURL_USE_PKGCONFIG AND
  40. NOT DEFINED LIBSSH_INCLUDE_DIR AND
  41. NOT DEFINED LIBSSH_LIBRARY)
  42. find_package(PkgConfig QUIET)
  43. pkg_check_modules(LIBSSH "libssh")
  44. endif()
  45. if(LIBSSH_FOUND)
  46. string(REPLACE ";" " " LIBSSH_CFLAGS "${LIBSSH_CFLAGS}")
  47. message(STATUS "Found Libssh (via pkg-config): ${LIBSSH_INCLUDE_DIRS} (found version \"${LIBSSH_VERSION}\")")
  48. else()
  49. find_path(LIBSSH_INCLUDE_DIR NAMES "libssh/libssh.h")
  50. find_library(LIBSSH_LIBRARY NAMES "ssh" "libssh")
  51. if(LIBSSH_INCLUDE_DIR AND EXISTS "${LIBSSH_INCLUDE_DIR}/libssh/libssh_version.h")
  52. set(_version_regex1 "#[\t ]*define[\t ]+LIBSSH_VERSION_MAJOR[\t ]+([0-9]+).*")
  53. set(_version_regex2 "#[\t ]*define[\t ]+LIBSSH_VERSION_MINOR[\t ]+([0-9]+).*")
  54. set(_version_regex3 "#[\t ]*define[\t ]+LIBSSH_VERSION_MICRO[\t ]+([0-9]+).*")
  55. file(STRINGS "${LIBSSH_INCLUDE_DIR}/libssh/libssh_version.h" _version_str1 REGEX "${_version_regex1}")
  56. file(STRINGS "${LIBSSH_INCLUDE_DIR}/libssh/libssh_version.h" _version_str2 REGEX "${_version_regex2}")
  57. file(STRINGS "${LIBSSH_INCLUDE_DIR}/libssh/libssh_version.h" _version_str3 REGEX "${_version_regex3}")
  58. string(REGEX REPLACE "${_version_regex1}" "\\1" _version_str1 "${_version_str1}")
  59. string(REGEX REPLACE "${_version_regex2}" "\\1" _version_str2 "${_version_str2}")
  60. string(REGEX REPLACE "${_version_regex3}" "\\1" _version_str3 "${_version_str3}")
  61. set(LIBSSH_VERSION "${_version_str1}.${_version_str2}.${_version_str3}")
  62. unset(_version_regex1)
  63. unset(_version_regex2)
  64. unset(_version_regex3)
  65. unset(_version_str1)
  66. unset(_version_str2)
  67. unset(_version_str3)
  68. endif()
  69. include(FindPackageHandleStandardArgs)
  70. find_package_handle_standard_args(Libssh
  71. REQUIRED_VARS
  72. LIBSSH_INCLUDE_DIR
  73. LIBSSH_LIBRARY
  74. VERSION_VAR
  75. LIBSSH_VERSION
  76. )
  77. if(LIBSSH_FOUND)
  78. set(LIBSSH_INCLUDE_DIRS ${LIBSSH_INCLUDE_DIR})
  79. set(LIBSSH_LIBRARIES ${LIBSSH_LIBRARY})
  80. endif()
  81. mark_as_advanced(LIBSSH_INCLUDE_DIR LIBSSH_LIBRARY)
  82. endif()
  83. if(LIBSSH_FOUND AND WIN32)
  84. list(APPEND LIBSSH_LIBRARIES "iphlpapi") # for if_nametoindex
  85. endif()