-
Notifications
You must be signed in to change notification settings - Fork 1.5k
[core] Make zlib a builtin obtained from the web and remove the vendored code #21613
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
dpiparo
wants to merge
2
commits into
root-project:master
Choose a base branch
from
dpiparo:builtin_zlib
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,140 +1,69 @@ | ||
| # Copyright (C) 1995-2019, Rene Brun and Fons Rademakers. | ||
| # Copyright (C) 1995-2026, Rene Brun and Fons Rademakers. | ||
| # All rights reserved. | ||
| # | ||
| # For the licensing terms see $ROOTSYS/LICENSE. | ||
| # For the list of contributors see $ROOTSYS/README/CREDITS. | ||
|
|
||
| project(ZLIB C) | ||
| # **PLEASE UPDATE ALSO THE FOLLOWING LINE WHEN UPDATING THE VERSION** | ||
| # 3 Feb 2026, https://github.com/zlib-ng/zlib-ng/releases/tag/2.3.3 | ||
| set(ROOT_ZLIB_VERSION 2.3.3) | ||
| set(ROOT_ZLIB_HASH "f9c65aa9c852eb8255b636fd9f07ce1c406f061ec19a2e7d508b318ca0c907d1") | ||
|
|
||
| set(ZLIB_PUBLIC_HEADERS | ||
| zconf.h | ||
| zlib.h | ||
| ) | ||
|
|
||
| set(ZLIB_PRIVATE_HEADERS | ||
| crc32.h | ||
| deflate.h | ||
| gzguts.h | ||
| inffast.h | ||
| inffixed.h | ||
| inflate.h | ||
| inftrees.h | ||
| trees.h | ||
| zutil.h | ||
| ) | ||
|
|
||
| set(ZLIBCF_PRIVATE_HEADERS | ||
| crc32.h | ||
| deflate_cf.h | ||
| gzguts.h | ||
| inffast.h | ||
| inffixed.h | ||
| inflate.h | ||
| inftrees.h | ||
| trees.h | ||
| zutil.h | ||
| ) | ||
|
|
||
| set(ZLIB_SOURCES | ||
| adler32.c | ||
| compress.c | ||
| crc32.c | ||
| deflate.c | ||
| gzclose.c | ||
| gzlib.c | ||
| gzread.c | ||
| gzwrite.c | ||
| inflate.c | ||
| infback.c | ||
| inftrees.c | ||
| inffast.c | ||
| trees.c | ||
| uncompr.c | ||
| zutil.c | ||
| ) | ||
|
|
||
| set(ZLIBCF_SOURCES | ||
| adler32_cf.c | ||
| compress.c | ||
| crc32_cf.c | ||
| deflate_cf.c | ||
| gzclose.c | ||
| gzlib.c | ||
| gzread.c | ||
| gzwrite.c | ||
| inflate.c | ||
| infback.c | ||
| inftrees.c | ||
| inffast.c | ||
| trees_cf.c | ||
| uncompr.c | ||
| zutil.c | ||
| ) | ||
|
|
||
| unset(ZLIB_FOUND CACHE) | ||
| unset(ZLIB_FOUND PARENT_SCOPE) | ||
| set(ZLIB_FOUND TRUE CACHE BOOL "" FORCE) | ||
|
|
||
| file(STRINGS zlib.h ZLIB_H REGEX "^#define ZLIB_VERSION \"[^\"]*\"$") | ||
| string(REGEX REPLACE "^.*ZLIB_VERSION \"([0-9]+).*$" "\\1" ZLIB_VERSION_MAJOR "${ZLIB_H}") | ||
| string(REGEX REPLACE "^.*ZLIB_VERSION \"[0-9]+\\.([0-9]+).*$" "\\1" ZLIB_VERSION_MINOR "${ZLIB_H}") | ||
| string(REGEX REPLACE "^.*ZLIB_VERSION \"[0-9]+\\.[0-9]+\\.([0-9]+).*$" "\\1" ZLIB_VERSION_PATCH "${ZLIB_H}") | ||
| set(ZLIB_VERSION_STRING "${ZLIB_VERSION_MAJOR}.${ZLIB_VERSION_MINOR}.${ZLIB_VERSION_PATCH}") | ||
|
|
||
| set(ZLIB_VERSION_TWEAK "") | ||
| if("${ZLIB_H}" MATCHES "ZLIB_VERSION \"[0-9]+\\.[0-9]+\\.[0-9]+\\.([0-9]+)") | ||
| set(ZLIB_VERSION_TWEAK "${CMAKE_MATCH_1}") | ||
| string(APPEND ZLIB_VERSION_STRING ".${ZLIB_VERSION_TWEAK}") | ||
| endif() | ||
| set(ROOT_ZLIB_PREFIX ${CMAKE_BINARY_DIR}/builtins/ZLIB-prefix PARENT_SCOPE) | ||
| set(ROOT_ZLIB_PREFIX ${CMAKE_BINARY_DIR}/builtins/ZLIB-prefix) | ||
|
|
||
| set(ZLIB_VERSION ${ZLIB_VERSION_STRING} CACHE INTERNAL "") | ||
| set(ZLIB_VERSION_STRING ${ZLIB_VERSION_STRING} CACHE INTERNAL "") | ||
|
|
||
| set(ZLIB_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR} CACHE INTERNAL "") | ||
| set(ZLIB_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR} CACHE INTERNAL "") | ||
|
|
||
| if((CMAKE_SYSTEM_PROCESSOR MATCHES "amd64|x86_64|AMD64|X86_64|aarch64") AND (CMAKE_SYSTEM_NAME MATCHES "Linux")) | ||
| # Calling helper to avoid using old unsupported binutils (e.g. with SL6) | ||
| # macro is returning extra ${ROOT_DEFINITIONS} used after in ZLIB-CF | ||
| root_check_assembler() | ||
| # Calling helper to avoid using old unsupported binutils (e.g. with Centos7 | ||
| # and native gcc compiler 4.8.5) | ||
| # Macros are returning bools SSE_SUPPORT & AVX2_SUPPORT | ||
| root_check_sse41() | ||
| root_check_avx2() | ||
| if(SSE_SUPPORT OR AVX2_SUPPORT) | ||
| set(ZLIB_CF TRUE CACHE INTERNAL "") | ||
| endif() | ||
| endif() | ||
|
|
||
| if(ZLIB_CF) | ||
| add_library(ZLIB STATIC ${ZLIB_PUBLIC_HEADERS} ${ZLIBCF_PRIVATE_HEADERS} ${ZLIBCF_SOURCES}) | ||
| # Here we need two cases because the library has two different names on Linux/macOS and Windows | ||
| if(MSVC) | ||
| set(ROOT_ZLIB_LIBRARY ${ROOT_ZLIB_PREFIX}/lib/zlibstatic${CMAKE_STATIC_LIBRARY_SUFFIX}) | ||
| else() | ||
| add_library(ZLIB STATIC ${ZLIB_PUBLIC_HEADERS} ${ZLIB_PRIVATE_HEADERS} ${ZLIB_SOURCES}) | ||
| set(ROOT_ZLIB_LIBRARY ${ROOT_ZLIB_PREFIX}/lib/${CMAKE_STATIC_LIBRARY_PREFIX}z${CMAKE_STATIC_LIBRARY_SUFFIX}) | ||
| endif() | ||
|
|
||
| set_target_properties(ZLIB PROPERTIES C_VISIBILITY_PRESET hidden POSITION_INDEPENDENT_CODE ON) | ||
| target_include_directories(ZLIB INTERFACE $<BUILD_INTERFACE:${ZLIB_INCLUDE_DIR}>) | ||
|
|
||
| if((CMAKE_SYSTEM_PROCESSOR MATCHES "amd64|x86_64|AMD64|X86_64") AND (CMAKE_SYSTEM_NAME MATCHES "Linux")) | ||
| target_compile_options(ZLIB PRIVATE -Wno-unused-function -O3 -mpclmul -Wno-attribute-alias ${ROOT_DEFINITIONS}) | ||
| else() | ||
| if(NOT MSVC) | ||
| target_compile_options(ZLIB PRIVATE -O3) | ||
| endif() | ||
| if(MSVC) | ||
| # In the MSVC case, we forward the default C++ configuration flags because | ||
| # they are changed by ROOT in SetUpWindows.cmake. | ||
| set(zlib_extra_cmake_args | ||
| -DCMAKE_CXXFLAGS_RELWITHDEBINFO=${CMAKE_CXX_FLAGS_RELWITHDEBINFO} | ||
| -DCMAKE_CXXFLAGS_RELEASE=${CMAKE_CXX_FLAGS_RELEASE} | ||
| -DCMAKE_CXXFLAGS_DEBUG=${CMAKE_CXX_FLAGS_DEBUG}) | ||
| endif() | ||
|
|
||
| add_library(ZLIB::ZLIB ALIAS ZLIB) | ||
| ExternalProject_Add( | ||
| BUILTIN_ZLIB | ||
| URL https://lcgpackages.web.cern.ch/lcgpackages/tarFiles/sources/zlib-ng-${ROOT_ZLIB_VERSION}.tar.gz | ||
| URL_HASH SHA256=${ROOT_ZLIB_HASH} | ||
| PREFIX ${ROOT_ZLIB_PREFIX} | ||
| CMAKE_ARGS -G ${CMAKE_GENERATOR} | ||
| -DCMAKE_INSTALL_PREFIX=<INSTALL_DIR> | ||
| -DCMAKE_INSTALL_LIBDIR=<INSTALL_DIR>/lib | ||
| -DCMAKE_POSITION_INDEPENDENT_CODE=ON | ||
| -DCMAKE_CXX_VISIBILITY_PRESET=hidden | ||
| -DCMAKE_C_VISIBILITY_PRESET=hidden | ||
| -BUILD_TESTING=OFF | ||
| -DWITH_GTEST=OFF | ||
| -DBUILD_SHARED_LIBS=OFF | ||
| -DZLIB_COMPAT=ON | ||
| ${zlib_extra_cmake_args} | ||
| BUILD_COMMAND ${CMAKE_COMMAND} --build . --config $<CONFIG> | ||
| INSTALL_COMMAND ${CMAKE_COMMAND} --install . --config $<CONFIG> | ||
| LOG_DOWNLOAD 1 LOG_CONFIGURE 1 LOG_BUILD 1 LOG_INSTALL 1 LOG_OUTPUT_ON_FAILURE 1 | ||
| BUILD_BYPRODUCTS ${ROOT_ZLIB_LIBRARY} | ||
| TIMEOUT 600 | ||
| ) | ||
|
|
||
| set(ZLIB_LIBRARY $<TARGET_FILE:ZLIB::ZLIB> CACHE INTERNAL FORCE "") | ||
| set(ZLIB_LIBRARIES ZLIB::ZLIB CACHE INTERNAL "") | ||
| set(ZLIB_INCLUDE_DIR ${ROOT_ZLIB_PREFIX}/include) | ||
| file(MAKE_DIRECTORY ${ZLIB_INCLUDE_DIR}) | ||
| set_property(GLOBAL APPEND PROPERTY ROOT_BUILTIN_TARGETS ZLIB::ZLIB) | ||
|
|
||
| if(DEFINED ZLIB_LIBRARY_DEBUG) | ||
| set(ZLIB_LIBRARY_DEBUG ${ZLIB_LIBRARY} CACHE INTERNAL "") | ||
| endif() | ||
| add_library(ZLIB STATIC IMPORTED GLOBAL) | ||
| add_library(ZLIB::ZLIB ALIAS ZLIB) | ||
| target_include_directories(ZLIB INTERFACE ${ZLIB_INCLUDE_DIR}) | ||
| set_target_properties(ZLIB PROPERTIES IMPORTED_LOCATION ${ROOT_ZLIB_LIBRARY}) | ||
|
|
||
| if(DEFINED ZLIB_LIBRARY_RELEASE) | ||
| set(ZLIB_LIBRARY_RELEASE ${ZLIB_LIBRARY} CACHE INTERNAL "") | ||
| endif() | ||
| add_dependencies(ZLIB BUILTIN_ZLIB) | ||
|
|
||
| set_property(GLOBAL APPEND PROPERTY ROOT_BUILTIN_TARGETS ZLIB::ZLIB) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is used to make all builtins build before the rest of ROOT. It could be replaced by some correctly crafted |
||
| # Set the canonical output of find_package according to | ||
| # https://cmake.org/cmake/help/latest/manual/cmake-developer.7.html#standard-variable-names | ||
| set(ZLIB_INCLUDE_DIRS ${ZLIB_INCLUDE_DIR} PARENT_SCOPE) | ||
| set(ZLIB_LIBRARIES ${ROOT_ZLIB_LIBRARY} PARENT_SCOPE) | ||
| set(ZLIB_FOUND TRUE PARENT_SCOPE) | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Without adding it to all builtin targets (see other comment), one should add: