Skip to content

Commit a0b0b80

Browse files
committed
cmake: Allow user to select bundled zlib
Under some circumstances the installed / system version of zlib may not be desirable due to being too old or buggy. This patch adds the option `USE_BUNDLED_ZLIB` that will cause the bundled version of zlib to be used. We may also want to add similar functionality to allow the user to select other bundled 3rd-party dependencies instead of using the system versions. /cc @pks-t @ethomson
1 parent 0393ecc commit a0b0b80

File tree

2 files changed

+17
-12
lines changed

2 files changed

+17
-12
lines changed

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ OPTION( ENABLE_WERROR "Enable compilation with -Werror" OFF )
5555
IF (UNIX AND NOT APPLE)
5656
OPTION( ENABLE_REPRODUCIBLE_BUILDS "Enable reproducible builds" OFF )
5757
ENDIF()
58+
OPTION( USE_BUNDLED_ZLIB "Use the bundled version of zlib" OFF )
5859

5960
IF(MSVC)
6061
# This option is only available when building with MSVC. By default, libgit2

src/CMakeLists.txt

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -255,23 +255,27 @@ ELSE()
255255
ENDIF()
256256

257257
# Optional external dependency: zlib
258-
FIND_PACKAGE(ZLIB)
259-
IF (ZLIB_FOUND)
260-
LIST(APPEND LIBGIT2_INCLUDES ${ZLIB_INCLUDE_DIRS})
261-
LIST(APPEND LIBGIT2_LIBS ${ZLIB_LIBRARIES})
262-
IF(APPLE OR CMAKE_SYSTEM_NAME MATCHES "FreeBSD")
263-
LIST(APPEND LIBGIT2_LIBS "z")
264-
LIST(APPEND LIBGIT2_PC_LIBS "-lz")
258+
IF(NOT USE_BUNDLED_ZLIB)
259+
FIND_PACKAGE(ZLIB)
260+
IF(ZLIB_FOUND)
261+
LIST(APPEND LIBGIT2_INCLUDES ${ZLIB_INCLUDE_DIRS})
262+
LIST(APPEND LIBGIT2_LIBS ${ZLIB_LIBRARIES})
263+
IF(APPLE OR CMAKE_SYSTEM_NAME MATCHES "FreeBSD")
264+
LIST(APPEND LIBGIT2_LIBS "z")
265+
LIST(APPEND LIBGIT2_PC_LIBS "-lz")
266+
ELSE()
267+
SET(LIBGIT2_PC_REQUIRES "${LIBGIT2_PC_REQUIRES} zlib")
268+
ENDIF()
269+
ADD_FEATURE_INFO(zlib ON "using system zlib")
265270
ELSE()
266-
SET(LIBGIT2_PC_REQUIRES "${LIBGIT2_PC_REQUIRES} zlib")
271+
MESSAGE(STATUS "zlib was not found; using bundled 3rd-party sources." )
267272
ENDIF()
268-
ADD_FEATURE_INFO(zlib ON "Zlib support")
269-
ELSE()
270-
MESSAGE(STATUS "zlib was not found; using bundled 3rd-party sources." )
273+
ENDIF()
274+
IF(USE_BUNDLED_ZLIB OR NOT ZLIB_FOUND)
271275
ADD_SUBDIRECTORY("${libgit2_SOURCE_DIR}/deps/zlib" "${libgit2_BINARY_DIR}/deps/zlib")
272276
LIST(APPEND LIBGIT2_INCLUDES "${libgit2_SOURCE_DIR}/deps/zlib")
273277
LIST(APPEND LIBGIT2_OBJECTS $<TARGET_OBJECTS:zlib>)
274-
ADD_FEATURE_INFO(zlib ON "Zlib support (bundled)")
278+
ADD_FEATURE_INFO(zlib ON "using bundled zlib")
275279
ENDIF()
276280

277281
# Optional external dependency: libssh2

0 commit comments

Comments
 (0)