CMake build system.

Tested:
 - Windows:
    - Visual C++ 2005/2008/2010/2012/2013/MinGW-w64
    - static/shared
    - 32/64-bit
    - OpenSSL/WinCNG
    - Without zlib
 - Linux:
    - GCC 4.6.3/Clang 3.4
    - static/shared
    - 32/64-bit
    - OpenSSL/Libgcrypt
    - With/Without zlib
 - MacOS X
    - AppleClang 6.0.0
    - static
    - 64-bit
    - OpenSSL
    - Without zlib

Conflicts:
	README
This commit is contained in:
Alexander Lamaison 2014-12-23 21:05:05 +00:00
parent 523a552258
commit 6bf8983368
28 changed files with 1865 additions and 9 deletions

101
CMakeLists.txt Normal file
View File

@ -0,0 +1,101 @@
# Copyright (c) 2014, 2015 Alexander Lamaison <alexander.lamaison@gmail.com>
#
# Redistribution and use in source and binary forms,
# with or without modification, are permitted provided
# that the following conditions are met:
#
# Redistributions of source code must retain the above
# copyright notice, this list of conditions and the
# following disclaimer.
#
# Redistributions in binary form must reproduce the above
# copyright notice, this list of conditions and the following
# disclaimer in the documentation and/or other materials
# provided with the distribution.
#
# Neither the name of the copyright holder nor the names
# of any other contributors may be used to endorse or
# promote products derived from this software without
# specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
# CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
# INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
# USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
# OF SUCH DAMAGE.
cmake_minimum_required(VERSION 2.8.11)
set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
project(libssh2 C)
set(PROJECT_URL "http://www.libssh2.org/")
set(PROJECT_DESCRIPTION "The SSH library")
option(BUILD_SHARED_LIBS "Build Shared Libraries" OFF)
# Parse version
file(READ ${CMAKE_CURRENT_SOURCE_DIR}/include/libssh2.h _HEADER_CONTENTS)
string(
REGEX REPLACE ".*#define LIBSSH2_VERSION[ \t]+\"([^\"]+)\".*" "\\1"
LIBSSH2_VERSION "${_HEADER_CONTENTS}")
string(
REGEX REPLACE ".*#define LIBSSH2_VERSION_MAJOR[ \t]+([0-9]+).*" "\\1"
LIBSSH2_VERSION_MAJOR "${_HEADER_CONTENTS}")
string(
REGEX REPLACE ".*#define LIBSSH2_VERSION_MINOR[ \t]+([0-9]+).*" "\\1"
LIBSSH2_VERSION_MINOR "${_HEADER_CONTENTS}")
string(
REGEX REPLACE ".*#define LIBSSH2_VERSION_PATCH[ \t]+([0-9]+).*" "\\1"
LIBSSH2_VERSION_PATCH "${_HEADER_CONTENTS}")
if(NOT LIBSSH2_VERSION OR
NOT LIBSSH2_VERSION_MAJOR MATCHES "^[0-9]+$" OR
NOT LIBSSH2_VERSION_MINOR MATCHES "^[0-9]+$" OR
NOT LIBSSH2_VERSION_PATCH MATCHES "^[0-9]+$")
message(
FATAL_ERROR
"Unable to parse version from"
"${CMAKE_CURRENT_SOURCE_DIR}/include/libssh2.h")
endif()
include(GNUInstallDirs)
install(
FILES docs/AUTHORS COPYING docs/HACKING README RELEASE-NOTES NEWS
DESTINATION ${CMAKE_INSTALL_DOCDIR})
include(max_warnings)
include(FeatureSummary)
add_subdirectory(src)
option(BUILD_EXAMPLES "Build libssh2 examples" ON)
if(BUILD_EXAMPLES)
add_subdirectory(example)
endif()
option(BUILD_TESTING "Build libssh2 test suite" ON)
if(BUILD_TESTING)
enable_testing()
add_subdirectory(tests)
endif()
add_subdirectory(docs)
feature_summary(WHAT ALL)
set(CPACK_PACKAGE_VERSION_MAJOR ${LIBSSH2_VERSION_MAJOR})
set(CPACK_PACKAGE_VERSION_MINOR ${LIBSSH2_VERSION_MINOR})
set(CPACK_PACKAGE_VERSION_PATCH ${LIBSSH2_VERSION_PATCH})
set(CPACK_PACKAGE_VERSION ${LIBSSH2_VERSION})
include(CPack)

