diff options
author | Jakub Zakrzewski <jzakrzewski@e2ebridge.com> | 2014-08-06 14:50:40 +0200 |
---|---|---|
committer | Daniel Stenberg <daniel@haxx.se> | 2014-08-25 12:44:24 +0200 |
commit | 118977f19d2d7e842bdf4424c7cfbc5991781412 (patch) | |
tree | 101303b81ea6e5a1a13b4e8ee66f7dbfe40bc0a1 | |
parent | 88c17d5587447b367c7ec836ff9b847860f52f75 (diff) |
Cmake: LibSSH2 detection and use.
-rw-r--r-- | CMake/FindLibSSH2.cmake | 35 | ||||
-rw-r--r-- | CMakeLists.txt | 38 | ||||
-rw-r--r-- | lib/curl_config.h.cmake | 15 |
3 files changed, 85 insertions, 3 deletions
diff --git a/CMake/FindLibSSH2.cmake b/CMake/FindLibSSH2.cmake new file mode 100644 index 000000000..12a7c612b --- /dev/null +++ b/CMake/FindLibSSH2.cmake @@ -0,0 +1,35 @@ +# - Try to find the libssh2 library +# Once done this will define +# +# LIBSSH2_FOUND - system has the libssh2 library +# LIBSSH2_INCLUDE_DIR - the libssh2 include directory +# LIBSSH2_LIBRARY - the libssh2 library name + +if (LIBSSH2_INCLUDE_DIR AND LIBSSH2_LIBRARY) + set(LibSSH2_FIND_QUIETLY TRUE) +endif (LIBSSH2_INCLUDE_DIR AND LIBSSH2_LIBRARY) + +FIND_PATH(LIBSSH2_INCLUDE_DIR libssh2.h +) + +FIND_LIBRARY(LIBSSH2_LIBRARY NAMES ssh2 +) + +if(LIBSSH2_INCLUDE_DIR) + file(STRINGS "${LIBSSH2_INCLUDE_DIR}/libssh2.h" libssh2_version_str REGEX "^#define[\t ]+LIBSSH2_VERSION_NUM[\t ]+0x[0-9][0-9][0-9][0-9][0-9][0-9].*") + + string(REGEX REPLACE "^.*LIBSSH2_VERSION_NUM[\t ]+0x([0-9][0-9]).*$" "\\1" LIBSSH2_VERSION_MAJOR "${libssh2_version_str}") + string(REGEX REPLACE "^.*LIBSSH2_VERSION_NUM[\t ]+0x[0-9][0-9]([0-9][0-9]).*$" "\\1" LIBSSH2_VERSION_MINOR "${libssh2_version_str}") + string(REGEX REPLACE "^.*LIBSSH2_VERSION_NUM[\t ]+0x[0-9][0-9][0-9][0-9]([0-9][0-9]).*$" "\\1" LIBSSH2_VERSION_PATCH "${libssh2_version_str}") + + string(REGEX REPLACE "^0(.+)" "\\1" LIBSSH2_VERSION_MAJOR "${LIBSSH2_VERSION_MAJOR}") + string(REGEX REPLACE "^0(.+)" "\\1" LIBSSH2_VERSION_MINOR "${LIBSSH2_VERSION_MINOR}") + string(REGEX REPLACE "^0(.+)" "\\1" LIBSSH2_VERSION_PATCH "${LIBSSH2_VERSION_PATCH}") + + set(LIBSSH2_VERSION "${LIBSSH2_VERSION_MAJOR}.${LIBSSH2_VERSION_MINOR}.${LIBSSH2_VERSION_PATCH}") +endif(LIBSSH2_INCLUDE_DIR) + +include(FindPackageHandleStandardArgs) +FIND_PACKAGE_HANDLE_STANDARD_ARGS(LibSSH2 DEFAULT_MSG LIBSSH2_INCLUDE_DIR LIBSSH2_LIBRARY ) + +MARK_AS_ADVANCED(LIBSSH2_INCLUDE_DIR LIBSSH2_LIBRARY LIBSSH2_VERSION_MAJOR LIBSSH2_VERSION_MINOR LIBSSH2_VERSION_PATCH LIBSSH2_VERSION) diff --git a/CMakeLists.txt b/CMakeLists.txt index 9603c18c8..bf4dcd722 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -289,11 +289,40 @@ if(CMAKE_USE_OPENSSL) endif(OPENSSL_FOUND) endif(CMAKE_USE_OPENSSL) +#libSSH2 +option(CMAKE_USE_LIBSSH2 "Use libSSH2" ON) +mark_as_advanced(CMAKE_USE_LIBSSH2) +set(USE_LIBSSH2 OFF) +set(HAVE_LIBSSH2 OFF) + +if(CMAKE_USE_LIBSSH2) + find_package(LibSSH2) + if(LIBSSH2_FOUND) + list(APPEND CURL_LIBS ${LIBSSH2_LIBRARY}) + set(CMAKE_REQUIRED_LIBRARIES ${LIBSSH2_LIBRARY}) + set(CMAKE_REQUIRED_INCLUDES "${LIBSSH2_INCLUDE_DIR}") + set(HAVE_LIBSSH2 ON) + set(USE_LIBSSH2 ON) + + # find_package has already found the headers + set(CURL_INCLUDES ${CURL_INCLUDES} "${LIBSSH2_INCLUDE_DIR}/libssh2.h") + set(CURL_TEST_DEFINES "${CURL_TEST_DEFINES} -DHAVE_LIBSSH2_H") + + # now check for specific libssh2 symbols as they were added in different versions + set(CMAKE_EXTRA_INCLUDE_FILES "libssh2.h") + check_function_exists(libssh2_version HAVE_LIBSSH2_VERSION) + check_function_exists(libssh2_init HAVE_LIBSSH2_INIT) + check_function_exists(libssh2_exit HAVE_LIBSSH2_EXIT) + check_function_exists(libssh2_scp_send64 HAVE_LIBSSH2_SCP_SEND64) + check_function_exists(libssh2_session_handshake HAVE_LIBSSH2_SESSION_HANDSHAKE) + set(CMAKE_EXTRA_INCLUDE_FILES "") + + endif(LIBSSH2_FOUND) +endif(CMAKE_USE_LIBSSH2) + # If we have features.h, then do the _BSD_SOURCE magic check_include_file("features.h" HAVE_FEATURES_H) - - # Check for header files if(NOT UNIX) check_include_file_concat("ws2tcpip.h" HAVE_WS2TCPIP_H) @@ -337,7 +366,6 @@ check_include_file_concat("ifaddrs.h" HAVE_IFADDRS_H) check_include_file_concat("io.h" HAVE_IO_H) check_include_file_concat("krb.h" HAVE_KRB_H) check_include_file_concat("libgen.h" HAVE_LIBGEN_H) -check_include_file_concat("libssh2.h" HAVE_LIBSSH2_H) check_include_file_concat("limits.h" HAVE_LIMITS_H) check_include_file_concat("locale.h" HAVE_LOCALE_H) check_include_file_concat("net/if.h" HAVE_NET_IF_H) @@ -779,6 +807,10 @@ function(SETUP_CURL_DEPENDENCIES TARGET_NAME) #ADD_DEFINITIONS( -DUSE_SSLEAY ) endif() + if(CMAKE_USE_LIBSSH2 AND LIBSSH2_FOUND) + include_directories(${LIBSSH2_INCLUDE_DIR}) + endif() + target_link_libraries(${TARGET_NAME} ${CURL_LIBS}) endfunction() diff --git a/lib/curl_config.h.cmake b/lib/curl_config.h.cmake index bb6acc4ec..c8b884c51 100644 --- a/lib/curl_config.h.cmake +++ b/lib/curl_config.h.cmake @@ -356,6 +356,21 @@ /* Define to 1 if you have the `ssh2' library (-lssh2). */ #cmakedefine HAVE_LIBSSH2 1 +/* Define to 1 if libssh2 provides `libssh2_version'. */ +#cmakedefine HAVE_LIBSSH2_VERSION 1 + +/* Define to 1 if libssh2 provides `libssh2_init'. */ +#cmakedefine HAVE_LIBSSH2_INIT 1 + +/* Define to 1 if libssh2 provides `libssh2_exit'. */ +#cmakedefine HAVE_LIBSSH2_EXIT 1 + +/* Define to 1 if libssh2 provides `libssh2_scp_send64'. */ +#cmakedefine HAVE_LIBSSH2_SCP_SEND64 1 + +/* Define to 1 if libssh2 provides `libssh2_session_handshake'. */ +#cmakedefine HAVE_LIBSSH2_SESSION_HANDSHAKE 1 + /* Define to 1 if you have the <libssh2.h> header file. */ #cmakedefine HAVE_LIBSSH2_H 1 |