cmake: refactor libssh2 selection Move SSH selection into its own cmake module.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92
diff --git a/cmake/SelectSSH.cmake b/cmake/SelectSSH.cmake
new file mode 100644
index 0000000..0356ee3
--- /dev/null
+++ b/cmake/SelectSSH.cmake
@@ -0,0 +1,41 @@
+# Optional external dependency: libssh2
+if(USE_SSH)
+ find_pkglibraries(LIBSSH2 libssh2)
+ if(NOT LIBSSH2_FOUND)
+ find_package(LibSSH2)
+ set(LIBSSH2_INCLUDE_DIRS ${LIBSSH2_INCLUDE_DIR})
+ get_filename_component(LIBSSH2_LIBRARY_DIRS "${LIBSSH2_LIBRARY}" DIRECTORY)
+ set(LIBSSH2_LIBRARIES ${LIBSSH2_LIBRARY})
+ set(LIBSSH2_LDFLAGS "-lssh2")
+ endif()
+
+ if(NOT LIBSSH2_FOUND)
+ message(FATAL_ERROR "LIBSSH2 not found. Set CMAKE_PREFIX_PATH if it is installed outside of the default search path.")
+ endif()
+endif()
+
+if(LIBSSH2_FOUND)
+ set(GIT_SSH 1)
+ list(APPEND LIBGIT2_SYSTEM_INCLUDES ${LIBSSH2_INCLUDE_DIRS})
+ list(APPEND LIBGIT2_LIBS ${LIBSSH2_LIBRARIES})
+ list(APPEND LIBGIT2_PC_LIBS ${LIBSSH2_LDFLAGS})
+
+ check_library_exists("${LIBSSH2_LIBRARIES}" libssh2_userauth_publickey_frommemory "${LIBSSH2_LIBRARY_DIRS}" HAVE_LIBSSH2_MEMORY_CREDENTIALS)
+ if(HAVE_LIBSSH2_MEMORY_CREDENTIALS)
+ set(GIT_SSH_MEMORY_CREDENTIALS 1)
+ endif()
+else()
+ message(STATUS "LIBSSH2 not found. Set CMAKE_PREFIX_PATH if it is installed outside of the default search path.")
+endif()
+
+if(WIN32 AND EMBED_SSH_PATH)
+ file(GLOB SSH_SRC "${EMBED_SSH_PATH}/src/*.c")
+ list(SORT SSH_SRC)
+ list(APPEND LIBGIT2_OBJECTS ${SSH_SRC})
+
+ list(APPEND LIBGIT2_INCLUDES "${EMBED_SSH_PATH}/include")
+ file(WRITE "${EMBED_SSH_PATH}/src/libssh2_config.h" "#define HAVE_WINCNG\n#define LIBSSH2_WINCNG\n#include \"../win32/libssh2_config.h\"")
+ set(GIT_SSH 1)
+endif()
+
+add_feature_info(SSH GIT_SSH "SSH transport support")
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 5c2c527..819fc42 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -115,6 +115,7 @@ include(SelectHTTPSBackend)
include(SelectHashes)
include(SelectHTTPParser)
include(SelectRegex)
+include(SelectSSH)
target_sources(git2internal PRIVATE ${SRC_SHA1})
@@ -151,32 +152,6 @@ elseif(USE_BUNDLED_ZLIB OR NOT ZLIB_FOUND)
add_feature_info(zlib ON "using bundled zlib")
endif()
-# Optional external dependency: libssh2
-if(USE_SSH)
- find_pkglibraries(LIBSSH2 libssh2)
- if(NOT LIBSSH2_FOUND)
- find_package(LibSSH2)
- set(LIBSSH2_INCLUDE_DIRS ${LIBSSH2_INCLUDE_DIR})
- get_filename_component(LIBSSH2_LIBRARY_DIRS "${LIBSSH2_LIBRARY}" DIRECTORY)
- set(LIBSSH2_LIBRARIES ${LIBSSH2_LIBRARY})
- set(LIBSSH2_LDFLAGS "-lssh2")
- endif()
-endif()
-if(LIBSSH2_FOUND)
- set(GIT_SSH 1)
- list(APPEND LIBGIT2_SYSTEM_INCLUDES ${LIBSSH2_INCLUDE_DIRS})
- list(APPEND LIBGIT2_LIBS ${LIBSSH2_LIBRARIES})
- list(APPEND LIBGIT2_PC_LIBS ${LIBSSH2_LDFLAGS})
-
- check_library_exists("${LIBSSH2_LIBRARIES}" libssh2_userauth_publickey_frommemory "${LIBSSH2_LIBRARY_DIRS}" HAVE_LIBSSH2_MEMORY_CREDENTIALS)
- if(HAVE_LIBSSH2_MEMORY_CREDENTIALS)
- set(GIT_SSH_MEMORY_CREDENTIALS 1)
- endif()
-else()
- message(STATUS "LIBSSH2 not found. Set CMAKE_PREFIX_PATH if it is installed outside of the default search path.")
-endif()
-add_feature_info(SSH GIT_SSH "SSH transport support")
-
# Optional external dependency: ntlmclient
if(USE_NTLMCLIENT)
set(GIT_NTLM 1)