From 85b8d2551ba63f795fea58e97973a445ff0e0de4 Mon Sep 17 00:00:00 2001
From: Martchus <martchus@gmx.net>
Date: Thu, 5 Nov 2020 21:59:33 +0100
Subject: [PATCH 4/8] Fix transitive dependencies (of static libraries)

The dependencies of these libraries are not reliably picked up by their
corresponding find modules. This change allows adding the required
dependencies by setting certain variables, e.g. within the toolchain file.

This change also disables the upstream hack for OpenSSL's dependencies
as it is even more hacky to hardcode the library names.

Change-Id: I3baec612ee071eec77f756b18bbb9af87663527c
---
 .../3rdparty/extra-cmake-modules/find-modules/FindGLIB2.cmake | 2 +-
 cmake/FindMySQL.cmake                                         | 1 +
 cmake/FindWrapDBus1.cmake                                     | 1 +
 cmake/FindWrapOpenSSL.cmake                                   | 4 ++--
 cmake/FindWrapSystemFreetype.cmake                            | 2 +-
 cmake/FindWrapSystemHarfbuzz.cmake                            | 2 +-
 cmake/FindWrapSystemPNG.cmake                                 | 2 +-
 src/plugins/sqldrivers/psql/CMakeLists.txt                    | 2 +-
 8 files changed, 9 insertions(+), 7 deletions(-)

diff --git a/qtbase/cmake/3rdparty/extra-cmake-modules/find-modules/FindGLIB2.cmake b/qtbase/cmake/3rdparty/extra-cmake-modules/find-modules/FindGLIB2.cmake
index 24a194c9cb3..a6a16b494fd 100644
--- a/qtbase/cmake/3rdparty/extra-cmake-modules/find-modules/FindGLIB2.cmake
+++ b/qtbase/cmake/3rdparty/extra-cmake-modules/find-modules/FindGLIB2.cmake
@@ -135,7 +135,7 @@ if(GLIB2_FOUND AND NOT TARGET GLIB2::GLIB2)
   add_library(GLIB2::GLIB2 UNKNOWN IMPORTED)
   set_target_properties(GLIB2::GLIB2 PROPERTIES
                         IMPORTED_LOCATION "${GLIB2_LIBRARIES}"
-                        INTERFACE_LINK_LIBRARIES "${GTHREAD2_LIBRARIES}"
+                        INTERFACE_LINK_LIBRARIES "${GTHREAD2_LIBRARIES};${GLIB2_DEPENDENCIES}"
                         INTERFACE_INCLUDE_DIRECTORIES "${GLIB2_INCLUDE_DIRS}")
 endif()
 
diff --git a/qtbase/cmake/FindMySQL.cmake b/qtbase/cmake/FindMySQL.cmake
index a069a5eb125..0fcba2148e0 100644
--- a/qtbase/cmake/FindMySQL.cmake
+++ b/qtbase/cmake/FindMySQL.cmake
@@ -40,6 +40,7 @@ if(MySQL_FOUND)
     add_library(MySQL::MySQL UNKNOWN IMPORTED)
     set_target_properties(MySQL::MySQL PROPERTIES
                           IMPORTED_LOCATION "${MySQL_LIBRARIES}"
+                          INTERFACE_LINK_LIBRARIES "${MYSQL_DEPENDENCIES}"
                           INTERFACE_INCLUDE_DIRECTORIES "${MySQL_INCLUDE_DIRS}")
   endif()
 endif()
--- a/qtbase/cmake/FindWrapBrotli.cmake
+++ b/qtbase/cmake/FindWrapBrotli.cmake
@@ -23,6 +23,8 @@
         if (libbrotlidec_FOUND)
             add_library(WrapBrotli::WrapBrotliDec INTERFACE IMPORTED)
             target_link_libraries(WrapBrotli::WrapBrotliDec INTERFACE PkgConfig::libbrotlidec)
+            set_property(TARGET WrapBrotli::WrapBrotliDec APPEND PROPERTY
+                         INTERFACE_LINK_LIBRARIES WrapBrotli::WrapBrotliCommon)
             set(WrapBrotli_FOUND ON)
         endif()
 
@@ -30,6 +32,8 @@
         if (libbrotlienc_FOUND)
             add_library(WrapBrotli::WrapBrotliEnc INTERFACE IMPORTED)
             target_link_libraries(WrapBrotli::WrapBrotliEnc INTERFACE PkgConfig::libbrotlienc)
+            set_property(TARGET WrapBrotli::WrapBrotliEnc APPEND PROPERTY
+                         INTERFACE_LINK_LIBRARIES WrapBrotli::WrapBrotliCommon)
             set(WrapBrotli_FOUND ON)
         endif()
 
diff --git a/qtbase/cmake/FindWrapDBus1.cmake b/qtbase/cmake/FindWrapDBus1.cmake
index bdbcab9eb3c..06e9af49f6b 100644
--- a/qtbase/cmake/FindWrapDBus1.cmake
+++ b/qtbase/cmake/FindWrapDBus1.cmake
@@ -47,4 +47,5 @@ find_package_handle_standard_args(WrapDBus1 REQUIRED_VARS
                                             VERSION_VAR DBus1_VERSION)
 if(TARGET dbus-1)
     set_property(TARGET dbus-1 PROPERTY IMPORTED_IMPLIB ${DBus1_LIBRARY})