4
README
View File

@ -14,4 +14,6 @@ Source code: https://github.com/libssh2/libssh2
Web site source code: https://github.com/libssh2/www
Installation instructions are in docs/INSTALL
Installation instructions are in:
- docs/INSTALL_CMAKE for CMake
- docs/INSTALL_AUTOTOOLS for Autotools

View File

@ -0,0 +1,81 @@
# Copyright (c) 2014 Alexander Lamaison <alexander.lamaison@gmail.com>
#
# Redistribution and use in source and binary forms,
# with or without modification, are permitted provided
# that the following conditions are met:
#
# Redistributions of source code must retain the above
# copyright notice, this list of conditions and the
# following disclaimer.
#
# Redistributions in binary form must reproduce the above
# copyright notice, this list of conditions and the following
# disclaimer in the documentation and/or other materials
# provided with the distribution.
#
# Neither the name of the copyright holder nor the names
# of any other contributors may be used to endorse or
# promote products derived from this software without
# specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
# CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
# INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
# USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
# OF SUCH DAMAGE.
# - check_function_exists_maybe_need_library(<function> <var> [lib1 ... libn])
#
# Check if function is available for linking, first without extra libraries, and
# then, if not found that way, linking in each optional library as well. This
# function is similar to autotools AC_SEARCH_LIBS.
#
# If the function if found, this will define <var>.
#
# If the function was only found by linking in an additional library, this
# will define NEED_LIB_LIBX, where LIBX is the one of lib1 to libn that
# makes the function available, in uppercase.
#
# The following variables may be set before calling this macro to
# modify the way the check is run:
#
# CMAKE_REQUIRED_FLAGS = string of compile command line flags
# CMAKE_REQUIRED_DEFINITIONS = list of macros to define (-DFOO=bar)
# CMAKE_REQUIRED_INCLUDES = list of include directories
# CMAKE_REQUIRED_LIBRARIES = list of libraries to link
#
include(CheckFunctionExists)
include(CheckLibraryExists)
function(check_function_exists_may_need_library function variable)
check_function_exists(${function} ${variable})
if(NOT ${variable})
foreach(lib ${ARGN})
string(TOUPPER ${lib} UP_LIB)
# Use new variable to prevent cache from previous step shortcircuiting
# new test
check_library_exists(${lib} ${function} "" HAVE_${function}_IN_${lib})
if(HAVE_${function}_IN_${lib})
set(${variable} 1 CACHE INTERNAL
"Function ${function} found in library ${lib}")
set(NEED_LIB_${UP_LIB} 1 CACHE INTERNAL
"Need to link ${lib}")
break()
endif()
endforeach()
endif()
endfunction()

View File

