cmake: simplify compression selection

This commit is contained in:
Edward Thomson
2024-12-22 12:32:10 +00:00
parent c4a65c34c2
commit fdb73f5d1d
4 changed files with 55 additions and 40 deletions

View File

@@ -38,7 +38,7 @@ option(USE_GSSAPI "Enable SPNEGO authentication using GSSAPI" OFF)
set(USE_HTTP_PARSER "" CACHE STRING "Selects HTTP Parser support: http-parser, llhttp, or builtin. (Defaults to builtin.)")
# set(USE_XDIFF "" CACHE STRING "Specifies the xdiff implementation; either system or builtin.")
set(REGEX_BACKEND "" CACHE STRING "Selects regex provider. One of regcomp_l, pcre2, pcre, regcomp, or builtin.")
option(USE_BUNDLED_ZLIB "Use the bundled version of zlib. Can be set to one of Bundled(ON)/Chromium. The Chromium option requires a x86_64 processor with SSE4.2 and CLMUL" OFF)
set(USE_COMPRESSION "" CACHE STRING "Selects compression backend. Either builtin or zlib.")
# Debugging options
option(USE_LEAK_CHECKER "Run tests with leak checker" OFF)

View File

@@ -0,0 +1,53 @@
include(SanitizeBool)
# Fall back to the previous cmake configuration, "USE_BUNDLED_ZLIB"
if(NOT USE_COMPRESSION AND USE_BUNDLED_ZLIB)
SanitizeBool(USE_BUNDLED_ZLIB)
if(USE_BUNDLED_ZLIB STREQUAL ON)
set(USE_COMPRESSION "builtin")
elseif(USE_BUNDLED_ZLIB STREQUAL OFF)
set(USE_COMPRESSION "zlib")
else()
message(FATAL_ERROR "unknown setting to USE_BUNDLED_ZLIB: ${USE_BUNDLED_ZLIB}")
endif()
endif()
if(NOT USE_COMPRESSION)
find_package(ZLIB)
if(ZLIB_FOUND)
set(GIT_COMPRESSION_ZLIB 1)
else()
message(STATUS "zlib was not found; using bundled 3rd-party sources." )
set(GIT_COMPRESSION_BUILTIN 1)
endif()
elseif(USE_COMPRESSION STREQUAL "zlib")
find_package(ZLIB)
if(NOT ZLIB_FOUND)
message(FATAL_ERROR "system zlib was requested but not found")
endif()
set(GIT_COMPRESSION_ZLIB 1)
elseif(USE_COMPRESSION STREQUAL "builtin")
set(GIT_COMPRESSION_BUILTIN 1)
endif()
if(GIT_COMPRESSION_ZLIB)
list(APPEND LIBGIT2_SYSTEM_INCLUDES ${ZLIB_INCLUDE_DIRS})
list(APPEND LIBGIT2_SYSTEM_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(compression ON "using system zlib")
elseif(GIT_COMPRESSION_BUILTIN)
add_subdirectory("${PROJECT_SOURCE_DIR}/deps/zlib" "${PROJECT_BINARY_DIR}/deps/zlib")
list(APPEND LIBGIT2_DEPENDENCY_INCLUDES "${PROJECT_SOURCE_DIR}/deps/zlib")
list(APPEND LIBGIT2_DEPENDENCY_OBJECTS $<TARGET_OBJECTS:zlib>)
add_feature_info(compression ON "using bundled zlib")
else()
message(FATAL_ERROR "unknown compression backend")
endif()

View File

@@ -1,38 +0,0 @@
# Optional external dependency: zlib
include(SanitizeBool)
SanitizeBool(USE_BUNDLED_ZLIB)
if(USE_BUNDLED_ZLIB STREQUAL ON)
set(USE_BUNDLED_ZLIB "Bundled")
set(GIT_COMPRESSION_BUILTIN)
endif()
if(USE_BUNDLED_ZLIB STREQUAL "OFF")
find_package(ZLIB)
if(ZLIB_FOUND)
list(APPEND LIBGIT2_SYSTEM_INCLUDES ${ZLIB_INCLUDE_DIRS})
list(APPEND LIBGIT2_SYSTEM_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")
set(GIT_COMPRESSION_ZLIB 1)
else()
message(STATUS "zlib was not found; using bundled 3rd-party sources." )
endif()
endif()
if(USE_BUNDLED_ZLIB STREQUAL "Chromium")
add_subdirectory("${PROJECT_SOURCE_DIR}/deps/chromium-zlib" "${PROJECT_BINARY_DIR}/deps/chromium-zlib")
list(APPEND LIBGIT2_DEPENDENCY_INCLUDES "${PROJECT_SOURCE_DIR}/deps/chromium-zlib")
list(APPEND LIBGIT2_DEPENDENCY_OBJECTS $<TARGET_OBJECTS:chromium_zlib>)
add_feature_info(zlib ON "using (Chromium) bundled zlib")
set(GIT_COMPRESSION_BUILTIN 1)
elseif(USE_BUNDLED_ZLIB OR NOT ZLIB_FOUND)
add_subdirectory("${PROJECT_SOURCE_DIR}/deps/zlib" "${PROJECT_BINARY_DIR}/deps/zlib")
list(APPEND LIBGIT2_DEPENDENCY_INCLUDES "${PROJECT_SOURCE_DIR}/deps/zlib")
list(APPEND LIBGIT2_DEPENDENCY_OBJECTS $<TARGET_OBJECTS:zlib>)
add_feature_info(zlib ON "using bundled zlib")
set(GIT_COMPRESSION_BUILTIN 1)
endif()

View File

@@ -43,7 +43,7 @@ include(SelectHTTPParser)
include(SelectRegex)
include(SelectXdiff)
include(SelectSSH)
include(SelectZlib)
include(SelectCompression)
#
# Platform support