Skip to content

Commit 1ecda61

Browse files
committed
Set the correct dependencies in the pkg-config file
When linking statically, the including project needs to know what the current library build depends on so they can link to it. Store this information in the pkg-config file. While here, remove claims that users need to link to zlib or libcrypto.
1 parent 98fec8a commit 1ecda61

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

CMakeLists.txt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,15 @@ IF(MSVC)
5050
OPTION( STATIC_CRT "Link the static CRT libraries" ON )
5151
ENDIF()
5252

53+
# This variable will contain the libraries we need to put into
54+
# libgit2.pc's Requires.private. That is, what we're linking to or
55+
# what someone who's statically linking us needs to link to.
56+
SET(LIBGIT2_PC_REQUIRES "")
57+
# This will be set later if we use the system's http-parser library or
58+
# use iconv (OSX) and will be written to the Libs.private field in the
59+
# pc file.
60+
SET(LIBGIT2_PC_LIBS "")
61+
5362
# Installation paths
5463
#
5564
SET(BIN_INSTALL_DIR bin CACHE PATH "Where to install binaries to.")
@@ -68,6 +77,7 @@ FUNCTION(TARGET_OS_LIBRARIES target)
6877
IF(USE_ICONV)
6978
TARGET_LINK_LIBRARIES(${target} iconv)
7079
ADD_DEFINITIONS(-DGIT_USE_ICONV)
80+
SET(LIBGIT2_PC_LIBS "${LIBGIT2_PC_LIBS} -liconv")
7181
ENDIF()
7282

7383
IF(THREADSAFE)
@@ -119,6 +129,7 @@ ELSE ()
119129
IF (HTTP_PARSER_FOUND AND HTTP_PARSER_VERSION_MAJOR EQUAL 2)
120130
INCLUDE_DIRECTORIES(${HTTP_PARSER_INCLUDE_DIRS})
121131
LINK_LIBRARIES(${HTTP_PARSER_LIBRARIES})
132+
SET(LIBGIT2_PC_LIBS "${LIBGIT2_PC_LIBS} -lhttp_parser")
122133
ELSE()
123134
MESSAGE("http-parser was not found or is too old; using bundled 3rd-party sources.")
124135
INCLUDE_DIRECTORIES(deps/http-parser)
@@ -132,6 +143,7 @@ IF (WIN32 AND NOT MINGW AND NOT SHA1_TYPE STREQUAL "builtin")
132143
FILE(GLOB SRC_SHA1 src/hash/hash_win32.c)
133144
ELSEIF (OPENSSL_FOUND AND NOT SHA1_TYPE STREQUAL "builtin")
134145
ADD_DEFINITIONS(-DOPENSSL_SHA1)
146+
SET(LIBGIT2_PC_REQUIRES "${LIBGIT2_PC_REQUIRES} openssl")
135147
ELSE()
136148
FILE(GLOB SRC_SHA1 src/hash/hash_generic.c)
137149
ENDIF()
@@ -154,6 +166,7 @@ FIND_PACKAGE(ZLIB QUIET)
154166
IF (ZLIB_FOUND)
155167
INCLUDE_DIRECTORIES(${ZLIB_INCLUDE_DIRS})
156168
LINK_LIBRARIES(${ZLIB_LIBRARIES})
169+
SET(LIBGIT2_PC_REQUIRES "${LIBGIT2_PC_REQUIRES} zlib")
157170
# Fake the message CMake would have shown
158171
MESSAGE("-- Found zlib: ${ZLIB_LIBRARY}")
159172
ELSE()
@@ -169,6 +182,7 @@ ENDIF()
169182
IF (LIBSSH2_FOUND)
170183
ADD_DEFINITIONS(-DGIT_SSH)
171184
INCLUDE_DIRECTORIES(${LIBSSH2_INCLUDE_DIR})
185+
SET(LIBGIT2_PC_REQUIRES "${LIBGIT2_PC_REQUIRES} libssh2")
172186
SET(SSH_LIBRARIES ${LIBSSH2_LIBRARIES})
173187
ENDIF()
174188

libgit2.pc.in

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ includedir=@CMAKE_INSTALL_PREFIX@/@INCLUDE_INSTALL_DIR@
44
Name: libgit2
55
Description: The git library, take 2
66
Version: @LIBGIT2_VERSION_STRING@
7-
Requires: libcrypto
8-
Libs: -L${libdir} -lgit2 -lz -lcrypto
7+
Requires.private: @LIBGIT2_PC_REQUIRES@
8+
Libs.private: @LIBGIT2_PC_LIBS@
9+
Libs: -L${libdir} -lgit2
910
Cflags: -I${includedir}

0 commit comments

Comments
 (0)