@ -0,0 +1,119 @@
include(CheckCSourceCompiles)
# - check_nonblocking_socket_support()
#
# Check for how to set a socket to non-blocking state. There seems to exist
# four known different ways, with the one used almost everywhere being POSIX
# and XPG3, while the other different ways for different systems (old BSD,
# Windows and Amiga).
#
# One of the following variables will be set indicating the supported
# method (if any):
# HAVE_O_NONBLOCK
# HAVE_FIONBIO
# HAVE_IOCTLSOCKET
# HAVE_IOCTLSOCKET_CASE
# HAVE_SO_NONBLOCK
# HAVE_DISABLED_NONBLOCKING
#
# The following variables may be set before calling this macro to
# modify the way the check is run:
#
# CMAKE_REQUIRED_FLAGS = string of compile command line flags
# CMAKE_REQUIRED_DEFINITIONS = list of macros to define (-DFOO=bar)
# CMAKE_REQUIRED_INCLUDES = list of include directories
# CMAKE_REQUIRED_LIBRARIES = list of libraries to link
#
macro(check_nonblocking_socket_support)
# There are two known platforms (AIX 3.x and SunOS 4.1.x) where the
# O_NONBLOCK define is found but does not work.
check_c_source_compiles("
#include <sys/types.h>
#include <unistd.h>
#include <fcntl.h>
#if defined(sun) || defined(__sun__) || defined(__SUNPRO_C) || defined(__SUNPRO_CC)
# if defined(__SVR4) || defined(__srv4__)
# define PLATFORM_SOLARIS
# else
# define PLATFORM_SUNOS4
# endif
#endif
#if (defined(_AIX) || defined(__xlC__)) && !defined(_AIX41)
# define PLATFORM_AIX_V3
#endif
#if defined(PLATFORM_SUNOS4) || defined(PLATFORM_AIX_V3) || defined(__BEOS__)
#error \"O_NONBLOCK does not work on this platform\"
#endif
int main()
{
int socket;
int flags = fcntl(socket, F_SETFL, flags | O_NONBLOCK);
}"
HAVE_O_NONBLOCK)
if(NOT HAVE_O_NONBLOCK)
check_c_source_compiles("/* FIONBIO test (old-style unix) */
#include <unistd.h>
#include <stropts.h>
int main()
{
int socket;
int flags = ioctl(socket, FIONBIO, &flags);
}"
HAVE_FIONBIO)
if(NOT HAVE_FIONBIO)
check_c_source_compiles("/* ioctlsocket test (Windows) */
#undef inline
#ifndef WIN32_LEAN_AND_MEAN
#define WIN32_LEAN_AND_MEAN
#endif
#include <windows.h>
#include <winsock2.h>
int main()
{
SOCKET sd;
unsigned long flags = 0;
sd = socket(0, 0, 0);
ioctlsocket(sd, FIONBIO, &flags);
}"
HAVE_IOCTLSOCKET)
if(NOT HAVE_IOCTLSOCKET)
check_c_source_compiles("/* IoctlSocket test (Amiga?) */
#include <sys/ioctl.h>
int main()
{
int socket;
int flags = IoctlSocket(socket, FIONBIO, (long)1);
}"
HAVE_IOCTLSOCKET_CASE)
if(NOT HAVE_IOCTLSOCKET_CASE)
check_c_source_compiles("/* SO_NONBLOCK test (BeOS) */
#include <socket.h>
int main()
{
long b = 1;
int socket;
int flags = setsockopt(socket, SOL_SOCKET, SO_NONBLOCK, &b, sizeof(b));
}"
HAVE_SO_NONBLOCK)
if(NOT HAVE_SO_NONBLOCK)
# No non-blocking socket method found
set(HAVE_DISABLED_NONBLOCKING 1)
endif()
endif()
endif()
endif()
endif()
endmacro()

View File

