diff --git a/cmake/FindWrapSystemZLIB.cmake b/cmake/FindWrapSystemZLIB.cmake new file mode 100644 index 0000000000..c109a598be --- /dev/null +++ b/cmake/FindWrapSystemZLIB.cmake @@ -0,0 +1,29 @@ +# We can't create the same interface imported target multiple times, CMake will complain if we do +# that. This can happen if the find_package call is done in multiple different subdirectories. +if(TARGET WrapSystemZLIB::WrapSystemZLIB) + set(WrapSystemZLIB_FOUND ON) + return() +endif() + +set(WrapSystemZLIB_FOUND OFF) + +find_package(ZLIB ${${CMAKE_FIND_PACKAGE_NAME}_FIND_VERSION}) + +if(ZLIB_FOUND) + set(WrapSystemZLIB_FOUND ON) + + add_library(WrapSystemZLIB::WrapSystemZLIB INTERFACE IMPORTED) + if(APPLE) + # On Darwin platforms FindZLIB sets IMPORTED_LOCATION to the absolute path of the library + # within the framework. This ends up as an absolute path link flag, which we don't want, + # because that makes our .prl files un-relocatable and also breaks iOS simulator_and_device + # SDK switching in Xcode. + # Just pass a linker flag instead. + target_link_libraries(WrapSystemZLIB::WrapSystemZLIB INTERFACE "-lz") + else() + target_link_libraries(WrapSystemZLIB::WrapSystemZLIB INTERFACE ZLIB::ZLIB) + endif() +endif() + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(WrapSystemZLIB DEFAULT_MSG WrapSystemZLIB_FOUND) diff --git a/cmake/FindWrapZLIB.cmake b/cmake/FindWrapZLIB.cmake index 585dc5e95e..ecb0070f81 100644 --- a/cmake/FindWrapZLIB.cmake +++ b/cmake/FindWrapZLIB.cmake @@ -1,29 +1,11 @@ -# We can't create the same interface imported target multiple times, CMake will complain if we do -# that. This can happen if the find_package call is done in multiple different subdirectories. -if(TARGET WrapZLIB::WrapZLIB) - set(WrapZLIB_FOUND ON) - return() -endif() +include(QtFindWrapHelper NO_POLICY_SCOPE) -set(WrapZLIB_FOUND OFF) - -find_package(ZLIB ${WrapZLIB_FIND_VERSION}) - -if(ZLIB_FOUND) - set(WrapZLIB_FOUND ON) - - add_library(WrapZLIB::WrapZLIB INTERFACE IMPORTED) - if(APPLE) - # On Darwin platforms FindZLIB sets IMPORTED_LOCATION to the absolute path of the library - # within the framework. This ends up as an absolute path link flag, which we don't want, - # because that makes our .prl files un-relocatable and also breaks iOS simulator_and_device - # SDK switching in Xcode. - # Just pass a linker flag instead. - target_link_libraries(WrapZLIB::WrapZLIB INTERFACE "-lz") - else() - target_link_libraries(WrapZLIB::WrapZLIB INTERFACE ZLIB::ZLIB) - endif() -endif() - -include(FindPackageHandleStandardArgs) -find_package_handle_standard_args(WrapZLIB DEFAULT_MSG WrapZLIB_FOUND) +qt_find_package_system_or_bundled(wrap_zlib + FRIENDLY_PACKAGE_NAME "ZLIB" + WRAP_PACKAGE_TARGET "WrapZLIB::WrapZLIB" + WRAP_PACKAGE_FOUND_VAR_NAME "WrapZLIB_FOUND" + BUNDLED_PACKAGE_NAME "BundledZLIB" + BUNDLED_PACKAGE_TARGET "BundledZLIB" + SYSTEM_PACKAGE_NAME "WrapSystemZLIB" + SYSTEM_PACKAGE_TARGET "WrapSystemZLIB::WrapSystemZLIB" +) diff --git a/configure.cmake b/configure.cmake index af6568b370..af1cb4116d 100644 --- a/configure.cmake +++ b/configure.cmake @@ -4,8 +4,7 @@ #### Libraries -qt_find_package(WrapZLIB 1.0.8 PROVIDED_TARGETS WrapZLIB::WrapZLIB MODULE_NAME global QMAKE_LIB zlib) -# special case begin +qt_find_package(WrapSystemZLIB 1.0.8 PROVIDED_TARGETS WrapSystemZLIB::WrapSystemZLIB MODULE_NAME global QMAKE_LIB zlib) # Work around global target promotion failure when WrapZLIB is used on APPLE platforms. # What ends up happening is that the ZLIB::ZLIB target is not promoted to global by qt_find_package, # then qt_find_package(WrapSystemPNG) tries to find its dependency ZLIB::ZLIB, sees it's not global @@ -910,7 +909,7 @@ qt_feature("stack-protector-strong" PRIVATE ) qt_feature("system-zlib" PRIVATE LABEL "Using system zlib" - CONDITION WrapZLIB_FOUND + CONDITION WrapSystemZLIB_FOUND ) qt_feature("zstd" PRIVATE LABEL "Zstandard support" diff --git a/src/3rdparty/CMakeLists.txt b/src/3rdparty/CMakeLists.txt index 68113d8bac..a02150e0f1 100644 --- a/src/3rdparty/CMakeLists.txt +++ b/src/3rdparty/CMakeLists.txt @@ -26,6 +26,11 @@ if(QT_FEATURE_regularexpression AND NOT QT_FEATURE_system_pcre2) endif() qt_install_3rdparty_library_wrap_config_extra_file(BundledPcre2) +if(NOT QT_FEATURE_system_zlib) + add_subdirectory(zlib) +endif() +qt_install_3rdparty_library_wrap_config_extra_file(BundledZLIB) + if (ANDROID) add_subdirectory(gradle) endif() diff --git a/src/3rdparty/zlib/CMakeLists.txt b/src/3rdparty/zlib/CMakeLists.txt new file mode 100644 index 0000000000..74335d9ba6 --- /dev/null +++ b/src/3rdparty/zlib/CMakeLists.txt @@ -0,0 +1,44 @@ +qt_internal_add_3rdparty_library(BundledZLIB + STATIC + SOURCES + src/adler32.c + src/compress.c + src/crc32.c + src/crc32.h + src/deflate.c + src/deflate.h + src/gzclose.c + src/gzguts.h + src/gzlib.c + src/gzread.c + src/gzwrite.c + src/infback.c + src/inffast.c + src/inffast.h + src/inffixed.h + src/inflate.c + src/inflate.h + src/inftrees.c + src/inftrees.h + src/trees.c + src/trees.h + src/uncompr.c + src/zconf.h + src/zlib.h + src/zutil.c + src/zutil.h + DEFINES + QT_BUILD_CORE_LIB + INCLUDE_DIRECTORIES + $ +) + +qt_disable_warnings(BundledZLIB) + +qt_set_symbol_visibility_hidden(BundledZLIB) + +qt_internal_add_3rdparty_header_module(ZlibPrivate + EXTERNAL_HEADERS + src/zlib.h + src/zconf.h +) diff --git a/src/3rdparty/zlib/qtpatches.diff b/src/3rdparty/zlib/qtpatches.diff index 0666fc2201..07018605a2 100644 --- a/src/3rdparty/zlib/qtpatches.diff +++ b/src/3rdparty/zlib/qtpatches.diff @@ -15,24 +15,11 @@ diff -ruN orig/ChangeLog src/ChangeLog diff -ruN orig/gzguts.h src/gzguts.h --- orig/gzguts.h +++ src/gzguts.h -@@ -3,6 +3,25 @@ +@@ -3,6 +3,12 @@ * For conditions of distribution and use, see copyright notice in zlib.h */ -+#ifdef _MSC_VER -+# ifndef _CRT_SECURE_NO_DEPRECATE -+# define _CRT_SECURE_NO_DEPRECATE -+# endif -+# ifndef _CRT_NONSTDC_NO_DEPRECATE -+# define _CRT_NONSTDC_NO_DEPRECATE -+# endif -+// disable warnings like '=': conversion from 'size_t' to 'unsigned int', possible loss of data -+# pragma warning(disable: 4267; disable: 4244) -+#endif -+ -+#ifndef QT_BOOTSTRAPPED -+# include -+#endif ++#include + +#ifdef QT_VISIBILITY_AVAILABLE +#define HAVE_HIDDEN @@ -107,13 +94,11 @@ diff -ruN orig/zlib.h src/zlib.h diff -ruN orig/zutil.h src/zutil.h --- orig/zutil.h +++ src/zutil.h -@@ -13,6 +13,14 @@ +@@ -13,6 +13,12 @@ #ifndef ZUTIL_H #define ZUTIL_H -+#ifndef QT_BOOTSTRAPPED -+# include -+#endif ++#include + +#ifdef QT_VISIBILITY_AVAILABLE +#define HAVE_HIDDEN @@ -122,7 +107,7 @@ diff -ruN orig/zutil.h src/zutil.h #ifdef HAVE_HIDDEN # define ZLIB_INTERNAL __attribute__((visibility ("hidden"))) #else -@@ -143,6 +151,11 @@ +@@ -143,6 +149,11 @@ # if defined(__MWERKS__) && __dest_os != __be_os && __dest_os != __win32_os # include /* for fdopen */ # else @@ -134,7 +119,7 @@ diff -ruN orig/zutil.h src/zutil.h # ifndef fdopen # define fdopen(fd,mode) NULL /* No fdopen() */ # endif -@@ -166,7 +179,7 @@ +@@ -166,7 +177,7 @@ # define OS_CODE 18 #endif diff --git a/src/3rdparty/zlib/src/gzguts.h b/src/3rdparty/zlib/src/gzguts.h index 3ec32af25f..26d2ac9bd0 100644 --- a/src/3rdparty/zlib/src/gzguts.h +++ b/src/3rdparty/zlib/src/gzguts.h @@ -3,20 +3,7 @@ * For conditions of distribution and use, see copyright notice in zlib.h */ -#ifdef _MSC_VER -# ifndef _CRT_SECURE_NO_DEPRECATE -# define _CRT_SECURE_NO_DEPRECATE -# endif -# ifndef _CRT_NONSTDC_NO_DEPRECATE -# define _CRT_NONSTDC_NO_DEPRECATE -# endif -// disable warnings like '=': conversion from 'size_t' to 'unsigned int', possible loss of data -# pragma warning(disable: 4267; disable: 4244) -#endif - -#ifndef QT_BOOTSTRAPPED -# include -#endif +#include #ifdef QT_VISIBILITY_AVAILABLE #define HAVE_HIDDEN diff --git a/src/3rdparty/zlib/src/zutil.h b/src/3rdparty/zlib/src/zutil.h index 0d78483358..c535e57eb6 100644 --- a/src/3rdparty/zlib/src/zutil.h +++ b/src/3rdparty/zlib/src/zutil.h @@ -13,9 +13,7 @@ #ifndef ZUTIL_H #define ZUTIL_H -#ifndef QT_BOOTSTRAPPED -# include -#endif +#include #ifdef QT_VISIBILITY_AVAILABLE #define HAVE_HIDDEN diff --git a/src/corelib/CMakeLists.txt b/src/corelib/CMakeLists.txt index 6f5e0ec6cf..3c5301fee2 100644 --- a/src/corelib/CMakeLists.txt +++ b/src/corelib/CMakeLists.txt @@ -3,6 +3,7 @@ # special case begin qt_find_package(Threads PROVIDED_TARGETS Threads::Threads) qt_find_package(WrapPCRE2 PROVIDED_TARGETS WrapPCRE2::WrapPCRE2) +qt_find_package(WrapZLIB PROVIDED_TARGETS WrapZLIB::WrapZLIB) # compute the reverse relative path from QtCoreConfigExtras to the install prefix @@ -272,6 +273,7 @@ qt_internal_add_module(Core ../3rdparty/tinycbor/src LIBRARIES Qt::GlobalConfigPrivate # special case + WrapZLIB::WrapZLIB PRECOMPILED_HEADER "global/qt_pch.h" GENERATE_CPP_EXPORTS @@ -673,30 +675,9 @@ qt_internal_extend_target(Core CONDITION QT_FEATURE_std_atomic64 WrapAtomic::WrapAtomic ) -qt_internal_extend_target(Core CONDITION QT_FEATURE_system_zlib - LIBRARIES - WrapZLIB::WrapZLIB -) - qt_internal_extend_target(Core CONDITION NOT QT_FEATURE_system_zlib - SOURCES - ../3rdparty/zlib/src/adler32.c - ../3rdparty/zlib/src/compress.c - ../3rdparty/zlib/src/crc32.c - ../3rdparty/zlib/src/deflate.c - ../3rdparty/zlib/src/gzclose.c - ../3rdparty/zlib/src/gzlib.c - ../3rdparty/zlib/src/gzread.c - ../3rdparty/zlib/src/gzwrite.c - ../3rdparty/zlib/src/infback.c - ../3rdparty/zlib/src/inffast.c - ../3rdparty/zlib/src/inflate.c - ../3rdparty/zlib/src/inftrees.c - ../3rdparty/zlib/src/trees.c - ../3rdparty/zlib/src/uncompr.c - ../3rdparty/zlib/src/zutil.c - INCLUDE_DIRECTORIES - ../3rdparty/zlib/src + LIBRARIES + Qt::ZlibPrivate ) qt_internal_extend_target(Core CONDITION QT_FEATURE_commandlineparser @@ -1333,14 +1314,6 @@ qt_internal_add_docs(Core doc/qtcore.qdocconf ) -if(NOT QT_FEATURE_system_zlib) - qt_internal_add_3rdparty_header_module(ZlibPrivate - EXTERNAL_HEADERS - ../3rdparty/zlib/src/zlib.h - ../3rdparty/zlib/src/zconf.h - ) -endif() - qt_internal_add_optimize_full_flags() # Copy / install an lldb python script into the QtCore.framework.dSYM bundle which searches