Hello,

I am working on adding libssh2 support into cmake (specifically the curl
code). Most of the ground work was previously done so most of what I had to
use was add cmake support. I'm having some issues still.

So, I've added the option for libssh2, its find_package call, and defined
the options in Utilities/cmcurl/config.h.in for libssh2.

When try a simple test (cmake -P)
file(WRITE  upload.txt "testing upload")
file(UPLOAD upload.txt "sftp://username:pw@url:path/to/home/"; STATUS status
SHOW_PROGRESS)
message(STATUS "STATUS ${status}")

I get:
-- STATUS 6;"couldn't resolve host name"
or (If I drop the path):
-- STATUS 2;"failed init"

I cannot be sure if this is a parsing problem or some other problem.  Using
--debug-output doesn't give me anything additional and I don't know where
this error is being thrown.  Is there an easy way to get more info than
this?  I've tried adding some printfs to print the hostname, but they don't
seem to be displayed (or maybe I haven't found the correct location of
where its thrown).


The only non cmake change I made was a function name change for
libssh2_free to libssh2_free2 in ssh.c. The current code defines this
function for the LIBSSH2_FREE_FUNC callback but this function is already
defined in libssh2.h (I am using version 1.4.3).  I renamed this function
in the cmake code to libssh2_free2 so the symbols would not clash.
Anyway, I attached the git patch so people can take a look. There may be a
few debug messages in there which would be removed before submission.

-Jameson
From 6a4c0e1eb7d3820d598502a944de149d7f2d616e Mon Sep 17 00:00:00 2001
From: Jameson Merkow <[email protected]>
Date: Wed, 29 Oct 2014 12:13:25 -0700
Subject: [PATCH 1/2] Added options for libssh2

---
 CMakeLists.txt                  |  3 ---
 Modules/FindLibSsh2.cmake       | 29 +++++++++++++++++++++++++++++
 Utilities/cmcurl/CMakeLists.txt | 14 ++++++++++++++
 Utilities/cmcurl/config.h.in    |  1 +
 Utilities/cmcurl/ssh.c          | 12 +++++++++---
 5 files changed, 53 insertions(+), 6 deletions(-)
 create mode 100644 Modules/FindLibSsh2.cmake

diff --git a/CMakeLists.txt b/CMakeLists.txt
index c2060ea..b4123ad 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -110,9 +110,6 @@ macro(CMAKE_HANDLE_SYSTEM_LIBRARIES)
 
 endmacro()
 
-
-
-
 if(NOT CMake_TEST_EXTERNAL_CMAKE)
   set(CMAKE_BUILD_ON_VISUAL_STUDIO 0)
   if(WIN32 AND NOT UNIX AND NOT MINGW)
diff --git a/Modules/FindLibSsh2.cmake b/Modules/FindLibSsh2.cmake
new file mode 100644
index 0000000..b4c1d77
--- /dev/null
+++ b/Modules/FindLibSsh2.cmake
@@ -0,0 +1,29 @@
+# - Try to find libssh2
+# Once done this will define
+#  LIBSSH2_FOUND - System has libssh2
+#  LIBSSH2_INCLUDE_DIRS - The libssh2 include directories
+#  LIBSSH2_LIBRARIES - The libraries needed to use libssh2
+#  LIBSSH2_DEFINITIONS - Compiler switches required for using libssh2
+
+find_package(PkgConfig)
+pkg_check_modules(PC_LIBSSH2 QUIET libssh2)
+set(LIBSSH2_DEFINITIONS ${PC_LIBSSH2_CFLAGS_OTHER})
+
+message(STATUS "Looking for libssh2...")
+find_path(LIBSSH2_INCLUDE_DIR libssh2.h
+          HINTS ${PC_LIBSSH2_INCLUDEDIR} ${PC_LIBSSH2_INCLUDE_DIRS}
+          PATH_SUFFIXES libssh2 )
+
+find_library(LIBSSH2_LIBRARY NAMES ssh2 libssh2
+             HINTS ${PC_LIBSSH2_LIBDIR} ${PC_LIBSSH2_LIBRARY_DIRS} )
+
+set(LIBSSH2_LIBRARIES ${LIBSSH2_LIBRARY} )
+set(LIBSSH2_INCLUDE_DIRS ${LIBSSH2_INCLUDE_DIR} )
+
+include(FindPackageHandleStandardArgs)
+# handle the QUIETLY and REQUIRED arguments and set LIBSSH2_FOUND to TRUE
+# if all listed variables are TRUE
+find_package_handle_standard_args(LibSsh2  DEFAULT_MSG
+                                  LIBSSH2_LIBRARY LIBSSH2_INCLUDE_DIR)
+
+mark_as_advanced(LIBSSH2_INCLUDE_DIR LIBSSH2_LIBRARY)
\ No newline at end of file
diff --git a/Utilities/cmcurl/CMakeLists.txt b/Utilities/cmcurl/CMakeLists.txt
index 97fd2ff..cafa606 100644
--- a/Utilities/cmcurl/CMakeLists.txt
+++ b/Utilities/cmcurl/CMakeLists.txt
@@ -210,6 +210,20 @@ IF(CMAKE_USE_OPENSSL)
   ENDIF()
 ENDIF(CMAKE_USE_OPENSSL)
 
