Skip to content

Commit e35a22a

Browse files
committed
cmake: refactor libssh2 selection
Move SSH selection into its own cmake module.
1 parent f0cb378 commit e35a22a

File tree

2 files changed

+42
-26
lines changed

2 files changed

+42
-26
lines changed

cmake/SelectSSH.cmake

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# Optional external dependency: libssh2
2+
if(USE_SSH)
3+
find_pkglibraries(LIBSSH2 libssh2)
4+
if(NOT LIBSSH2_FOUND)
5+
find_package(LibSSH2)
6+
set(LIBSSH2_INCLUDE_DIRS ${LIBSSH2_INCLUDE_DIR})
7+
get_filename_component(LIBSSH2_LIBRARY_DIRS "${LIBSSH2_LIBRARY}" DIRECTORY)
8+
set(LIBSSH2_LIBRARIES ${LIBSSH2_LIBRARY})
9+
set(LIBSSH2_LDFLAGS "-lssh2")
10+
endif()
11+
12+
if(NOT LIBSSH2_FOUND)
13+
message(FATAL_ERROR "LIBSSH2 not found. Set CMAKE_PREFIX_PATH if it is installed outside of the default search path.")
14+
endif()
15+
endif()
16+
17+
if(LIBSSH2_FOUND)
18+
set(GIT_SSH 1)
19+
list(APPEND LIBGIT2_SYSTEM_INCLUDES ${LIBSSH2_INCLUDE_DIRS})
20+
list(APPEND LIBGIT2_LIBS ${LIBSSH2_LIBRARIES})
21+
list(APPEND LIBGIT2_PC_LIBS ${LIBSSH2_LDFLAGS})
22+
23+
check_library_exists("${LIBSSH2_LIBRARIES}" libssh2_userauth_publickey_frommemory "${LIBSSH2_LIBRARY_DIRS}" HAVE_LIBSSH2_MEMORY_CREDENTIALS)
24+
if(HAVE_LIBSSH2_MEMORY_CREDENTIALS)
25+
set(GIT_SSH_MEMORY_CREDENTIALS 1)
26+
endif()
27+
else()
28+
message(STATUS "LIBSSH2 not found. Set CMAKE_PREFIX_PATH if it is installed outside of the default search path.")
29+
endif()
30+
31+
if(WIN32 AND EMBED_SSH_PATH)
32+
file(GLOB SSH_SRC "${EMBED_SSH_PATH}/src/*.c")
33+
list(SORT SSH_SRC)
34+
list(APPEND LIBGIT2_OBJECTS ${SSH_SRC})
35+
36+
list(APPEND LIBGIT2_INCLUDES "${EMBED_SSH_PATH}/include")
37+
file(WRITE "${EMBED_SSH_PATH}/src/libssh2_config.h" "#define HAVE_WINCNG\n#define LIBSSH2_WINCNG\n#include \"../win32/libssh2_config.h\"")
38+
set(GIT_SSH 1)
39+
endif()
40+
41+
add_feature_info(SSH GIT_SSH "SSH transport support")

src/CMakeLists.txt

Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ include(SelectHTTPSBackend)
115115
include(SelectHashes)
116116
include(SelectHTTPParser)
117117
include(SelectRegex)
118+
include(SelectSSH)
118119

119120
target_sources(git2internal PRIVATE ${SRC_SHA1})
120121

@@ -151,32 +152,6 @@ elseif(USE_BUNDLED_ZLIB OR NOT ZLIB_FOUND)
151152
add_feature_info(zlib ON "using bundled zlib")
152153
endif()
153154

154-
# Optional external dependency: libssh2
155-
if(USE_SSH)
156-
find_pkglibraries(LIBSSH2 libssh2)
157-
if(NOT LIBSSH2_FOUND)
158-
find_package(LibSSH2)
159-
set(LIBSSH2_INCLUDE_DIRS ${LIBSSH2_INCLUDE_DIR})
160-
get_filename_component(LIBSSH2_LIBRARY_DIRS "${LIBSSH2_LIBRARY}" DIRECTORY)
161-
set(LIBSSH2_LIBRARIES ${LIBSSH2_LIBRARY})
162-
set(LIBSSH2_LDFLAGS "-lssh2")
163-
endif()
164-
endif()
165-
if(LIBSSH2_FOUND)
166-
set(GIT_SSH 1)
167-
list(APPEND LIBGIT2_SYSTEM_INCLUDES ${LIBSSH2_INCLUDE_DIRS})
168-
list(APPEND LIBGIT2_LIBS ${LIBSSH2_LIBRARIES})
169-
list(APPEND LIBGIT2_PC_LIBS ${LIBSSH2_LDFLAGS})
170-
171-
check_library_exists("${LIBSSH2_LIBRARIES}" libssh2_userauth_publickey_frommemory "${LIBSSH2_LIBRARY_DIRS}" HAVE_LIBSSH2_MEMORY_CREDENTIALS)
172-
if(HAVE_LIBSSH2_MEMORY_CREDENTIALS)
173-
set(GIT_SSH_MEMORY_CREDENTIALS 1)
174-
endif()
175-
else()
176-
message(STATUS "LIBSSH2 not found. Set CMAKE_PREFIX_PATH if it is installed outside of the default search path.")
177-
endif()
178-
add_feature_info(SSH GIT_SSH "SSH transport support")
179-
180155
# Optional external dependency: ntlmclient
181156
if(USE_NTLMCLIENT)
182157
set(GIT_NTLM 1)

0 commit comments

Comments
 (0)