Commit 0a3a220fa9eba8cf9f8e250509958c2131b0a3c6

Laurent Stacul 2021-09-14T09:53:24

Discover libssh2 without pkg-config

diff --git a/cmake/FindLibSSH2.cmake b/cmake/FindLibSSH2.cmake
new file mode 100644
index 0000000..ff58935
--- /dev/null
+++ b/cmake/FindLibSSH2.cmake
@@ -0,0 +1,13 @@
+# LIBSSH2_FOUND - system has the libssh2 library
+# LIBSSH2_INCLUDE_DIR - the libssh2 include directory
+# LIBSSH2_LIBRARY - the libssh2 library name
+
+FIND_PATH(LIBSSH2_INCLUDE_DIR libssh2.h)
+
+FIND_LIBRARY(LIBSSH2_LIBRARY NAMES ssh2 libssh2)
+
+INCLUDE(FindPackageHandleStandardArgs)
+find_package_handle_standard_args(LibSSH2
+    REQUIRED_VARS LIBSSH2_LIBRARY LIBSSH2_INCLUDE_DIR)
+
+MARK_AS_ADVANCED(LIBSSH2_INCLUDE_DIR LIBSSH2_LIBRARY)
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 45dec27..c3029a9 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -232,6 +232,13 @@ ENDIF()
 # Optional external dependency: libssh2
 IF (USE_SSH)
 	FIND_PKGLIBRARIES(LIBSSH2 libssh2)
+    IF (NOT LIBSSH2_FOUND)
+        FIND_PACKAGE(LibSSH2)
+        SET(LIBSSH2_INCLUDE_DIRS ${LIBSSH2_INCLUDE_DIR})
+        GET_FILENAME_COMPONENT(LIBSSH2_LIBRARY_DIRS "${LIBSSH2_LIBRARY}" DIRECTORY)
+        SET(LIBSSH2_LIBRARIES ${LIBSSH2_LIBRARY})
+        SET(LIBSSH2_LDFLAGS "-lssh2")
+    ENDIF()
 ENDIF()
 IF (LIBSSH2_FOUND)
 	SET(GIT_SSH 1)