+
+OPTION(CMAKE_USE_LIBSSH2 "Use libssh2 code with curl." OFF)
+MARK_AS_ADVANCED(CMAKE_USE_LIBSSH2)
+IF(CMAKE_USE_LIBSSH2)
+  SET(USE_LIBSSH2 TRUE)
+  FIND_PACKAGE(LibSsh2 REQUIRED)
+  INCLUDE_DIRECTORIES(${LIBSSH2_INCLUDE_DIR})
+  SET(CURL_LIBS  ${CURL_LIBS} ${LIBSSH2_LIBRARIES})
+  set(HAVE_LIBSSH2 TRUE)
+  set(CURL_LIBSSH2_DEBUG TRUE)
+  CHECK_INCLUDE_FILE("libssh2.h"       HAVE_LIBSSH2_H)
+  message("HAVE_LIBSSH2 ${HAVE_LIBSSH2}")
+ENDIF(CMAKE_USE_LIBSSH2)
+
 # Check for idn
 CHECK_LIBRARY_EXISTS_CONCAT("idn" idna_to_ascii_lz HAVE_LIBIDN)
 
diff --git a/Utilities/cmcurl/config.h.in b/Utilities/cmcurl/config.h.in
index 148722b..45a5f3c 100644
--- a/Utilities/cmcurl/config.h.in
+++ b/Utilities/cmcurl/config.h.in
@@ -656,6 +656,7 @@
 
 /* if libSSH2 is in use */
 #cmakedefine USE_LIBSSH2 ${USE_LIBSSH2}
+#cmakedefine CURL_LIBSSH2_DEBUG ${CURL_LIBSSH2_DEBUG}
 
 /* If you want to build curl with the built-in manual */
 #cmakedefine USE_MANUAL ${USE_MANUAL}
diff --git a/Utilities/cmcurl/ssh.c b/Utilities/cmcurl/ssh.c
index 24cba1b..1dcdaa4 100644
--- a/Utilities/cmcurl/ssh.c
+++ b/Utilities/cmcurl/ssh.c
@@ -167,9 +167,13 @@
 #define LIBSSH2_SFTP_S_IXOTH S_IXOTH
 #endif
 
+
 static LIBSSH2_ALLOC_FUNC(libssh2_malloc);
 static LIBSSH2_REALLOC_FUNC(libssh2_realloc);
-static LIBSSH2_FREE_FUNC(libssh2_free);
+#ifndef USE_LIBSSH2
+static LIBSSH2_FREE_FUNC(libssh2_free2);
+#endif
+
 
 static void
 kbd_callback(const char *name, int name_len, const char *instruction,
@@ -232,12 +236,14 @@ static LIBSSH2_REALLOC_FUNC(libssh2_realloc)
   (void)abstract;
 }
 
-static LIBSSH2_FREE_FUNC(libssh2_free)
+
+static LIBSSH2_FREE_FUNC(libssh2_free2)
 {
   free(ptr);
   (void)abstract;
 }
 
+
 static CURLcode ssh_init(struct connectdata *conn)
 {
   struct SessionHandle *data = conn->data;
@@ -312,7 +318,7 @@ CURLcode Curl_ssh_connect(struct connectdata *conn, bool *done)
   }
 #endif /* CURL_LIBSSH2_DEBUG */
   sock = conn->sock[FIRSTSOCKET];
-  ssh->ssh_session = libssh2_session_init_ex(libssh2_malloc, libssh2_free,
+  ssh->ssh_session = libssh2_session_init_ex(libssh2_malloc, libssh2_free2,
                                             libssh2_realloc, ssh);
   if (ssh->ssh_session == NULL) {
     failf(data, "Failure initialising ssh session\n");
-- 
1.9.1


From 71dfd789e603e12d4ee71d1605ee7d528709304d Mon Sep 17 00:00:00 2001
From: Jameson Merkow <[email protected]>
Date: Wed, 29 Oct 2014 12:22:39 -0700
Subject: [PATCH 2/2] removed a ifdef

---
 Utilities/cmcurl/ssh.c | 2 --
 1 file changed, 2 deletions(-)

diff --git a/Utilities/cmcurl/ssh.c b/Utilities/cmcurl/ssh.c
index 1dcdaa4..b78fe25 100644
--- a/Utilities/cmcurl/ssh.c
+++ b/Utilities/cmcurl/ssh.c
@@ -170,9 +170,7 @@
 
 static LIBSSH2_ALLOC_FUNC(libssh2_malloc);
 static LIBSSH2_REALLOC_FUNC(libssh2_realloc);
-#ifndef USE_LIBSSH2
 static LIBSSH2_FREE_FUNC(libssh2_free2);
-#endif
 
 
 static void
-- 
1.9.1

-- 

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: 
http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more 
information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at 
http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/cmake-developers

Reply via email to