+    set_property(TARGET dbus-1 PROPERTY INTERFACE_LINK_LIBRARIES "${DBUS1_DEPENDENCIES}")
 endif()
diff --git a/qtbase/cmake/FindWrapOpenSSL.cmake b/qtbase/cmake/FindWrapOpenSSL.cmake
index 7b6dccb1d26..550c5134fb0 100644
--- a/qtbase/cmake/FindWrapOpenSSL.cmake
+++ b/qtbase/cmake/FindWrapOpenSSL.cmake
@@ -11,7 +11,7 @@ set(WrapOpenSSL_FOUND OFF)
 find_package(WrapOpenSSLHeaders ${WrapOpenSSL_FIND_VERSION})
 
 if(TARGET OpenSSL::SSL)
-    if(WIN32)
+    if(WIN32 AND NOT MINGW)
         get_target_property(libType OpenSSL::Crypto TYPE)
         if(libType STREQUAL "ALIAS")
             get_target_property(writableLib OpenSSL::Crypto ALIASED_TARGET)
@@ -26,7 +26,7 @@ if(TARGET OpenSSL::SSL)
     set(WrapOpenSSL_FOUND ON)
 
     add_library(WrapOpenSSL::WrapOpenSSL INTERFACE IMPORTED)
-    target_link_libraries(WrapOpenSSL::WrapOpenSSL INTERFACE OpenSSL::SSL)
+    target_link_libraries(WrapOpenSSL::WrapOpenSSL INTERFACE OpenSSL::SSL ${OPENSSL_DEPENDENCIES})
 endif()
 
 include(FindPackageHandleStandardArgs)
diff --git a/qtbase/cmake/FindWrapSystemFreetype.cmake b/qtbase/cmake/FindWrapSystemFreetype.cmake
index 2cf6caca193..23dc161e4cf 100644
--- a/qtbase/cmake/FindWrapSystemFreetype.cmake
+++ b/qtbase/cmake/FindWrapSystemFreetype.cmake
@@ -44,7 +44,7 @@ find_package_handle_standard_args(WrapSystemFreetype
 if(WrapSystemFreetype_FOUND)
     add_library(WrapSystemFreetype::WrapSystemFreetype INTERFACE IMPORTED)
     target_link_libraries(WrapSystemFreetype::WrapSystemFreetype
-                          INTERFACE "${__freetype_target_name}")
+                          INTERFACE "${__freetype_target_name}" ${FREETYPE_DEPENDENCIES})
 endif()
 unset(__freetype_target_name)
 unset(__freetype_found)
diff --git a/qtbase/cmake/FindWrapSystemHarfbuzz.cmake b/qtbase/cmake/FindWrapSystemHarfbuzz.cmake
index fc6233d942b..1e6105a00c8 100644
--- a/qtbase/cmake/FindWrapSystemHarfbuzz.cmake
+++ b/qtbase/cmake/FindWrapSystemHarfbuzz.cmake
@@ -70,7 +70,7 @@ find_package_handle_standard_args(WrapSystemHarfbuzz
 if(WrapSystemHarfbuzz_FOUND)
     add_library(WrapSystemHarfbuzz::WrapSystemHarfbuzz INTERFACE IMPORTED)
     target_link_libraries(WrapSystemHarfbuzz::WrapSystemHarfbuzz
-                          INTERFACE "${__harfbuzz_target_name}")
+                          INTERFACE "${__harfbuzz_target_name}" ${HARFBUZZ_DEPENDENCIES})
 endif()
 unset(__harfbuzz_target_name)
 unset(__harfbuzz_find_include_dirs_hints)
diff --git a/qtbase/cmake/FindWrapSystemPNG.cmake b/qtbase/cmake/FindWrapSystemPNG.cmake
index 372a064ff49..a363bfd31b4 100644
--- a/qtbase/cmake/FindWrapSystemPNG.cmake
+++ b/qtbase/cmake/FindWrapSystemPNG.cmake
@@ -33,7 +33,7 @@ find_package_handle_standard_args(WrapSystemPNG
 if(WrapSystemPNG_FOUND)
     add_library(WrapSystemPNG::WrapSystemPNG INTERFACE IMPORTED)
     target_link_libraries(WrapSystemPNG::WrapSystemPNG
-                          INTERFACE "${__png_target_name}")
+                          INTERFACE "${__png_target_name}" ${LIBPNG_DEPENDENCIES})
 endif()
 unset(__png_target_name)
 unset(__png_found)
diff --git a/qtbase/src/plugins/sqldrivers/psql/CMakeLists.txt b/qtbase/src/plugins/sqldrivers/psql/CMakeLists.txt
index d3a6a8588e2..743154fc508 100644
--- a/qtbase/src/plugins/sqldrivers/psql/CMakeLists.txt
+++ b/qtbase/src/plugins/sqldrivers/psql/CMakeLists.txt
@@ -16,7 +16,7 @@ qt_internal_add_plugin(QPSQLDriverPlugin
         QT_NO_CAST_FROM_ASCII
         QT_NO_CAST_TO_ASCII
     LIBRARIES
-        PostgreSQL::PostgreSQL
+        PostgreSQL::PostgreSQL ${POSTGRESQL_DEPENDENCIES}
         Qt::Core
         Qt::CorePrivate
         Qt::SqlPrivate
