Merge pull request #4403 from hkleynhans/select_bundled_zlib cmake: Allow user to select bundled zlib
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 58032ac..549f34a 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -55,6 +55,7 @@ OPTION( ENABLE_WERROR "Enable compilation with -Werror" OFF )
IF (UNIX AND NOT APPLE)
OPTION( ENABLE_REPRODUCIBLE_BUILDS "Enable reproducible builds" OFF )
ENDIF()
+OPTION( USE_BUNDLED_ZLIB "Use the bundled version of zlib" OFF )
IF(MSVC)
# This option is only available when building with MSVC. By default, libgit2
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 3c04f8a..e456ab7 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -255,23 +255,27 @@ ELSE()
ENDIF()
# Optional external dependency: zlib
-FIND_PACKAGE(ZLIB)
-IF (ZLIB_FOUND)
- LIST(APPEND LIBGIT2_INCLUDES ${ZLIB_INCLUDE_DIRS})
- LIST(APPEND LIBGIT2_LIBS ${ZLIB_LIBRARIES})
- IF(APPLE OR CMAKE_SYSTEM_NAME MATCHES "FreeBSD")
- LIST(APPEND LIBGIT2_LIBS "z")
- LIST(APPEND LIBGIT2_PC_LIBS "-lz")
+IF(NOT USE_BUNDLED_ZLIB)
+ FIND_PACKAGE(ZLIB)
+ IF(ZLIB_FOUND)
+ LIST(APPEND LIBGIT2_INCLUDES ${ZLIB_INCLUDE_DIRS})
+ LIST(APPEND LIBGIT2_LIBS ${ZLIB_LIBRARIES})
+ IF(APPLE OR CMAKE_SYSTEM_NAME MATCHES "FreeBSD")
+ LIST(APPEND LIBGIT2_LIBS "z")
+ LIST(APPEND LIBGIT2_PC_LIBS "-lz")
+ ELSE()
+ SET(LIBGIT2_PC_REQUIRES "${LIBGIT2_PC_REQUIRES} zlib")
+ ENDIF()
+ ADD_FEATURE_INFO(zlib ON "using system zlib")
ELSE()
- SET(LIBGIT2_PC_REQUIRES "${LIBGIT2_PC_REQUIRES} zlib")
+ MESSAGE(STATUS "zlib was not found; using bundled 3rd-party sources." )
ENDIF()
- ADD_FEATURE_INFO(zlib ON "Zlib support")
-ELSE()
- MESSAGE(STATUS "zlib was not found; using bundled 3rd-party sources." )
+ENDIF()
+IF(USE_BUNDLED_ZLIB OR NOT ZLIB_FOUND)
ADD_SUBDIRECTORY("${libgit2_SOURCE_DIR}/deps/zlib" "${libgit2_BINARY_DIR}/deps/zlib")
LIST(APPEND LIBGIT2_INCLUDES "${libgit2_SOURCE_DIR}/deps/zlib")
LIST(APPEND LIBGIT2_OBJECTS $<TARGET_OBJECTS:zlib>)
- ADD_FEATURE_INFO(zlib ON "Zlib support (bundled)")
+ ADD_FEATURE_INFO(zlib ON "using bundled zlib")
ENDIF()
# Optional external dependency: libssh2