summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEdward Thomson <ethomson@edwardthomson.com>2021-11-10 21:59:46 -0500
committerEdward Thomson <ethomson@edwardthomson.com>2021-11-11 15:56:11 -0500
commit4e84ddd5b091b6e6e85ff6484e72d9f90da1c4b0 (patch)
treed7ae8252eb57398ed53fa60323c41b20662dc658
parent83fa548078b0b35030ba028676d6b5674d86ba18 (diff)
downloadlibgit2-4e84ddd5b091b6e6e85ff6484e72d9f90da1c4b0.tar.gz
cmake: refactor zlib selectionethomson/cmake3
Move zlib selection into its own cmake module.
-rw-r--r--cmake/SelectZlib.cmake34
-rw-r--r--src/CMakeLists.txt34
2 files changed, 35 insertions, 33 deletions
diff --git a/cmake/SelectZlib.cmake b/cmake/SelectZlib.cmake
new file mode 100644
index 000000000..2dfc6c86e
--- /dev/null
+++ b/cmake/SelectZlib.cmake
@@ -0,0 +1,34 @@
+# Optional external dependency: zlib
+include(SanitizeBool)
+
+SanitizeBool(USE_BUNDLED_ZLIB)
+if(USE_BUNDLED_ZLIB STREQUAL ON)
+ set(USE_BUNDLED_ZLIB "Bundled")
+endif()
+
+if(USE_BUNDLED_ZLIB STREQUAL "OFF")
+ find_package(ZLIB)
+ if(ZLIB_FOUND)
+ list(APPEND LIBGIT2_SYSTEM_INCLUDES ${ZLIB_INCLUDE_DIRS})
+ list(APPEND LIBGIT2_LIBS ${ZLIB_LIBRARIES})
+ if(APPLE OR CMAKE_SYSTEM_NAME MATCHES "FreeBSD")
+ list(APPEND LIBGIT2_PC_LIBS "-lz")
+ else()
+ list(APPEND LIBGIT2_PC_REQUIRES "zlib")
+ endif()
+ add_feature_info(zlib ON "using system zlib")
+ else()
+ message(STATUS "zlib was not found; using bundled 3rd-party sources." )
+ endif()
+endif()
+if(USE_BUNDLED_ZLIB STREQUAL "Chromium")
+ add_subdirectory("${libgit2_SOURCE_DIR}/deps/chromium-zlib" "${libgit2_BINARY_DIR}/deps/chromium-zlib")
+ list(APPEND LIBGIT2_INCLUDES "${libgit2_SOURCE_DIR}/deps/chromium-zlib")
+ list(APPEND LIBGIT2_OBJECTS $<TARGET_OBJECTS:chromium_zlib>)
+ add_feature_info(zlib ON "using (Chromium) bundled zlib")
+elseif(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 "using bundled zlib")
+endif()
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 8a57b2345..ae02ef9aa 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -99,42 +99,10 @@ include(SelectHTTPParser)
include(SelectRegex)
include(SelectSSH)
include(SelectWinHTTP)
+include(SelectZlib)
target_sources(git2internal PRIVATE ${SRC_SHA1})
-# Optional external dependency: zlib
-SanitizeBool(USE_BUNDLED_ZLIB)
-if(USE_BUNDLED_ZLIB STREQUAL ON)
- set(USE_BUNDLED_ZLIB "Bundled")
-endif()
-
-if(USE_BUNDLED_ZLIB STREQUAL "OFF")
- find_package(ZLIB)
- if(ZLIB_FOUND)
- list(APPEND LIBGIT2_SYSTEM_INCLUDES ${ZLIB_INCLUDE_DIRS})
- list(APPEND LIBGIT2_LIBS ${ZLIB_LIBRARIES})
- if(APPLE OR CMAKE_SYSTEM_NAME MATCHES "FreeBSD")
- list(APPEND LIBGIT2_PC_LIBS "-lz")
- else()
- list(APPEND LIBGIT2_PC_REQUIRES "zlib")
- endif()
- add_feature_info(zlib ON "using system zlib")
- else()
- message(STATUS "zlib was not found; using bundled 3rd-party sources." )
- endif()
-endif()
-if(USE_BUNDLED_ZLIB STREQUAL "Chromium")
- add_subdirectory("${libgit2_SOURCE_DIR}/deps/chromium-zlib" "${libgit2_BINARY_DIR}/deps/chromium-zlib")
- list(APPEND LIBGIT2_INCLUDES "${libgit2_SOURCE_DIR}/deps/chromium-zlib")
- list(APPEND LIBGIT2_OBJECTS $<TARGET_OBJECTS:chromium_zlib>)
- add_feature_info(zlib ON "using (Chromium) bundled zlib")
-elseif(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 "using bundled zlib")
-endif()
-
# Optional external dependency: ntlmclient
if(USE_NTLMCLIENT)
set(GIT_NTLM 1)