@ -0,0 +1,72 @@
# Copyright (c) 2014 Alexander Lamaison <alexander.lamaison@gmail.com>
#
# Redistribution and use in source and binary forms,
# with or without modification, are permitted provided
# that the following conditions are met:
#
# Redistributions of source code must retain the above
# copyright notice, this list of conditions and the
# following disclaimer.
#
# Redistributions in binary form must reproduce the above
# copyright notice, this list of conditions and the following
# disclaimer in the documentation and/or other materials
# provided with the distribution.
#
# Neither the name of the copyright holder nor the names
# of any other contributors may be used to endorse or
# promote products derived from this software without
# specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
# CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
# INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
# USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
# OF SUCH DAMAGE.
include(CMakeParseArguments)
function(ADD_TARGET_TO_COPY_DEPENDENCIES)
set(options)
set(oneValueArgs TARGET)
set(multiValueArgs DEPENDENCIES BEFORE_TARGETS)
cmake_parse_arguments(COPY
"${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
if(NOT COPY_DEPENDENCIES)
return()
endif()
# Using a custom target to drive custom commands stops multiple
# parallel builds trying to kick off the commands at the same time
add_custom_target(${COPY_TARGET})
foreach(target ${COPY_BEFORE_TARGETS})
add_dependencies(${target} ${COPY_TARGET})
endforeach()
foreach(dependency ${COPY_DEPENDENCIES})
add_custom_command(
TARGET ${COPY_TARGET}
DEPENDS ${dependency}
# Make directory first otherwise file is copied in place of
# directory instead of into it
COMMAND ${CMAKE_COMMAND}
ARGS -E make_directory ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}
COMMAND ${CMAKE_COMMAND}
ARGS -E copy ${dependency} ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}
VERBATIM)
endforeach()
endfunction()

53
cmake/FindLibgcrypt.cmake Normal file
View File

@ -0,0 +1,53 @@
# Copyright (c) 2014 Alexander Lamaison <alexander.lamaison@gmail.com>
#
# Redistribution and use in source and binary forms,
# with or without modification, are permitted provided
# that the following conditions are met:
#
# Redistributions of source code must retain the above
# copyright notice, this list of conditions and the
# following disclaimer.
#
# Redistributions in binary form must reproduce the above
# copyright notice, this list of conditions and the following
# disclaimer in the documentation and/or other materials
# provided with the distribution.
#
# Neither the name of the copyright holder nor the names
# of any other contributors may be used to endorse or
# promote products derived from this software without
# specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
# CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
# INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
# USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
# OF SUCH DAMAGE.
# - Try to find Libgcrypt
# This will define all or none of:
# LIBGCRYPT_FOUND - if Libgcrypt headers and library was found
# LIBGCRYPT_INCLUDE_DIRS - The Libgcrypt include directories
# LIBGCRYPT_LIBRARIES - The libraries needed to use Libgcrypt
find_path(LIBGCRYPT_INCLUDE_DIR gcrypt.h)
find_library(LIBGCRYPT_LIBRARY NAMES gcrypt libgcrypt)
set(LIBGCRYPT_LIBRARIES ${LIBGCRYPT_LIBRARY})
set(LIBGCRYPT_INCLUDE_DIRS ${LIBGCRYPT_INCLUDE_DIR})
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(Libgcrypt DEFAULT_MSG
LIBGCRYPT_LIBRARY LIBGCRYPT_INCLUDE_DIR)
mark_as_advanced(LIBGCRYPT_INCLUDE_DIR LIBGCRYPT_LIBRARY)

View File

@ -0,0 +1,64 @@
# Copyright (c) 2014 Alexander Lamaison <alexander.lamaison@gmail.com>
#
# Redistribution and use in source and binary forms,
# with or without modification, are permitted provided
# that the following conditions are met:
#
# Redistributions of source code must retain the above
# copyright notice, this list of conditions and the
# following disclaimer.
#
# Redistributions in binary form must reproduce the above
# copyright notice, this list of conditions and the following
# disclaimer in the documentation and/or other materials
# provided with the distribution.
#
# Neither the name of the copyright holder nor the names
# of any other contributors may be used to endorse or
# promote products derived from this software without
# specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
# CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
# INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
# USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
# OF SUCH DAMAGE.
# Some systems have their socket functions in a library.
# (Solaris -lsocket/-lnsl, Windows -lws2_32). This macro appends those
# libraries to the given list
macro(append_needed_socket_libraries LIBRARIES_LIST)
if(CMAKE_SYSTEM_NAME STREQUAL "Windows" AND CMAKE_SIZEOF_VOID_P EQUAL 4)
# x86 Windows uses STDCALL for these functions, so their names are mangled,
# meaning the platform checks don't work. Hardcoding these until we get
# a better solution.
set(HAVE_SOCKET 1)
set(HAVE_SELECT 1)
set(HAVE_INET_ADDR 1)
set(NEED_LIB_WS2_32 1)
else()
check_function_exists_may_need_library(socket HAVE_SOCKET socket ws2_32)
check_function_exists_may_need_library(select HAVE_SELECT ws2_32)
check_function_exists_may_need_library(inet_addr HAVE_INET_ADDR nsl ws2_32)
endif()
if(NEED_LIB_SOCKET)
list(APPEND ${LIBRARIES_LIST} socket)
endif()
if(NEED_LIB_NSL)
list(APPEND ${LIBRARIES_LIST} nsl)
endif()
if(NEED_LIB_WS2_32)
list(APPEND ${LIBRARIES_LIST} ws2_32)
endif()
endmacro()

