From f565aeebfa108d03e5c782881edd2ced849a4989 Mon Sep 17 00:00:00 2001 From: Aris Adamantiadis Date: Sat, 21 Sep 2013 23:32:51 +0200 Subject: [PATCH] Compile libssh with nacl if possible Conflicts: DefineOptions.cmake --- CMakeLists.txt | 8 +++++ DefineOptions.cmake | 6 +++- cmake/Modules/FindNaCl.cmake | 61 ++++++++++++++++++++++++++++++++++++ config.h.cmake | 4 ++- 4 files changed, 77 insertions(+), 2 deletions(-) create mode 100644 cmake/Modules/FindNaCl.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 2c5c7232..5998bc50 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -71,6 +71,13 @@ if (WITH_GSSAPI) find_package(GSSAPI) endif (WITH_GSSAPI) +if (WITH_NACL) + find_package(NaCl) + if (NOT NACL_FOUND) + set(WITH_NACL OFF) + endif (NOT NACL_FOUND) +endif (WITH_NACL) + # config.h checks include(ConfigureChecks.cmake) configure_file(config.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/config.h) @@ -125,6 +132,7 @@ message(STATUS "********** ${PROJECT_NAME} build options : **********") message(STATUS "zlib support: ${WITH_ZLIB}") message(STATUS "libgcrypt support: ${WITH_GCRYPT}") +message(STATUS "libnacl support: ${WITH_NACL}") message(STATUS "SSH-1 support: ${WITH_SSH1}") message(STATUS "SFTP support: ${WITH_SFTP}") message(STATUS "Server support : ${WITH_SERVER}") diff --git a/DefineOptions.cmake b/DefineOptions.cmake index 756b948a..ab7819a5 100644 --- a/DefineOptions.cmake +++ b/DefineOptions.cmake @@ -13,7 +13,7 @@ option(WITH_TESTING "Build with unit tests" OFF) option(WITH_CLIENT_TESTING "Build with client tests; requires a running sshd" OFF) option(WITH_BENCHMARKS "Build benchmarks tools" OFF) option(WITH_EXAMPLES "Build examples" ON) - +option(WITH_NACL "Build with libnacl (curve25519" ON) if (WITH_ZLIB) set(WITH_LIBZ ON) else (WITH_ZLIB) @@ -27,3 +27,7 @@ endif(WITH_BENCHMARKS) if (WITH_TESTING) set(WITH_STATIC_LIB ON) endif (WITH_TESTING) + +if (WITH_NACL) + set(WITH_NACL ON) +endif (WITH_NACL) \ No newline at end of file diff --git a/cmake/Modules/FindNaCl.cmake b/cmake/Modules/FindNaCl.cmake new file mode 100644 index 00000000..fa9c4090 --- /dev/null +++ b/cmake/Modules/FindNaCl.cmake @@ -0,0 +1,61 @@ +# - Try to find NaCl +# Once done this will define +# +# NACL_FOUND - system has NaCl +# NACL_INCLUDE_DIRS - the NaCl include directory +# NACL_LIBRARIES - Link these to use NaCl +# NACL_DEFINITIONS - Compiler switches required for using NaCl +# +# Copyright (c) 2010 Andreas Schneider +# Copyright (c) 2013 Aris Adamantiadis +# +# Redistribution and use is allowed according to the terms of the New +# BSD license. +# For details see the accompanying COPYING-CMAKE-SCRIPTS file. +# + + +if (NACL_LIBRARIES AND NACL_INCLUDE_DIRS) + # in cache already + set(NACL_FOUND TRUE) +else (NACL_LIBRARIES AND NACL_INCLUDE_DIRS) + + find_path(NACL_INCLUDE_DIR + NAMES + nacl/crypto_box_curve25519xsalsa20poly1305.h + PATHS + /usr/include + /usr/local/include + /opt/local/include + /sw/include + ) + + find_library(NACL_LIBRARY + NAMES + nacl + PATHS + /usr/lib + /usr/local/lib + /opt/local/lib + /sw/lib + ) + + set(NACL_INCLUDE_DIRS + ${NACL_INCLUDE_DIR} + ) + + if (NACL_LIBRARY) + set(NACL_LIBRARIES + ${NACL_LIBRARIES} + ${NACL_LIBRARY} + ) + endif (NACL_LIBRARY) + + include(FindPackageHandleStandardArgs) + find_package_handle_standard_args(NaCl DEFAULT_MSG NACL_LIBRARIES NACL_INCLUDE_DIRS) + + # show the NACL_INCLUDE_DIRS and NACL_LIBRARIES variables only in the advanced view + mark_as_advanced(NACL_INCLUDE_DIRS NACL_LIBRARIES) + +endif (NACL_LIBRARIES AND NACL_INCLUDE_DIRS) + diff --git a/config.h.cmake b/config.h.cmake index 1835e070..a4bf4f13 100644 --- a/config.h.cmake +++ b/config.h.cmake @@ -126,7 +126,6 @@ /* Define to 1 if you have the `pthread' library (-lpthread). */ #cmakedefine HAVE_PTHREAD 1 - /**************************** OPTIONS ****************************/ #cmakedefine HAVE_GCC_THREAD_LOCAL_STORAGE 1 @@ -158,6 +157,9 @@ /* Define to 1 if you want to enable calltrace debug output */ #cmakedefine DEBUG_CALLTRACE 1 +/* Define to 1 if you want to enable NaCl support */ +#cmakedefine WITH_NACL 1 + /*************************** ENDIAN *****************************/ /* Define WORDS_BIGENDIAN to 1 if your processor stores words with the most