From c776e7705225851f2f655da09ddce0c1ef52bab8 Mon Sep 17 00:00:00 2001 From: Ruslan Baratov Date: Sat, 1 Feb 2014 11:31:20 +0400 Subject: [PATCH 1/8] Replace tabs from CMakeLists.txt with spaces To be consistent with the remaining file replace the two occurences of tabs with 4 spaces. --- CMakeLists.txt | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 7f1b69f4a..98243e15c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -76,10 +76,10 @@ if(NOT CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_CURRENT_BINARY_DIR) endif() set(ZLIB_PC ${CMAKE_CURRENT_BINARY_DIR}/zlib.pc) -configure_file( ${CMAKE_CURRENT_SOURCE_DIR}/zlib.pc.cmakein - ${ZLIB_PC} @ONLY) -configure_file( ${CMAKE_CURRENT_SOURCE_DIR}/zconf.h.cmakein - ${CMAKE_CURRENT_BINARY_DIR}/zconf.h @ONLY) +configure_file(${CMAKE_CURRENT_SOURCE_DIR}/zlib.pc.cmakein + ${ZLIB_PC} @ONLY) +configure_file(${CMAKE_CURRENT_SOURCE_DIR}/zconf.h.cmakein + ${CMAKE_CURRENT_BINARY_DIR}/zconf.h @ONLY) include_directories(${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_SOURCE_DIR}) From 747e0f5ae326a655255a77fd852e4d7af229db9e Mon Sep 17 00:00:00 2001 From: Ruslan Baratov Date: Sat, 1 Feb 2014 14:35:10 +0400 Subject: [PATCH 2/8] Teach ZLIB respect BUILD_SHARED_LIBS --- CMakeLists.txt | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 98243e15c..1488e2918 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -147,8 +147,8 @@ if(MINGW) set(ZLIB_DLL_SRCS ${CMAKE_CURRENT_BINARY_DIR}/zlib1rc.obj) endif(MINGW) -add_library(zlib SHARED ${ZLIB_SRCS} ${ZLIB_DLL_SRCS} ${ZLIB_PUBLIC_HDRS} ${ZLIB_PRIVATE_HDRS}) -add_library(zlibstatic STATIC ${ZLIB_SRCS} ${ZLIB_PUBLIC_HDRS} ${ZLIB_PRIVATE_HDRS}) + +add_library(zlib ${ZLIB_SRCS} ${ZLIB_DLL_SRCS} ${ZLIB_PUBLIC_HDRS} ${ZLIB_PRIVATE_HDRS}) set_target_properties(zlib PROPERTIES DEFINE_SYMBOL ZLIB_DLL) set_target_properties(zlib PROPERTIES SOVERSION 1) @@ -165,7 +165,7 @@ endif() if(UNIX) # On unix-like platforms the library is almost always called libz - set_target_properties(zlib zlibstatic PROPERTIES OUTPUT_NAME z) + set_target_properties(zlib PROPERTIES OUTPUT_NAME z) if(NOT APPLE) set_target_properties(zlib PROPERTIES LINK_FLAGS "-Wl,--version-script,\"${CMAKE_CURRENT_SOURCE_DIR}/zlib.map\"") endif() @@ -175,7 +175,7 @@ elseif(BUILD_SHARED_LIBS AND WIN32) endif() if(NOT SKIP_INSTALL_LIBRARIES AND NOT SKIP_INSTALL_ALL ) - install(TARGETS zlib zlibstatic + install(TARGETS zlib RUNTIME DESTINATION "${INSTALL_BIN_DIR}" ARCHIVE DESTINATION "${INSTALL_LIB_DIR}" LIBRARY DESTINATION "${INSTALL_LIB_DIR}" ) From 45d8b6cf0bf23841cb50a1cb18d8eb200685a513 Mon Sep 17 00:00:00 2001 From: Ruslan Baratov Date: Sat, 1 Feb 2014 14:37:03 +0400 Subject: [PATCH 3/8] Fix file path for iOS targets --- test/example.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/test/example.c b/test/example.c index 582a17a3c..71c1768b8 100644 --- a/test/example.c +++ b/test/example.c @@ -15,6 +15,13 @@ #if defined(VMS) || defined(RISCOS) # define TESTFILE "foo-gz" +#elif defined(__APPLE__) +# include "TargetConditionals.h" +# if (TARGET_OS_IPHONE) +# define TESTFILE "/tmp/foo.gz" +# else +# define TESTFILE "foo.gz" +# endif #else # define TESTFILE "foo.gz" #endif From 4ee64f820db27be16529f492ddd727618a5a8882 Mon Sep 17 00:00:00 2001 From: Ruslan Baratov Date: Fri, 1 May 2015 12:19:41 +0200 Subject: [PATCH 4/8] Set version in command 'project' --- CMakeLists.txt | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 1488e2918..f9272cd86 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,9 +1,10 @@ -cmake_minimum_required(VERSION 2.4.4...3.15.0) +cmake_minimum_required(VERSION 3.0...3.15.0) set(CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS ON) -project(zlib C) +project(ZLIB VERSION "1.3" LANGUAGES C) + +set(VERSION "${PROJECT_VERSION}") -set(VERSION "1.3") set(INSTALL_BIN_DIR "${CMAKE_INSTALL_PREFIX}/bin" CACHE PATH "Installation directory for executables") set(INSTALL_LIB_DIR "${CMAKE_INSTALL_PREFIX}/lib" CACHE PATH "Installation directory for libraries") From ae48e16cc60092fea95ef9ec1be47ca5b49269d2 Mon Sep 17 00:00:00 2001 From: Ruslan Baratov Date: Wed, 19 Nov 2014 18:42:58 +0300 Subject: [PATCH 5/8] Install config --- CMakeLists.txt | 46 +++++++++++++++++++++++++++++++++++++++---- cmake/Config.cmake.in | 1 + 2 files changed, 43 insertions(+), 4 deletions(-) create mode 100644 cmake/Config.cmake.in diff --git a/CMakeLists.txt b/CMakeLists.txt index f9272cd86..0d6e953c2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -176,10 +176,48 @@ elseif(BUILD_SHARED_LIBS AND WIN32) endif() if(NOT SKIP_INSTALL_LIBRARIES AND NOT SKIP_INSTALL_ALL ) - install(TARGETS zlib - RUNTIME DESTINATION "${INSTALL_BIN_DIR}" - ARCHIVE DESTINATION "${INSTALL_LIB_DIR}" - LIBRARY DESTINATION "${INSTALL_LIB_DIR}" ) + #### + # Installation (https://github.com/forexample/package-example) + + set(config_install_dir "lib/cmake/${PROJECT_NAME}") + set(include_install_dir "include") + + set(generated_dir "${CMAKE_CURRENT_BINARY_DIR}/generated") + + set(version_config "${generated_dir}/${PROJECT_NAME}ConfigVersion.cmake") + set(project_config "${generated_dir}/${PROJECT_NAME}Config.cmake") + set(targets_export_name "${PROJECT_NAME}Targets") + set(namespace "${PROJECT_NAME}::") + + include(CMakePackageConfigHelpers) + + # Note: PROJECT_VERSION is used as a VERSION + write_basic_package_version_file( + "${version_config}" COMPATIBILITY SameMajorVersion + ) + + # Note: variable 'targets_export_name' used + configure_file("cmake/Config.cmake.in" "${project_config}" @ONLY) + + install( + TARGETS zlib + EXPORT "${targets_export_name}" + LIBRARY DESTINATION "lib" + ARCHIVE DESTINATION "lib" + RUNTIME DESTINATION "bin" + INCLUDES DESTINATION "${include_install_dir}" + ) + + install( + FILES "${project_config}" "${version_config}" + DESTINATION "${config_install_dir}" + ) + + install( + EXPORT "${targets_export_name}" + NAMESPACE "${namespace}" + DESTINATION "${config_install_dir}" + ) endif() if(NOT SKIP_INSTALL_HEADERS AND NOT SKIP_INSTALL_ALL ) install(FILES ${ZLIB_PUBLIC_HDRS} DESTINATION "${INSTALL_INC_DIR}") diff --git a/cmake/Config.cmake.in b/cmake/Config.cmake.in new file mode 100644 index 000000000..6e9256eea --- /dev/null +++ b/cmake/Config.cmake.in @@ -0,0 +1 @@ +include("${CMAKE_CURRENT_LIST_DIR}/@targets_export_name@.cmake") From c6120a17e2910eb789fb45f4057d581eee2600cd Mon Sep 17 00:00:00 2001 From: Ruslan Baratov Date: Fri, 24 May 2019 23:25:48 +0300 Subject: [PATCH 6/8] Use configure_package_config_file --- CMakeLists.txt | 6 +++++- cmake/Config.cmake.in | 3 +++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 0d6e953c2..f58811fdf 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -197,7 +197,11 @@ if(NOT SKIP_INSTALL_LIBRARIES AND NOT SKIP_INSTALL_ALL ) ) # Note: variable 'targets_export_name' used - configure_file("cmake/Config.cmake.in" "${project_config}" @ONLY) + configure_package_config_file( + "cmake/Config.cmake.in" + "${project_config}" + INSTALL_DESTINATION "${config_install_dir}" + ) install( TARGETS zlib diff --git a/cmake/Config.cmake.in b/cmake/Config.cmake.in index 6e9256eea..9b4c9ee03 100644 --- a/cmake/Config.cmake.in +++ b/cmake/Config.cmake.in @@ -1 +1,4 @@ +@PACKAGE_INIT@ + include("${CMAKE_CURRENT_LIST_DIR}/@targets_export_name@.cmake") +check_required_components("@PROJECT_NAME@") From 57af136e436c5596e4f1c63fd5bdd2ce988777d1 Mon Sep 17 00:00:00 2001 From: Ruslan Baratov Date: Sat, 25 May 2019 14:27:02 +0300 Subject: [PATCH 7/8] Add ZLIB::ZLIB ALIAS target --- cmake/Config.cmake.in | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/cmake/Config.cmake.in b/cmake/Config.cmake.in index 9b4c9ee03..40b9de3a1 100644 --- a/cmake/Config.cmake.in +++ b/cmake/Config.cmake.in @@ -2,3 +2,12 @@ include("${CMAKE_CURRENT_LIST_DIR}/@targets_export_name@.cmake") check_required_components("@PROJECT_NAME@") + +if(NOT TARGET ZLIB::ZLIB) + set_target_properties( + ZLIB::zlib + PROPERTIES + IMPORTED_GLOBAL True + ) + add_library(ZLIB::ZLIB ALIAS ZLIB::zlib) +endif() From 600934d9020e2822aad40ddd05b775e73585e952 Mon Sep 17 00:00:00 2001 From: Pablo Date: Sat, 28 Mar 2026 22:31:44 +0100 Subject: [PATCH 8/8] fix: prevent fdopen macro from overriding stdio.h on macOS MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit On macOS, TARGET_OS_MAC is defined by the SDK headers. zutil.h defines fdopen(fd,mode) as NULL under this condition, but macOS stdio.h already declares fdopen() as a proper function — causing a redeclaration conflict when both headers are included in the same translation unit (e.g. when gRPC or other C++ libraries pull in both zlib and stdio headers). Add && !defined(__APPLE__) so the fdopen NULL macro only applies to legacy Mac OS (pre-macOS) targets, not modern macOS where the libc provides a real fdopen implementation. Fixes: compile error with Apple Clang on macOS 10.15+ (Catalina and later) --- zutil.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/zutil.h b/zutil.h index 902a304cc..9d3f8f688 100644 --- a/zutil.h +++ b/zutil.h @@ -137,7 +137,7 @@ extern z_const char * const z_errmsg[10]; /* indexed by 2-zlib_error */ # endif #endif -#if defined(MACOS) || defined(TARGET_OS_MAC) +#if (defined(MACOS) || defined(TARGET_OS_MAC)) && !defined(__APPLE__) # define OS_CODE 7 # ifndef Z_SOLO # if defined(__MWERKS__) && __dest_os != __be_os && __dest_os != __win32_os