8000 cmake: setup required libraries before checking function · tiennou/libgit2@df2ff6f · GitHub
[go: up one dir, main page]

Skip to content

Commit df2ff6f

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 6311e88 commit df2ff6f

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

src/CMakeLists.txt

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,18 @@ 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+
SET(CMAKE_REQUIRED_LIBRARIES_OLD ${CMAKE_REQUIRED_LIBRARIES})
297+
IF(BUILD_SHARED_LIBS)
298+
SET(CMAKE_REQUIRED_LIBRARIES ${LIBSSH2_LIBRARIES})
299+
SET(LIBSSH2_TMP_LIBRARY_DIRS ${LIBSSH2_LIBRARY_DIRS})
300+
ELSE()
301+
SET(CMAKE_REQUIRED_LIBRARIES ${LIBSSH2_STATIC_LIBRARIES})
302+
SET(LIBSSH2_TMP_LIBRARY_DIRS ${LIBSSH2_STATIC_LIBRARY_DIRS})
303+
ENDIF()
304+
CHECK_LIBRARY_EXISTS(ssh2 libssh2_userauth_publickey_frommemory "${LIBSSH2_TMP_LIBRARY_DIRS}" HAVE_LIBSSH2_MEMORY_CREDENTIALS)
305+
SET(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES_OLD})
306+
UNSET(LIBSSH2_TMP_LIBRARY_DIRS)
296307
IF (HAVE_LIBSSH2_MEMORY_CREDENTIALS)
297308
SET(GIT_SSH_MEMORY_CREDENTIALS 1)
298309
ENDIF()

0 commit comments

Comments
 (0)
0