From eecf963ab888cd719892703c8ebea2483312e666 Mon Sep 17 00:00:00 2001 From: rainbeam Date: Fri, 29 Apr 2016 20:47:03 +0100 Subject: [PATCH] add cmake Find/Use for system libraries --- cmake/FindSSH2.cmake | 30 ++++++++++++++++++++++++++++++ cmake/UseOpenSSL.cmake | 14 ++++++++++++++ cmake/UseSSH2.cmake | 11 +++++++++++ cmake/UseZLIB.cmake | 11 +++++++++++ 4 files changed, 66 insertions(+) create mode 100644 cmake/FindSSH2.cmake create mode 100644 cmake/UseOpenSSL.cmake create mode 100644 cmake/UseSSH2.cmake create mode 100644 cmake/UseZLIB.cmake diff --git a/cmake/FindSSH2.cmake b/cmake/FindSSH2.cmake new file mode 100644 index 0000000..22f0851 --- /dev/null +++ b/cmake/FindSSH2.cmake @@ -0,0 +1,30 @@ +# - Try to find the ssh2 libssh2 library +# Once done this will define +# +# SSH2_FOUND - system has the SSH2 libssh2 library +# SSH2_INCLUDE_DIR - the SSH2 libssh2 include directory +# SSH2_LIBRARIES - The libraries needed to use SSH2 libssh2 + +# only look in default directories +find_path( + SSH2_INCLUDE_DIR + NAMES libssh2.h + DOC "ssh2 include dir" +) + +find_library( + SSH2_LIBRARY + NAMES ssh2 libssh2 + DOC "ssh2 library" +) + +set(SSH2_INCLUDE_DIRS ${SSH2_INCLUDE_DIR}) +set(SSH2_LIBRARIES ${SSH2_LIBRARY}) + +# handle the QUIETLY and REQUIRED arguments and set CURL_FOUND to TRUE +# if all listed variables are TRUE, hide their existence from configuration view +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(SSH2 DEFAULT_MSG + SSH2_LIBRARY SSH2_INCLUDE_DIR) +mark_as_advanced (SSH2_INCLUDE_DIR SSH2_LIBRARY) + diff --git a/cmake/UseOpenSSL.cmake b/cmake/UseOpenSSL.cmake new file mode 100644 index 0000000..d79ae38 --- /dev/null +++ b/cmake/UseOpenSSL.cmake @@ -0,0 +1,14 @@ +function(eth_apply TARGET REQUIRED) + find_package (OpenSSL) + + # cmake supplied FindOpenSSL doesn't set all our variables + set(OPENSSL_INCLUDE_DIRS ${OPENSSL_INCLUDE_DIR}) + + eth_show_dependency(OPENSSL OpenSSL) + if (OPENSSL_FOUND) + target_include_directories(${TARGET} SYSTEM PUBLIC ${OPENSSL_INCLUDE_DIRS}) + target_link_libraries(${TARGET} ${OPENSSL_LIBRARIES}) + elseif (NOT ${REQUIRED} STREQUAL "OPTIONAL") + message(FATAL_ERROR "OpenSSL library not found") + endif() +endfunction() diff --git a/cmake/UseSSH2.cmake b/cmake/UseSSH2.cmake new file mode 100644 index 0000000..1589754 --- /dev/null +++ b/cmake/UseSSH2.cmake @@ -0,0 +1,11 @@ +function(eth_apply TARGET REQUIRED) + find_package (SSH2) + eth_show_dependency(SSH2 ssh2) + + if (SSH2_FOUND) + target_include_directories(${TARGET} SYSTEM PUBLIC ${SSH2_INCLUDE_DIRS}) + target_link_libraries(${TARGET} ${SSH2_LIBRARIES}) + elseif (NOT ${REQUIRED} STREQUAL "OPTIONAL") + message(FATAL_ERROR "ssh2 library not found") + endif() +endfunction() diff --git a/cmake/UseZLIB.cmake b/cmake/UseZLIB.cmake new file mode 100644 index 0000000..d11010a --- /dev/null +++ b/cmake/UseZLIB.cmake @@ -0,0 +1,11 @@ +function(eth_apply TARGET REQUIRED) + find_package (ZLIB) + eth_show_dependency(ZLIB Zlib) + if (ZLIB_FOUND) + target_include_directories(${TARGET} SYSTEM PUBLIC ${ZLIB_INCLUDE_DIRS}) + # target_link_libraries(${TARGET} ${ZLIB_LIBRARIES}) + target_link_libraries(${TARGET} z) + elseif (NOT ${REQUIRED} STREQUAL "OPTIONAL") + message(FATAL_ERROR "Zlib library not found") + endif() +endfunction()