View File

@ -0,0 +1,42 @@
# Copyright (c) 2014 Alexander Lamaison <alexander.lamaison@gmail.com>
#
# Redistribution and use in source and binary forms,
# with or without modification, are permitted provided
# that the following conditions are met:
#
# Redistributions of source code must retain the above
# copyright notice, this list of conditions and the
# following disclaimer.
#
# Redistributions in binary form must reproduce the above
# copyright notice, this list of conditions and the following
# disclaimer in the documentation and/or other materials
# provided with the distribution.
#
# Neither the name of the copyright holder nor the names
# of any other contributors may be used to endorse or
# promote products derived from this software without
# specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
# CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
# INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
# USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
# OF SUCH DAMAGE.
# Cross-compile 32-bit binary on 64-bit linux host
set(CMAKE_SYSTEM_NAME Linux)
set(CMAKE_SYSTEM_VERSION 1)
set(CMAKE_SYSTEM_PROCESSOR "i386")
set(CMAKE_CXX_COMPILER_ARG1 "-m32")
set(CMAKE_C_COMPILER_ARG1 "-m32")

23
cmake/max_warnings.cmake Normal file
View File

@ -0,0 +1,23 @@
if(MSVC)
# Use the highest warning level for visual studio.
if(CMAKE_CXX_FLAGS MATCHES "/W[0-4]")
string(REGEX REPLACE "/W[0-4]" "/W4" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
else()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W4")
endif()
if(CMAKE_C_FLAGS MATCHES "/W[0-4]")
string(REGEX REPLACE "/W[0-4]" "/W4" CMAKE_C_FLAGS "${CMAKE_C_FLAGS}")
else()
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /W4")
endif()
# Disable broken warnings
add_definitions(-D_CRT_SECURE_NO_WARNINGS -D_CRT_NONSTDC_NO_DEPRECATE)
elseif(CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX)
if(NOT CMAKE_CXX_FLAGS MATCHES "-Wall")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall")
endif()
if(NOT CMAKE_C_FLAGS MATCHES "-Wall")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall")
endif()
endif()

204
docs/CMakeLists.txt Normal file
View File

@ -0,0 +1,204 @@
# Copyright (c) 2014 Alexander Lamaison <alexander.lamaison@gmail.com>
#
# Redistribution and use in source and binary forms,
# with or without modification, are permitted provided
# that the following conditions are met:
#
# Redistributions of source code must retain the above
# copyright notice, this list of conditions and the
# following disclaimer.
#
# Redistributions in binary form must reproduce the above
# copyright notice, this list of conditions and the following
# disclaimer in the documentation and/or other materials
# provided with the distribution.
#
# Neither the name of the copyright holder nor the names
# of any other contributors may be used to endorse or
# promote products derived from this software without
# specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
# CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
# INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
# USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
# OF SUCH DAMAGE.
set(MAN_PAGES
libssh2_agent_connect.3
libssh2_agent_disconnect.3
libssh2_agent_free.3
libssh2_agent_get_identity.3
libssh2_agent_init.3
libssh2_agent_list_identities.3
libssh2_agent_userauth.3
libssh2_banner_set.3
libssh2_base64_decode.3
libssh2_channel_close.3
libssh2_channel_direct_tcpip.3
libssh2_channel_direct_tcpip_ex.3
libssh2_channel_eof.3
libssh2_channel_exec.3
libssh2_channel_flush.3
libssh2_channel_flush_ex.3
libssh2_channel_flush_stderr.3
libssh2_channel_forward_accept.3
libssh2_channel_forward_cancel.3
libssh2_channel_forward_listen.3
libssh2_channel_forward_listen_ex.3
libssh2_channel_free.3
libssh2_channel_get_exit_signal.3
libssh2_channel_get_exit_status.3
libssh2_channel_handle_extended_data.3
libssh2_channel_handle_extended_data2.3
libssh2_channel_ignore_extended_data.3
libssh2_channel_open_ex.3
libssh2_channel_open_session.3
libssh2_channel_process_startup.3
libssh2_channel_read.3
libssh2_channel_read_ex.3
libssh2_channel_read_stderr.3
libssh2_channel_receive_window_adjust.3
libssh2_channel_receive_window_adjust2.3
libssh2_channel_request_pty.3
libssh2_channel_request_pty_ex.3
libssh2_channel_request_pty_size.3
libssh2_channel_request_pty_size_ex.3
libssh2_channel_send_eof.3
libssh2_channel_set_blocking.3
libssh2_channel_setenv.3
libssh2_channel_setenv_ex.3
libssh2_channel_shell.3
libssh2_channel_subsystem.3
libssh2_channel_wait_closed.3
libssh2_channel_wait_eof.3
libssh2_channel_window_read.3
libssh2_channel_window_read_ex.3
libssh2_channel_window_write.3
libssh2_channel_window_write_ex.3
libssh2_channel_write.3
libssh2_channel_write_ex.3
libssh2_channel_write_stderr.3
libssh2_channel_x11_req.3
libssh2_channel_x11_req_ex.3
libssh2_exit.3
libssh2_free.3
libssh2_hostkey_hash.3
libssh2_init.3
libssh2_keepalive_config.3
libssh2_keepalive_send.3
libssh2_knownhost_add.3
libssh2_knownhost_addc.3
libssh2_knownhost_check.3
libssh2_knownhost_checkp.3
libssh2_knownhost_del.3
libssh2_knownhost_free.3
libssh2_knownhost_get.3
libssh2_knownhost_init.3
libssh2_knownhost_readfile.3
libssh2_knownhost_readline.3
libssh2_knownhost_writefile.3
libssh2_knownhost_writeline.3
libssh2_poll.3
libssh2_poll_channel_read.3
libssh2_publickey_add.3
libssh2_publickey_add_ex.3
libssh2_publickey_init.3
libssh2_publickey_list_fetch.3
libssh2_publickey_list_free.3
libssh2_publickey_remove.3
libssh2_publickey_remove_ex.3
libssh2_publickey_shutdown.3
libssh2_scp_recv.3
libssh2_scp_send.3
libssh2_scp_send64.3
libssh2_scp_send_ex.3
libssh2_session_abstract.3
libssh2_session_banner_get.3
libssh2_session_banner_set.3
libssh2_session_block_directions.3
libssh2_session_callback_set.3
libssh2_session_disconnect.3
libssh2_session_disconnect_ex.3
libssh2_session_flag.3
libssh2_session_free.3
libssh2_session_get_blocking.3
libssh2_session_get_timeout.3
libssh2_session_hostkey.3
libssh2_session_init.3
libssh2_session_init_ex.3
libssh2_session_last_errno.3
libssh2_session_last_error.3
libssh2_session_method_pref.3
libssh2_session_methods.3
libssh2_session_set_blocking.3
libssh2_session_set_timeout.3
libssh2_session_startup.3
libssh2_session_supported_algs.3
libssh2_sftp_close.3
libssh2_sftp_close_handle.3
libssh2_sftp_closedir.3
libssh2_sftp_fsetstat.3
libssh2_sftp_fstat.3
libssh2_sftp_fstat_ex.3
libssh2_sftp_fstatvfs.3
libssh2_sftp_fsync.3
libssh2_sftp_get_channel.3
libssh2_sftp_init.3
libssh2_sftp_last_error.3
libssh2_sftp_lstat.3
libssh2_sftp_mkdir.3
libssh2_sftp_mkdir_ex.3
libssh2_sftp_open.3
libssh2_sftp_open_ex.3
libssh2_sftp_opendir.3
libssh2_sftp_read.3
libssh2_sftp_readdir.3
libssh2_sftp_readdir_ex.3
libssh2_sftp_readlink.3
libssh2_sftp_realpath.3
libssh2_sftp_rename.3
libssh2_sftp_rename_ex.3
libssh2_sftp_rewind.3
libssh2_sftp_rmdir.3
libssh2_sftp_rmdir_ex.3
libssh2_sftp_seek.3
libssh2_sftp_seek64.3
libssh2_sftp_setstat.3
libssh2_sftp_shutdown.3
libssh2_sftp_stat.3
libssh2_sftp_stat_ex.3
libssh2_sftp_statvfs.3
libssh2_sftp_symlink.3
libssh2_sftp_symlink_ex.3
libssh2_sftp_tell.3
libssh2_sftp_tell64.3
libssh2_sftp_unlink.3
libssh2_sftp_unlink_ex.3
libssh2_sftp_write.3
libssh2_trace.3
libssh2_trace_sethandler.3
libssh2_userauth_authenticated.3
libssh2_userauth_hostbased_fromfile.3
libssh2_userauth_hostbased_fromfile_ex.3
libssh2_userauth_keyboard_interactive.3
libssh2_userauth_keyboard_interactive_ex.3
libssh2_userauth_list.3
libssh2_userauth_password.3
libssh2_userauth_password_ex.3
libssh2_userauth_publickey.3
libssh2_userauth_publickey_fromfile.3
libssh2_userauth_publickey_fromfile_ex.3
libssh2_version.3)
include(GNUInstallDirs)
install(FILES ${MAN_PAGES} DESTINATION ${CMAKE_INSTALL_MANDIR}/man3)

174
docs/INSTALL_CMAKE Normal file
View File

@ -0,0 +1,174 @@
License: see COPYING
Source code: https://github.com/libssh2/libssh2
Web site source code: https://github.com/libssh2/www
Installation instructions are in docs/INSTALL
=======
To build libssh2 you will need CMake v2.8 or later [1] and one of the
following cryptography libraries:
* OpenSSL
* Libgcrypt
* WinCNG
Getting started
---------------
If you are happy with the default options, make a new build directory,
change to it, configure the build environment and build the project:
mkdir bin
cd bin
cmake ..
cmake --build .
libssh2 will be built as a static library and will use any
cryptography library available. The library binary will be put in
`bin/src`, with the examples in `bin/example` and the tests in
`bin/tests`.
Customising the build
---------------------
Of course, you might want to customise the build options. You can
pass the options to CMake on the command line:
cmake -D<option>=<value> ..
The following options are available:
* `BUILD_SHARED_LIBS=OFF`
Determines whether libssh2 is built as a static library or as a
shared library (.dll/.so). Can be `ON` or `OFF`.
* `CRYPTO_BACKEND=`
Chooses a specific cryptography library to use for cryptographic
operations. Can be `OpenSSL` (http://www.openssl.org),
`Libgcrypt` (http://www.gnupg.org/), `WinCNG` (Windows Vista+) or
blank to use any library available.
CMake will attempt to locate the libraries automatically. See [2]
for more information.
* `ENABLE_ZLIB_COMPRESSION=OFF`
Will use zlib (http://www.zlib.org) for payload compression. Can
be `ON` or `OFF`.
* `ENABLE_CRYPT_NONE=OFF`
The SSH2 Transport allows for unencrypted data transmission using
the "none" cipher. Because this is such a huge security hole, it
is typically disabled on SSH2 implementations and is disabled in
libssh2 by default as well.
Enabling this option will allow for "none" as a negotiable method,
however it still requires that the method be advertized by the
remote end and that no more-preferable methods are available.
* `ENABLE_MAC_NONE=OFF`
The SSH2 Transport also allows implementations to forego a message
authentication code. While this is less of a security risk than
using a "none" cipher, it is still not recommended as disabling
MAC hashes removes a layer of security.
Enabling this option will allow for "none" as a negotiable method,
however it still requires that the method be advertized by the
remote end and that no more-preferable methods are available.
* `ENABLE_GEX_NEW=ON`
The diffie-hellman-group-exchange-sha1 (dh-gex) key exchange
method originally defined an exchange negotiation using packet
type 30 to request a generation pair based on a single target
value. Later refinement of dh-gex provided for range and target
values. By default libssh2 will use the newer range method.
If you experience trouble connecting to an old SSH server using
dh-gex, try this option to fallback on the older more reliable
method.
* `ENABLE_DEBUG_LOGGING=ON` in Debug, `=OFF` in Release
Will enable the libssh2_trace() function for showing debug traces.
Build tools
-----------
The previous examples used CMake to start the build using:
cmake --build .
Alternatively, once CMake has configured your project, you can just
use your own build tool, e.g GNU make, Visual Studio, etc., from that
point onwards.
Tests
-----
To test the build, run the appropriate test target for your build
system. For example:
cmake --build . --target test
or
cmake --build . --target RUN_TESTS
How do I use libssh2 in my project if my project doesn't use CMake?
-------------------------------------------------------------------
If you are not using CMake for your own project, install libssh2
cmake <libssh2 source location>
cmake --build .
cmake --build . --target install
or
cmake --build . --target INSTALL
and then specify the install location to your project in the normal
way for your build environment. If you don't like the default install
location, add `-DCMAKE_INSTALL_PREFIX=<chosen prefix>` when initially
configuring the project.
How can I use libssh2 in my project if it also uses CMake?
----------------------------------------------------------
If your own project also uses CMake, you don't need to worry about
setting it up with libssh2's location. Just add just the following
lines and CMake will find libssh2 on your system, set up the necessary
paths and link the library with your binary.
find_package(Libssh2 REQUIRED CONFIG)
target_link_libraries(my_project_target Libssh2::libssh2)
Of course, you still have to make libssh2 available on your system
first. You can install it in the traditional way shown above, but you
don't have to. Instead you can just build it, which will export its
location to the user package registry [3] where `find_package` will
find it.
You can even combine the two steps using a so-called 'superbuild'
project [4] that downloads, builds and exports libssh2, and then
builds your project:
include(ExternalProject)
ExternalProject_Add(
Libssh2
URL <libssh2 download location>
URL_HASH SHA1=<libssh2 archive SHA1>
INSTALL_COMMAND "")
ExternalProject_Add(
MyProject DEPENDS Libssh2
SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/src
INSTALL_COMMAND "")
[1] http://www.cmake.org/cmake/resources/software.html
[2] http://www.cmake.org/cmake/help/v3.0/manual/cmake-packages.7.html
[3] http://www.cmake.org/cmake/help/v3.0/manual/cmake-packages.7.html#package-registry
[4] http://www.kitware.com/media/html/BuildingExternalProjectsWithCMake2.8.html

101
example/CMakeLists.txt Normal file
View File

@ -0,0 +1,101 @@
# Copyright (c) 2014 Alexander Lamaison <alexander.lamaison@gmail.com>
#
# Redistribution and use in source and binary forms,
# with or without modification, are permitted provided
# that the followin