Skip to content

Commit 79c5fd3

Browse files
committed
cmake: setup required libraries before checking function
As per the docs[1], another set of variables will be provided by PKG_CHECK_MODULES when static linking (with the additional libraries required for static links). We need to pass those libraries to CHECK_LIBRARY_EXISTS so *its* link succeeds. 1 - https://cmake.org/cmake/help/v3.1/module/FindPkgConfig.html#command:pkg_check_modules Ref: libgit2/objective-git#645
1 parent 21b9973 commit 79c5fd3

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/CMakeLists.txt

+8-1
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,14 @@ IF (LIBSSH2_FOUND)
292292
LIST(APPEND LIBGIT2_PC_LIBS ${LIBSSH2_LDFLAGS})
293293
#SET(LIBGIT2_PC_LIBS "${LIBGIT2_PC_LIBS} ${LIBSSH2_LDFLAGS}")
294294

295-
CHECK_LIBRARY_EXISTS("${LIBSSH2_LIBRARIES}" libssh2_userauth_publickey_frommemory "${LIBSSH2_LIBRARY_DIRS}" HAVE_LIBSSH2_MEMORY_CREDENTIALS)
295+
# We might need to provide additional libraries so libssh2 links
296+
IF(BUILD_SHARED_LIBS)
297+
CHECK_LIBRARY_EXISTS(ssh2 libssh2_userauth_publickey_frommemory "${LIBSSH2_LIBRARY_DIRS}" HAVE_LIBSSH2_MEMORY_CREDENTIALS)
298+
ELSE()
299+
SET(CMAKE_REQUIRED_LIBRARIES ${LIBSSH2_STATIC_LIBRARIES})
300+
CHECK_LIBRARY_EXISTS(ssh2 libssh2_userauth_publickey_frommemory "${LIBSSH2_STATIC_LIBRARY_DIRS}" HAVE_LIBSSH2_MEMORY_CREDENTIALS)
301+
UNSET(CMAKE_REQUIRED_LIBRARIES)
302+
ENDIF()
296303
IF (HAVE_LIBSSH2_MEMORY_CREDENTIALS)
297304
SET(GIT_SSH_MEMORY_CREDENTIALS 1)
298305
ENDIF()

0 commit comments

Comments
 (0)