diff --git a/.prev_configure.cmake b/.prev_configure.cmake index f796eddc8a..3cd944aeae 100644 --- a/.prev_configure.cmake +++ b/.prev_configure.cmake @@ -6,7 +6,7 @@ #### Libraries -qt_find_package(ZLIB 1.0.8 PROVIDED_TARGETS ZLIB::ZLIB MODULE_NAME global QMAKE_LIB zlib) +qt_find_package(WrapZLIB 1.0.8 PROVIDED_TARGETS WrapZLIB::WrapZLIB MODULE_NAME global QMAKE_LIB zlib) qt_find_package(ZSTD 1.3 PROVIDED_TARGETS ZSTD::ZSTD MODULE_NAME global QMAKE_LIB zstd) qt_find_package(WrapDBus1 1.2 PROVIDED_TARGETS dbus-1 MODULE_NAME global QMAKE_LIB dbus) qt_find_package(Libudev PROVIDED_TARGETS PkgConfig::Libudev MODULE_NAME global QMAKE_LIB libudev) @@ -809,7 +809,7 @@ qt_feature("stack-protector-strong" PRIVATE ) qt_feature("system-zlib" PRIVATE LABEL "Using system zlib" - CONDITION ZLIB_FOUND + CONDITION WrapZLIB_FOUND ) qt_feature("zstd" PRIVATE LABEL "Zstandard support" diff --git a/cmake/FindWrapZLIB.cmake b/cmake/FindWrapZLIB.cmake new file mode 100644 index 0000000000..585dc5e95e --- /dev/null +++ b/cmake/FindWrapZLIB.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 WrapZLIB::WrapZLIB) + set(WrapZLIB_FOUND ON) + return() +endif() + +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) diff --git a/configure.cmake b/configure.cmake index cfd355dcfe..3412703333 100644 --- a/configure.cmake +++ b/configure.cmake @@ -4,7 +4,19 @@ #### Libraries -qt_find_package(ZLIB 1.0.8 PROVIDED_TARGETS ZLIB::ZLIB MODULE_NAME global QMAKE_LIB zlib) +qt_find_package(WrapZLIB 1.0.8 PROVIDED_TARGETS WrapZLIB::WrapZLIB MODULE_NAME global QMAKE_LIB zlib) +# special case begin +# 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 +# and tries to promote it to global, but fails because the directory scope of the PNG package is +# different (src/gui) from where ZLIB was originally found (qtbase root). +# To avoid that, just manually promote the target to global here. +if(TARGET ZLIB::ZLIB) + set_property(TARGET ZLIB::ZLIB PROPERTY IMPORTED_GLOBAL TRUE) +endif() + +# special case end qt_find_package(ZSTD 1.3 PROVIDED_TARGETS ZSTD::ZSTD MODULE_NAME global QMAKE_LIB zstd) qt_find_package(WrapDBus1 1.2 PROVIDED_TARGETS dbus-1 MODULE_NAME global QMAKE_LIB dbus) qt_find_package(Libudev PROVIDED_TARGETS PkgConfig::Libudev MODULE_NAME global QMAKE_LIB libudev) @@ -824,7 +836,7 @@ qt_feature("stack-protector-strong" PRIVATE ) qt_feature("system-zlib" PRIVATE LABEL "Using system zlib" - CONDITION ZLIB_FOUND + CONDITION WrapZLIB_FOUND ) qt_feature("zstd" PRIVATE LABEL "Zstandard support" diff --git a/src/3rdparty/freetype/CMakeLists.txt b/src/3rdparty/freetype/CMakeLists.txt index 13f2c434c0..6a9de38984 100644 --- a/src/3rdparty/freetype/CMakeLists.txt +++ b/src/3rdparty/freetype/CMakeLists.txt @@ -78,7 +78,7 @@ qt_internal_extend_target(BundledFreetype CONDITION QT_FEATURE_png qt_internal_extend_target(BundledFreetype CONDITION QT_FEATURE_system_zlib LIBRARIES - ZLIB::ZLIB + WrapZLIB::WrapZLIB ) qt_internal_extend_target(BundledFreetype CONDITION NOT QT_FEATURE_system_zlib diff --git a/src/3rdparty/libpng/CMakeLists.txt b/src/3rdparty/libpng/CMakeLists.txt index e07272f7c6..637ebcf548 100644 --- a/src/3rdparty/libpng/CMakeLists.txt +++ b/src/3rdparty/libpng/CMakeLists.txt @@ -42,7 +42,7 @@ qt_set_symbol_visibility_hidden(BundledLibpng) qt_internal_extend_target(BundledLibpng CONDITION QT_FEATURE_system_zlib LIBRARIES - ZLIB::ZLIB + WrapZLIB::WrapZLIB ) qt_internal_extend_target(BundledLibpng CONDITION NOT QT_FEATURE_system_zlib diff --git a/src/corelib/CMakeLists.txt b/src/corelib/CMakeLists.txt index 3c6b20636a..8351ec9263 100644 --- a/src/corelib/CMakeLists.txt +++ b/src/corelib/CMakeLists.txt @@ -692,7 +692,7 @@ qt_internal_extend_target(Core CONDITION ICC qt_internal_extend_target(Core CONDITION QT_FEATURE_system_zlib LIBRARIES - ZLIB::ZLIB + WrapZLIB::WrapZLIB ) qt_internal_extend_target(Core CONDITION NOT QT_FEATURE_system_zlib diff --git a/src/gui/CMakeLists.txt b/src/gui/CMakeLists.txt index 31e727189b..a8692318eb 100644 --- a/src/gui/CMakeLists.txt +++ b/src/gui/CMakeLists.txt @@ -792,7 +792,7 @@ qt_internal_extend_target(Gui CONDITION ANDROID AND TEST_architecture_arch STREQ qt_internal_extend_target(Gui CONDITION QT_FEATURE_system_zlib LIBRARIES - ZLIB::ZLIB + WrapZLIB::WrapZLIB ) qt_internal_extend_target(Gui CONDITION NOT QT_FEATURE_system_zlib diff --git a/src/network/CMakeLists.txt b/src/network/CMakeLists.txt index dc32520b32..e49b8d8930 100644 --- a/src/network/CMakeLists.txt +++ b/src/network/CMakeLists.txt @@ -136,7 +136,7 @@ qt_internal_extend_target(Network CONDITION QT_FEATURE_http AND QT_FEATURE_zstd qt_internal_extend_target(Network CONDITION QT_FEATURE_system_zlib LIBRARIES - ZLIB::ZLIB + WrapZLIB::WrapZLIB ) qt_internal_extend_target(Network CONDITION NOT QT_FEATURE_system_zlib diff --git a/src/tools/bootstrap/CMakeLists.txt b/src/tools/bootstrap/CMakeLists.txt index a2f0e30920..7d1a067126 100644 --- a/src/tools/bootstrap/CMakeLists.txt +++ b/src/tools/bootstrap/CMakeLists.txt @@ -265,7 +265,7 @@ qt_internal_extend_target(Bootstrap CONDITION CMAKE_CROSSCOMPILING OR NOT QT_FEA qt_internal_extend_target(Bootstrap CONDITION QT_FEATURE_system_zlib AND NOT CMAKE_CROSSCOMPILING LIBRARIES - ZLIB::ZLIB + WrapZLIB::WrapZLIB ) qt_internal_extend_target(Bootstrap CONDITION MINGW AND WIN32 diff --git a/util/cmake/helper.py b/util/cmake/helper.py index 8917821a3e..c0063259a9 100644 --- a/util/cmake/helper.py +++ b/util/cmake/helper.py @@ -601,7 +601,7 @@ _library_map = [ LibraryMapping("xkbcommon", "XKB", "XKB::XKB", extra=["0.5.0"]), LibraryMapping("xlib", "X11", "X11::X11"), LibraryMapping("xrender", "XRender", "PkgConfig::XRender", extra=["0.6"]), - LibraryMapping("zlib", "ZLIB", "ZLIB::ZLIB", extra=["1.0.8"]), + LibraryMapping("zlib", "WrapZLIB", "WrapZLIB::WrapZLIB", extra=["1.0.8"]), LibraryMapping("zstd", "ZSTD", "ZSTD::ZSTD", extra=["1.3"]), LibraryMapping("tiff", "TIFF", "TIFF::TIFF"), LibraryMapping("webp", "WrapWebP", "WrapWebP::WrapWebP"),