summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHenry Kleynhans <hkleynhans@bloomberg.net>2017-11-11 14:03:14 +0000
committerHenry Kleynhans <hkleynhans@bloomberg.net>2017-11-11 16:43:37 +0000
commita0b0b80862d4fb471be66643fe695c23f7755bd8 (patch)
tree6bdecc465d80b40ceae4de7cede83c403ca8cdee
parent0393ecc6f8bb19e4ba55fd45e7bbde6596f9b334 (diff)
downloadlibgit2-a0b0b80862d4fb471be66643fe695c23f7755bd8.tar.gz
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
-rw-r--r--CMakeLists.txt1
-rw-r--r--src/CMakeLists.txt28
2 files changed, 17 insertions, 12 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 58032ac53..549f34ad8 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 3c04f8ae4..e456ab725 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