From 97dd25ccddaf09c2cd81e7e1c6bc937b18fcb314 Mon Sep 17 00:00:00 2001
From: Martchus <martchus@gmx.net>
Date: Sat, 5 Aug 2017 21:14:26 +0200
Subject: [PATCH 21/33] Allow usage of static version with CMake

Allow selecting between dynamic and static Qt versions
installed in the same prefix
 - Use eg. find_package(Qt5Core) for dynamic version
 - and eg. find_package(StaticQt5Core) for static version
 - Static targets are prefixed, eg. StaticQt5::Core
 - Set USE_STATIC_QT_BY_DEFAULT to use static version
   via regular find_package(Qt5Core)

Change-Id: I75f8ff616ad23038416be6271369f9dcc36f2528
---
 mkspecs/features/create_cmake.prf             |  96 ++++--
 .../data/cmake/Qt5BasicConfig.cmake.in        | 311 +++++++++++-------
 .../data/cmake/Qt5PluginTarget.cmake.in       |  32 +-
 .../cmake/Qt5StaticOnlyRedirection.cmake.in   |  11 +
 src/corelib/Qt5CoreConfigExtras.cmake.in      |  26 +-
 src/gui/Qt5GuiConfigExtras.cmake.in           |   8 +-
 src/testlib/Qt5TestConfigExtras.cmake.in      |   2 +-
 7 files changed, 319 insertions(+), 167 deletions(-)
 create mode 100644 mkspecs/features/data/cmake/Qt5StaticOnlyRedirection.cmake.in

diff --git a/mkspecs/features/create_cmake.prf b/mkspecs/features/create_cmake.prf
index 37689938eb..636a2af9b6 100644
--- a/mkspecs/features/create_cmake.prf
+++ b/mkspecs/features/create_cmake.prf
@@ -68,7 +68,7 @@ split_incpath {
             $$QT_MODULE_INCLUDE_BASE/$${CMAKE_INCLUDE_NAME}/$$eval(QT.$${MODULE}.VERSION)/$${CMAKE_INCLUDE_NAME})
 
     cmake_extra_source_includes.input = $$PWD/data/cmake/ExtraSourceIncludes.cmake.in
-    cmake_extra_source_includes.output = $$CMAKE_OUT_DIR/Qt5$${CMAKE_MODULE_NAME}/ExtraSourceIncludes.cmake
+    cmake_extra_source_includes.output = $$CMAKE_OUT_DIR/$${DEFAULT_QT_VARIANT_PREFIX}Qt5$${CMAKE_MODULE_NAME}/ExtraSourceIncludes.cmake
 
     !build_pass:QMAKE_SUBSTITUTES += \
         cmake_extra_source_includes
@@ -118,6 +118,8 @@ win32:!static:!staticlib {
 }
 
 static|staticlib:CMAKE_STATIC_TYPE = true
+static|staticlib:DEFAULT_QT_VARIANT_PREFIX = "Static"
+else:DEFAULT_QT_VARIANT_PREFIX = ""
 
 internal_module {
     CMAKE_INTERNAL_MODULE = true
@@ -214,20 +216,25 @@ contains(CONFIG, plugin) {
     win32 {
         !mingw|qtConfig(debug_and_release): debug_suffix="d"
 
-        CMAKE_PRL_FILE_LOCATION_RELEASE = $$PLUGIN_TYPE/$${CMAKE_QT_STEM}.prl
-        CMAKE_PRL_FILE_LOCATION_DEBUG = $$PLUGIN_TYPE/$${CMAKE_QT_STEM}$${debug_suffix}.prl
-
-        isEmpty(CMAKE_STATIC_TYPE) {
+        mingw {
             CMAKE_PLUGIN_LOCATION_RELEASE = $$PLUGIN_TYPE/$${CMAKE_QT_STEM}.dll
             CMAKE_PLUGIN_LOCATION_DEBUG = $$PLUGIN_TYPE/$${CMAKE_QT_STEM}$${debug_suffix}.dll
-        } else:mingw {
-            CMAKE_PLUGIN_LOCATION_RELEASE = $$PLUGIN_TYPE/lib$${CMAKE_QT_STEM}.a
-            CMAKE_PLUGIN_LOCATION_DEBUG = $$PLUGIN_TYPE/lib$${CMAKE_QT_STEM}$${debug_suffix}.a
+            CMAKE_PLUGIN_LOCATION_RELEASE_STATIC = $$PLUGIN_TYPE/lib$${CMAKE_QT_STEM}.a
+            CMAKE_PLUGIN_LOCATION_DEBUG_STATIC = $$PLUGIN_TYPE/lib$${CMAKE_QT_STEM}$${debug_suffix}.a
+            CMAKE_PRL_FILE_LOCATION_RELEASE = $$PLUGIN_TYPE/$${CMAKE_QT_STEM}.prl
+            CMAKE_PRL_FILE_LOCATION_DEBUG = $$PLUGIN_TYPE/$${CMAKE_QT_STEM}$${debug_suffix}.prl
+            CMAKE_PRL_FILE_LOCATION_RELEASE_STATIC = $$PLUGIN_TYPE/$${CMAKE_QT_STEM}.static.prl
+            CMAKE_PRL_FILE_LOCATION_DEBUG_STATIC = $$PLUGIN_TYPE/$${CMAKE_QT_STEM}$${debug_suffix}.static.prl
         } else {                         # MSVC static
             CMAKE_PLUGIN_LOCATION_RELEASE = $$PLUGIN_TYPE/$${CMAKE_QT_STEM}.lib
             CMAKE_PLUGIN_LOCATION_DEBUG = $$PLUGIN_TYPE/$${CMAKE_QT_STEM}$${debug_suffix}.lib
+            CMAKE_PLUGIN_LOCATION_RELEASE_STATIC = $$PLUGIN_TYPE/$${CMAKE_QT_STEM}.lib
+            CMAKE_PLUGIN_LOCATION_DEBUG_STATIC = $$PLUGIN_TYPE/$${CMAKE_QT_STEM}$${debug_suffix}.lib
+            CMAKE_PRL_FILE_LOCATION_RELEASE = $$PLUGIN_TYPE/$${CMAKE_QT_STEM}.prl
+            CMAKE_PRL_FILE_LOCATION_DEBUG = $$PLUGIN_TYPE/$${CMAKE_QT_STEM}$${debug_suffix}.prl
         }
     } else {
+        # this branch is broken by the patch, only apply when building for Windows
         mac {
             isEmpty(CMAKE_STATIC_TYPE): CMAKE_PLUGIN_EXT = .dylib
             else: CMAKE_PLUGIN_EXT = .a
@@ -247,9 +254,9 @@ contains(CONFIG, plugin) {
         }
     }
     cmake_target_file.input = $$PWD/data/cmake/Qt5PluginTarget.cmake.in
-    cmake_target_file.output = $$CMAKE_OUT_DIR/Qt5$${CMAKE_MODULE_NAME}/Qt5$${CMAKE_MODULE_NAME}_$${PLUGIN_CLASS_NAME}.cmake
+    cmake_target_file.output = $$CMAKE_OUT_DIR/$${DEFAULT_QT_VARIANT_PREFIX}Qt5$${CMAKE_MODULE_NAME}/$${DEFAULT_QT_VARIANT_PREFIX}Qt5$${CMAKE_MODULE_NAME}_$${PLUGIN_CLASS_NAME}.cmake
     cmake_qt5_plugin_import_file.input = $$PWD/data/cmake/Qt5ImportPlugin.cpp.in
-    cmake_qt5_plugin_import_file.output = $$CMAKE_OUT_DIR/Qt5$${CMAKE_MODULE_NAME}/Qt5$${CMAKE_MODULE_NAME}_$${PLUGIN_CLASS_NAME}_Import.cpp
+    cmake_qt5_plugin_import_file.output = $$CMAKE_OUT_DIR/$${DEFAULT_QT_VARIANT_PREFIX}Qt5$${CMAKE_MODULE_NAME}/Qt5$${CMAKE_MODULE_NAME}_$${PLUGIN_CLASS_NAME}_Import.cpp
 
     !build_pass {
         QMAKE_SUBSTITUTES += cmake_target_file
@@ -258,7 +265,7 @@ contains(CONFIG, plugin) {
 
     cmake_qt5_plugin_file.files = $$cmake_target_file.output
     static|staticlib: cmake_qt5_plugin_file.files += $$cmake_qt5_plugin_import_file.output
-    cmake_qt5_plugin_file.path = $$[QT_INSTALL_LIBS]/cmake/Qt5$${CMAKE_MODULE_NAME}
+    cmake_qt5_plugin_file.path = $$[QT_INSTALL_LIBS]/cmake/$${DEFAULT_QT_VARIANT_PREFIX}Qt5$${CMAKE_MODULE_NAME}
     INSTALLS += cmake_qt5_plugin_file
 
     return()
@@ -271,30 +278,38 @@ mod_deps =
 lib_deps =
 aux_mod_deps =
 aux_lib_deps =
+aux_compile_defs_static = QT_STATIC QT_DESIGNER_STATIC
+contains(QT_CONFIG, angle): aux_compile_defs += QT_OPENGL_ES_2_ANGLE_STATIC
 # Until CMake 3.0 is the minimum requirement of Qt 5, we need to filter
 # out header-only modules from dependencies.  CMake 3.0 provides INTERFACE
 # libraries which are equivalent to header-only modules.
 for (dep, sorted_deps) {
     cdep = $$cmakeModuleName($$dep)
     !contains(QT.$${dep}.module_config, no_link) {
-        mod_deps += $$cdep
-        lib_deps += Qt5::$$cdep
+        mod_deps += "$$cdep"
+        lib_deps += "${QT_VARIANT_PREFIX}Qt5::$$cdep"
+        lib_deps_static += "${QT_VARIANT_PREFIX}Qt5::$$cdep"
     } else {
-        aux_mod_deps += $$cdep
-        aux_lib_deps += Qt5::$$cdep
+        aux_mod_deps += "$$cdep"
+        aux_lib_deps += "${QT_VARIANT_PREFIX}Qt5::$$cdep"
+        aux_lib_deps_static += "${QT_VARIANT_PREFIX}Qt5::$$cdep"
     }
 }
 CMAKE_MODULE_DEPS = $$join(mod_deps, ";")
 CMAKE_QT5_MODULE_DEPS = $$join(lib_deps, ";")
+CMAKE_QT5_MODULE_DEPS_STATIC = $$join(lib_deps_static, ";")
 CMAKE_INTERFACE_MODULE_DEPS = $$join(aux_mod_deps, ";")
 CMAKE_INTERFACE_QT5_MODULE_DEPS = $$join(aux_lib_deps, ";")
 CMAKE_MODULE_PLUGIN_TYPES = $$join(QT.$${MODULE}.plugin_types, ";")
+CMAKE_INTERFACE_QT5_MODULE_DEPS_STATIC = $$join(aux_lib_deps_static, ";")
+CMAKE_INTERFACE_COMPILE_DEFINITIONS_STATIC = $$join(aux_compile_defs_static, ";")
 
 # Interface libraries have to have all properties starting with "INTERFACE_".
 CMAKE_FEATURE_PROPERTY_PREFIX = ""
 equals(TEMPLATE, aux): CMAKE_FEATURE_PROPERTY_PREFIX = "INTERFACE_"
 
 mac {
+    # this branch is broken by the patch, only apply when building for Windows
     !isEmpty(CMAKE_STATIC_TYPE) {
         CMAKE_LIB_FILE_LOCATION_DEBUG = lib$${CMAKE_QT_STEM}_debug.a
         CMAKE_LIB_FILE_LOCATION_RELEASE = lib$${CMAKE_QT_STEM}.a
@@ -321,13 +336,6 @@ mac {
     CMAKE_LIB_FILE_LOCATION_DEBUG = $${CMAKE_QT_STEM}$${debug_suffix}.dll
     CMAKE_LIB_FILE_LOCATION_RELEASE = $${CMAKE_QT_STEM}.dll
 
-    !isEmpty(CMAKE_STATIC_TYPE) {
-        CMAKE_STATIC_WINDOWS_BUILD = "true"
-
-        CMAKE_PRL_FILE_LOCATION_DEBUG = $${CMAKE_QT_STEM}$${debug_suffix}.prl
-        CMAKE_PRL_FILE_LOCATION_RELEASE = $${CMAKE_QT_STEM}.prl
-    }
-
     mingw {
         CMAKE_WINMAIN_FILE_LOCATION_DEBUG = libqt5main$${QT_LIBINFIX}$${debug_suffix}.a
         CMAKE_WINMAIN_FILE_LOCATION_RELEASE = libqt5main$${QT_LIBINFIX}.a
@@ -335,14 +343,30 @@ mac {
         isEmpty(QMAKE_EXTENSION_IMPORTLIB): QMAKE_EXTENSION_IMPORTLIB = a
         CMAKE_IMPLIB_FILE_LOCATION_DEBUG = lib$${CMAKE_QT_STEM}$${debug_suffix}.$${QMAKE_EXTENSION_IMPORTLIB}
         CMAKE_IMPLIB_FILE_LOCATION_RELEASE = lib$${CMAKE_QT_STEM}.$${QMAKE_EXTENSION_IMPORTLIB}
+        CMAKE_PRL_FILE_LOCATION_DEBUG = $${CMAKE_QT_STEM}$${debug_suffix}.prl
+        CMAKE_PRL_FILE_LOCATION_RELEASE = $${CMAKE_QT_STEM}.prl
+
+        CMAKE_IMPLIB_FILE_LOCATION_DEBUG_STATIC = lib$${CMAKE_QT_STEM}$${debug_suffix}.a
+        CMAKE_IMPLIB_FILE_LOCATION_RELEASE_STATIC = lib$${CMAKE_QT_STEM}.a
+        CMAKE_PRL_FILE_LOCATION_DEBUG_STATIC = $${CMAKE_QT_STEM}$${debug_suffix}.static.prl
+        CMAKE_PRL_FILE_LOCATION_RELEASE_STATIC = $${CMAKE_QT_STEM}.static.prl
+
     } else {
         CMAKE_WINMAIN_FILE_LOCATION_DEBUG = qt5main$${QT_LIBINFIX}$${debug_suffix}.lib
         CMAKE_WINMAIN_FILE_LOCATION_RELEASE = qt5main$${QT_LIBINFIX}.lib
 
         CMAKE_IMPLIB_FILE_LOCATION_DEBUG = $${CMAKE_QT_STEM}$${debug_suffix}.lib
         CMAKE_IMPLIB_FILE_LOCATION_RELEASE = $${CMAKE_QT_STEM}.lib
+        CMAKE_PRL_FILE_LOCATION_DEBUG = $${CMAKE_QT_STEM}$${debug_suffix}.prl
+        CMAKE_PRL_FILE_LOCATION_RELEASE = $${CMAKE_QT_STEM}.prl
+
+        CMAKE_IMPLIB_FILE_LOCATION_DEBUG_STATIC = $${CMAKE_QT_STEM}$${debug_suffix}.lib
+        CMAKE_IMPLIB_FILE_LOCATION_RELEASE_STATIC = $${CMAKE_QT_STEM}.lib
+        CMAKE_PRL_FILE_LOCATION_DEBUG_STATIC = $${CMAKE_QT_STEM}$${debug_suffix}.static.prl
+        CMAKE_PRL_FILE_LOCATION_RELEASE_STATIC = $${CMAKE_QT_STEM}.static.prl
     }
 } else {
+    # this branch is broken by the patch, only apply when building for Windows
     !isEmpty(CMAKE_STATIC_TYPE) {
         CMAKE_LIB_FILE_LOCATION_DEBUG = lib$${CMAKE_QT_STEM}.a
         CMAKE_LIB_FILE_LOCATION_RELEASE = lib$${CMAKE_QT_STEM}.a
@@ -362,12 +386,12 @@ mac {
 INSTALLS += cmake_qt5_module_files
 
 cmake_config_file.input = $$PWD/data/cmake/Qt5BasicConfig.cmake.in
-cmake_config_file.output = $$CMAKE_OUT_DIR/Qt5$${CMAKE_MODULE_NAME}/Qt5$${CMAKE_MODULE_NAME}Config.cmake
+cmake_config_file.output = $$CMAKE_OUT_DIR/$${DEFAULT_QT_VARIANT_PREFIX}Qt5$${CMAKE_MODULE_NAME}/$${DEFAULT_QT_VARIANT_PREFIX}Qt5$${CMAKE_MODULE_NAME}Config.cmake
 
 CMAKE_PACKAGE_VERSION = $$eval(QT.$${MODULE}.VERSION)
 
 cmake_config_version_file.input = $$PWD/data/cmake/Qt5ConfigVersion.cmake.in
-cmake_config_version_file.output = $$CMAKE_OUT_DIR/Qt5$${CMAKE_MODULE_NAME}/Qt5$${CMAKE_MODULE_NAME}ConfigVersion.cmake
+cmake_config_version_file.output = $$CMAKE_OUT_DIR/$${DEFAULT_QT_VARIANT_PREFIX}Qt5$${CMAKE_MODULE_NAME}/$${DEFAULT_QT_VARIANT_PREFIX}Qt5$${CMAKE_MODULE_NAME}ConfigVersion.cmake
 
 !build_pass:QMAKE_SUBSTITUTES += \
     cmake_config_file \
@@ -377,11 +401,29 @@ cmake_qt5_module_files.files = \
     $$cmake_config_file.output \
     $$cmake_config_version_file.output
 
+# add regular CMake package for static-only modules
+static|staticlib:actually_a_shared_build {
+    INSTALLS += cmake_qt5_module_files_shared
+
+    cmake_config_file_shared.input = $$PWD/data/cmake/Qt5StaticOnlyRedirection.cmake.in
+    cmake_config_file_shared.output = $$CMAKE_OUT_DIR/Qt5$${CMAKE_MODULE_NAME}/Qt5$${CMAKE_MODULE_NAME}Config.cmake
+    cmake_config_version_file_shared.input = $$PWD/data/cmake/Qt5ConfigVersion.cmake.in
+    cmake_config_version_file_shared.output = $$CMAKE_OUT_DIR/Qt5$${CMAKE_MODULE_NAME}/Qt5$${CMAKE_MODULE_NAME}ConfigVersion.cmake
+    !build_pass:QMAKE_SUBSTITUTES += \
+        cmake_config_file_shared \
+        cmake_config_version_file_shared
+
+    cmake_qt5_module_files_shared.files = \
+        $$cmake_config_file_shared.output \
+        $$cmake_config_version_file_shared.output
+    cmake_qt5_module_files_shared.path = $$[QT_INSTALL_LIBS]/cmake/Qt5$${CMAKE_MODULE_NAME}
+}
+
 cmake_extras_file.input = $$_PRO_FILE_PWD_/Qt5$${CMAKE_MODULE_NAME}ConfigExtras.cmake.in
 exists($$cmake_extras_file.input) {
 
     CMAKE_MODULE_EXTRAS = "true"
-    cmake_extras_file.output = $$CMAKE_OUT_DIR/Qt5$${CMAKE_MODULE_NAME}/Qt5$${CMAKE_MODULE_NAME}ConfigExtras.cmake
+    cmake_extras_file.output = $$CMAKE_OUT_DIR/$${DEFAULT_QT_VARIANT_PREFIX}Qt5$${CMAKE_MODULE_NAME}/$${DEFAULT_QT_VARIANT_PREFIX}Qt5$${CMAKE_MODULE_NAME}ConfigExtras.cmake
 
     !build_pass:QMAKE_SUBSTITUTES += cmake_extras_file
 
@@ -393,7 +435,7 @@ cmake_macros_file.input = $$_PRO_FILE_PWD_/Qt5$${CMAKE_MODULE_NAME}Macros.cmake
 exists($$cmake_macros_file.input) {
     CMAKE_MODULE_MACROS = "true"
 
-    cmake_macros_file.output = $$CMAKE_OUT_DIR/Qt5$${CMAKE_MODULE_NAME}/Qt5$${CMAKE_MODULE_NAME}Macros.cmake
+    cmake_macros_file.output = $$CMAKE_OUT_DIR/$${DEFAULT_QT_VARIANT_PREFIX}Qt5$${CMAKE_MODULE_NAME}/$${DEFAULT_QT_VARIANT_PREFIX}Qt5$${CMAKE_MODULE_NAME}Macros.cmake
     cmake_macros_file.CONFIG = verbatim
 
     !build_pass:QMAKE_SUBSTITUTES += cmake_macros_file
@@ -401,7 +443,7 @@ exists($$cmake_macros_file.input) {
     cmake_qt5_module_files.files += $$cmake_macros_file.output
 }
 
-cmake_qt5_module_files.path = $$[QT_INSTALL_LIBS]/cmake/Qt5$${CMAKE_MODULE_NAME}
+cmake_qt5_module_files.path = $$[QT_INSTALL_LIBS]/cmake/$${DEFAULT_QT_VARIANT_PREFIX}Qt5$${CMAKE_MODULE_NAME}
 
 # We are generating cmake files. Most developers of Qt are not aware of cmake,
 # so we require automatic tests to be available. The only module which should
diff --git a/mkspecs/features/data/cmake/Qt5BasicConfig.cmake.in b/mkspecs/features/data/cmake/Qt5BasicConfig.cmake.in
index 5a5bc4d61d..97150fb244 100644
--- a/mkspecs/features/data/cmake/Qt5BasicConfig.cmake.in
+++ b/mkspecs/features/data/cmake/Qt5BasicConfig.cmake.in
@@ -2,6 +2,33 @@ if (CMAKE_VERSION VERSION_LESS 3.1.0)
     message(FATAL_ERROR \"Qt 5 $${CMAKE_MODULE_NAME} module requires at least CMake version 3.1.0\")
 endif()
 
+!!IF isEmpty(CMAKE_STATIC_TYPE)
+# "redirect" to static package overriding variant prefix so it does not contain "Static" anymore
+option(USE_STATIC_QT_BY_DEFAULT \"specifies whether to use static Qt by default (rather than via Static-prefix)\" OFF)
+if(USE_STATIC_QT_BY_DEFAULT)
+    set(ORIGINAL_OVERRIDE_QT_VARIANT_PREFIX "${OVERRIDE_QT_VARIANT_PREFIX}")
+    if(OVERRIDE_QT_VARIANT_PREFIX)
+        string(REPLACE \"Static\" \"\" OVERRIDE_QT_VARIANT_PREFIX "${OVERRIDE_QT_VARIANT_PREFIX}")
+    endif()
+    if(NOT OVERRIDE_QT_VARIANT_PREFIX)
+        set(OVERRIDE_QT_VARIANT_PREFIX "none")
+    endif()
+    find_package(StaticQt5$${CMAKE_MODULE_NAME})
+    set(OVERRIDE_QT_VARIANT_PREFIX "${ORIGINAL_OVERRIDE_QT_VARIANT_PREFIX}")
+    return()
+endif()
+!!ENDIF
+
+if(OVERRIDE_QT_VARIANT_PREFIX)
+    if(OVERRIDE_QT_VARIANT_PREFIX STREQUAL "none")
+        unset(QT_VARIANT_PREFIX)
+    else()
+        set(QT_VARIANT_PREFIX "${OVERRIDE_QT_VARIANT_PREFIX}")
+    endif()
+else()
+    set(QT_VARIANT_PREFIX \"$${DEFAULT_QT_VARIANT_PREFIX}\")
+endif()
+
 !!IF !isEmpty(CMAKE_USR_MOVE_WORKAROUND)
 !!IF !isEmpty(CMAKE_LIB_DIR_IS_ABSOLUTE)
 set(_qt5$${CMAKE_MODULE_NAME}_install_prefix \"$$[QT_INSTALL_PREFIX]\")
@@ -28,15 +55,19 @@ set(_qt5$${CMAKE_MODULE_NAME}_install_prefix \"$$[QT_INSTALL_PREFIX]\")
 
 !!IF !equals(TEMPLATE, aux)
 # For backwards compatibility only. Use Qt5$${CMAKE_MODULE_NAME}_VERSION instead.
-set(Qt5$${CMAKE_MODULE_NAME}_VERSION_STRING "$$eval(QT.$${MODULE}.VERSION)")
+set(${QT_VARIANT_PREFIX}Qt5$${CMAKE_MODULE_NAME}_VERSION_STRING "$$eval(QT.$${MODULE}.VERSION)")
 
-set(Qt5$${CMAKE_MODULE_NAME}_LIBRARIES Qt5::$${CMAKE_MODULE_NAME})
+set(${QT_VARIANT_PREFIX}Qt5$${CMAKE_MODULE_NAME}_LIBRARIES ${QT_VARIANT_PREFIX}Qt5::$${CMAKE_MODULE_NAME})
 !!ENDIF // TEMPLATE != aux
 
-macro(_qt5_$${CMAKE_MODULE_NAME}_check_file_exists file)
-    if(NOT EXISTS \"${file}\" )
-        message(FATAL_ERROR \"The imported target \\\"Qt5::$${CMAKE_MODULE_NAME}\\\" references the file
-   \\\"${file}\\\"
+!!IF !isEmpty(CMAKE_STATIC_TYPE)
+macro(_qt5_$${CMAKE_MODULE_NAME}_check_file_exists_static FILE)
+!!ELSE
+macro(_qt5_$${CMAKE_MODULE_NAME}_check_file_exists FILE)
+!!ENDIF
+    if(NOT EXISTS \"${FILE}\")
+        message(FATAL_ERROR \"The imported target \\\"${QT_VARIANT_PREFIX}Qt5::$${CMAKE_MODULE_NAME}\\\" references the file
+   \\\"${FILE}\\\"
 but this file does not exist.  Possible reasons include:
 * The file was deleted, renamed, or moved to another location.
 * An install or uninstall procedure did not complete successfully.
@@ -177,12 +208,24 @@ if(NOT COMMAND _qt5_add_dependencies)
         endif()
     endfunction()
 endif()
+
+# ensure also regular/dynamic macro exists because it might be used in some extra config
+if(NOT COMMAND _qt5_$${CMAKE_MODULE_NAME}_check_file_exists)
+    macro(_qt5_$${CMAKE_MODULE_NAME}_check_file_exists FILE)
+        _qt5_$${CMAKE_MODULE_NAME}_check_file_exists_static(\"${FILE}\")
+    endmacro()
+endif()
 !!ENDIF
 
 !!IF !equals(TEMPLATE, aux)
-macro(_populate_$${CMAKE_MODULE_NAME}_target_properties Configuration LIB_LOCATION IMPLIB_LOCATION
+!!IF !isEmpty(CMAKE_STATIC_TYPE)
+macro(_populate_$${CMAKE_MODULE_NAME}_target_properties_static TARGET_NAME Configuration LIB_LOCATION IMPLIB_LOCATION
+      IsDebugAndRelease)
+!!ELSE
+macro(_populate_$${CMAKE_MODULE_NAME}_target_properties TARGET_NAME Configuration LIB_LOCATION IMPLIB_LOCATION
       IsDebugAndRelease)
-    set_property(TARGET Qt5::$${CMAKE_MODULE_NAME} APPEND PROPERTY IMPORTED_CONFIGURATIONS ${Configuration})
+!!ENDIF
+    set_property(TARGET ${TARGET_NAME} APPEND PROPERTY IMPORTED_CONFIGURATIONS ${Configuration})
 
 !!IF isEmpty(CMAKE_DLL_DIR_IS_ABSOLUTE)
     set(imported_location \"${_qt5$${CMAKE_MODULE_NAME}_install_prefix}/$${CMAKE_DLL_DIR}${LIB_LOCATION}\")
@@ -200,20 +243,20 @@ macro(_populate_$${CMAKE_MODULE_NAME}_target_properties Configuration LIB_LOCATI
     # FIXME: handle IsDebugAndRelease like in official version
 
 !!IF !isEmpty(CMAKE_STATIC_TYPE)
-    set_target_properties(Qt5::$${CMAKE_MODULE_NAME} PROPERTIES
+    set_target_properties(\"${TARGET_NAME}\" PROPERTIES
         \"IMPORTED_LOCATION_${Configuration}\" ${imported_location}
 !!IF !isEmpty(CMAKE_LIB_SONAME)
         \"IMPORTED_SONAME_${Configuration}\" \"$${CMAKE_LIB_SONAME}\"
 !!ENDIF
     )
-    _qt5_add_dependencies(Qt5::$${CMAKE_MODULE_NAME} \"${Configuration}\" \"${_deps}\")
+    _qt5_add_dependencies(\"${TARGET_NAME}\" \"${Configuration}\" \"${_deps}\")
     if(NOT CMAKE_VERSION VERSION_LESS \"3.13\")
-        set_target_properties(Qt5::$${CMAKE_MODULE_NAME} PROPERTIES
+        set_target_properties(\"${TARGET_NAME}\" PROPERTIES
             \"INTERFACE_LINK_OPTIONS\" \"${_Qt5$${CMAKE_MODULE_NAME}_STATIC_${Configuration}_LINK_FLAGS}\"
         )
     endif()
 !!ELSE
-    set_target_properties(Qt5::$${CMAKE_MODULE_NAME} PROPERTIES
+    set_target_properties(\"${TARGET_NAME}\" PROPERTIES
         \"INTERFACE_LINK_LIBRARIES_${Configuration}\" \"${_deps}\"
         \"IMPORTED_LOCATION_${Configuration}\" ${imported_location}
 !!IF !isEmpty(CMAKE_LIB_SONAME)
@@ -230,9 +273,13 @@ macro(_populate_$${CMAKE_MODULE_NAME}_target_properties Configuration LIB_LOCATI
 !!ELSE
     set(imported_implib \"IMPORTED_IMPLIB_${Configuration}\" \"$${CMAKE_LIB_DIR}${IMPLIB_LOCATION}\")
 !!ENDIF
+!!IF !isEmpty(CMAKE_STATIC_TYPE)
+    _qt5_$${CMAKE_MODULE_NAME}_check_file_exists_static(${imported_implib})
+!!ELSE
     _qt5_$${CMAKE_MODULE_NAME}_check_file_exists(${imported_implib})
+!!ENDIF
     if(NOT \"${IMPLIB_LOCATION}\" STREQUAL \"\")
-        set_target_properties(Qt5::$${CMAKE_MODULE_NAME} PROPERTIES
+        set_target_properties(${QT_VARIANT_PREFIX}Qt5::$${CMAKE_MODULE_NAME} PROPERTIES
         \"IMPORTED_IMPLIB_${Configuration}\" ${imported_implib}
         )
     endif()
@@ -249,8 +296,7 @@ macro(_populate_$${CMAKE_MODULE_NAME}_plugin_target_dependencies_from_prl_file P
 endmacro()
 !!ENDIF
 
-if (NOT TARGET Qt5::$${CMAKE_MODULE_NAME})
-
+if(NOT TARGET ${QT_VARIANT_PREFIX}Qt5::$${CMAKE_MODULE_NAME})
 !!IF !no_module_headers
 !!IF !isEmpty(CMAKE_BUILD_IS_FRAMEWORK)
     set(_Qt5$${CMAKE_MODULE_NAME}_OWN_INCLUDE_DIRS
@@ -258,46 +304,50 @@ if (NOT TARGET Qt5::$${CMAKE_MODULE_NAME})
       \"${_qt5$${CMAKE_MODULE_NAME}_install_prefix}/$${CMAKE_LIB_DIR}$${CMAKE_QT_STEM}.framework/Headers\"
     )
 !!IF isEmpty(CMAKE_NO_PRIVATE_INCLUDES)
-    set(Qt5$${CMAKE_MODULE_NAME}_PRIVATE_INCLUDE_DIRS
+    set(${QT_VARIANT_PREFIX}Qt5$${CMAKE_MODULE_NAME}_PRIVATE_INCLUDE_DIRS
         \"${_qt5$${CMAKE_MODULE_NAME}_install_prefix}/$${CMAKE_LIB_DIR}$${CMAKE_QT_STEM}.framework/Versions/$$section(VERSION, ., 0, 0)/Headers/$$VERSION/\"
         \"${_qt5$${CMAKE_MODULE_NAME}_install_prefix}/$${CMAKE_LIB_DIR}$${CMAKE_QT_STEM}.framework/Versions/$$section(VERSION, ., 0, 0)/Headers/$$VERSION/$${MODULE_INCNAME}\"
     )
-!!ELSE
-    set(Qt5$${CMAKE_MODULE_NAME}_PRIVATE_INCLUDE_DIRS \"\")
-!!ENDIF
-!!ELSE
+!!ELSE // isEmpty(CMAKE_NO_PRIVATE_INCLUDES)
+    set(${QT_VARIANT_PREFIX}Qt5$${CMAKE_MODULE_NAME}_PRIVATE_INCLUDE_DIRS \"\")
+!!ENDIF // isEmpty(CMAKE_NO_PRIVATE_INCLUDES)
+!!ELSE // !isEmpty(CMAKE_BUILD_IS_FRAMEWORK)
 !!IF isEmpty(CMAKE_INCLUDE_DIR_IS_ABSOLUTE)
     set(_Qt5$${CMAKE_MODULE_NAME}_OWN_INCLUDE_DIRS \"${_qt5$${CMAKE_MODULE_NAME}_install_prefix}/$$CMAKE_INCLUDE_DIR\" \"${_qt5$${CMAKE_MODULE_NAME}_install_prefix}/$${CMAKE_INCLUDE_DIR}$${MODULE_INCNAME}\")
 !!IF isEmpty(CMAKE_NO_PRIVATE_INCLUDES)
-    set(Qt5$${CMAKE_MODULE_NAME}_PRIVATE_INCLUDE_DIRS
+    set(${QT_VARIANT_PREFIX}Qt5$${CMAKE_MODULE_NAME}_PRIVATE_INCLUDE_DIRS
         \"${_qt5$${CMAKE_MODULE_NAME}_install_prefix}/$${CMAKE_INCLUDE_DIR}$${MODULE_INCNAME}/$$VERSION\"
         \"${_qt5$${CMAKE_MODULE_NAME}_install_prefix}/$${CMAKE_INCLUDE_DIR}$${MODULE_INCNAME}/$$VERSION/$${MODULE_INCNAME}\"
     )
 !!ELSE
-    set(Qt5$${CMAKE_MODULE_NAME}_PRIVATE_INCLUDE_DIRS \"\")
+    set(${QT_VARIANT_PREFIX}Qt5$${CMAKE_MODULE_NAME}_PRIVATE_INCLUDE_DIRS \"\")
 !!ENDIF
 !!ELSE
     set(_Qt5$${CMAKE_MODULE_NAME}_OWN_INCLUDE_DIRS \"$$CMAKE_INCLUDE_DIR\" \"$${CMAKE_INCLUDE_DIR}$${CMAKE_INCLUDE_NAME}\")
 !!IF isEmpty(CMAKE_NO_PRIVATE_INCLUDES)
-    set(Qt5$${CMAKE_MODULE_NAME}_PRIVATE_INCLUDE_DIRS
+    set(${QT_VARIANT_PREFIX}Qt5$${CMAKE_MODULE_NAME}_PRIVATE_INCLUDE_DIRS
         \"$${CMAKE_INCLUDE_DIR}$${MODULE_INCNAME}/$$VERSION\"
         \"$${CMAKE_INCLUDE_DIR}$${MODULE_INCNAME}/$$VERSION/$${MODULE_INCNAME}\"
     )
-!!ELSE
-    set(Qt5$${CMAKE_MODULE_NAME}_PRIVATE_INCLUDE_DIRS \"\")
-!!ENDIF
-!!ENDIF
-!!ENDIF
+!!ELSE // isEmpty(CMAKE_NO_PRIVATE_INCLUDES)
+    set(${QT_VARIANT_PREFIX}Qt5$${CMAKE_MODULE_NAME}_PRIVATE_INCLUDE_DIRS \"\")
+!!ENDIF // isEmpty(CMAKE_NO_PRIVATE_INCLUDES)
+!!ENDIF // isEmpty(CMAKE_INCLUDE_DIR_IS_ABSOLUTE)
+!!ENDIF // !isEmpty(CMAKE_BUILD_IS_FRAMEWORK)
 !!IF !isEmpty(CMAKE_ADD_SOURCE_INCLUDE_DIRS)
     include(\"${CMAKE_CURRENT_LIST_DIR}/ExtraSourceIncludes.cmake\" OPTIONAL)
 !!ENDIF
 !!ELSE
     set(_Qt5$${CMAKE_MODULE_NAME}_OWN_INCLUDE_DIRS \"\")
-    set(Qt5$${CMAKE_MODULE_NAME}_PRIVATE_INCLUDE_DIRS \"\")
+    set(${QT_VARIANT_PREFIX}Qt5$${CMAKE_MODULE_NAME}_PRIVATE_INCLUDE_DIRS \"\")
 !!ENDIF
 
     foreach(_dir ${_Qt5$${CMAKE_MODULE_NAME}_OWN_INCLUDE_DIRS})
+!!IF !isEmpty(CMAKE_STATIC_TYPE)
+        _qt5_$${CMAKE_MODULE_NAME}_check_file_exists_static(${_dir})
+!!ELSE
         _qt5_$${CMAKE_MODULE_NAME}_check_file_exists(${_dir})
+!!ENDIF
     endforeach()
 
 !!IF isEmpty(CMAKE_BUILD_IS_FRAMEWORK)
@@ -306,16 +356,20 @@ if (NOT TARGET Qt5::$${CMAKE_MODULE_NAME})
     list(FIND Qt5$${CMAKE_MODULE_NAME}_FIND_COMPONENTS Private _check_private)
     if (NOT _check_private STREQUAL -1)
         foreach(_dir ${Qt5$${CMAKE_MODULE_NAME}_PRIVATE_INCLUDE_DIRS})
+!!IF !isEmpty(CMAKE_STATIC_TYPE)
+            _qt5_$${CMAKE_MODULE_NAME}_check_file_exists_static(${_dir})
+!!ELSE
             _qt5_$${CMAKE_MODULE_NAME}_check_file_exists(${_dir})
+!!ENDIF
         endforeach()
     endif()
 !!ENDIF
 
 !!IF !equals(TEMPLATE, aux)
-    set(Qt5$${CMAKE_MODULE_NAME}_INCLUDE_DIRS ${_Qt5$${CMAKE_MODULE_NAME}_OWN_INCLUDE_DIRS})
+    set(${QT_VARIANT_PREFIX}Qt5$${CMAKE_MODULE_NAME}_INCLUDE_DIRS ${_Qt5$${CMAKE_MODULE_NAME}_OWN_INCLUDE_DIRS})
 
-    set(Qt5$${CMAKE_MODULE_NAME}_DEFINITIONS -D$${MODULE_DEFINE})
-    set(Qt5$${CMAKE_MODULE_NAME}_COMPILE_DEFINITIONS $${MODULE_DEFINES})
+    set(${QT_VARIANT_PREFIX}Qt5$${CMAKE_MODULE_NAME}_DEFINITIONS -D$${MODULE_DEFINE})
+    set(${QT_VARIANT_PREFIX}Qt5$${CMAKE_MODULE_NAME}_COMPILE_DEFINITIONS $${MODULE_DEFINES})
 !!ENDIF // TEMPLATE != aux
     set(_Qt5$${CMAKE_MODULE_NAME}_MODULE_DEPENDENCIES \"$${CMAKE_MODULE_DEPS}\")
 
@@ -323,10 +377,10 @@ if (NOT TARGET Qt5::$${CMAKE_MODULE_NAME})
     list(APPEND _Qt5$${CMAKE_MODULE_NAME}_MODULE_DEPENDENCIES \"$${CMAKE_INTERFACE_MODULE_DEPS}\")
 !!ENDIF
 
-    set(Qt5$${CMAKE_MODULE_NAME}_OWN_PRIVATE_INCLUDE_DIRS ${Qt5$${CMAKE_MODULE_NAME}_PRIVATE_INCLUDE_DIRS})
+    set(${QT_VARIANT_PREFIX}Qt5$${CMAKE_MODULE_NAME}_OWN_PRIVATE_INCLUDE_DIRS ${Qt5$${CMAKE_MODULE_NAME}_PRIVATE_INCLUDE_DIRS})
 
     set(_Qt5$${CMAKE_MODULE_NAME}_FIND_DEPENDENCIES_REQUIRED)
-    if (Qt5$${CMAKE_MODULE_NAME}_FIND_REQUIRED)
+    if (${QT_VARIANT_PREFIX}Qt5$${CMAKE_MODULE_NAME}_FIND_REQUIRED)
         set(_Qt5$${CMAKE_MODULE_NAME}_FIND_DEPENDENCIES_REQUIRED REQUIRED)
     endif()
     set(_Qt5$${CMAKE_MODULE_NAME}_FIND_DEPENDENCIES_QUIET)
@@ -334,17 +388,17 @@ if (NOT TARGET Qt5::$${CMAKE_MODULE_NAME})
         set(_Qt5$${CMAKE_MODULE_NAME}_DEPENDENCIES_FIND_QUIET QUIET)
     endif()
     set(_Qt5$${CMAKE_MODULE_NAME}_FIND_VERSION_EXACT)
-    if (Qt5$${CMAKE_MODULE_NAME}_FIND_VERSION_EXACT)
+    if (${QT_VARIANT_PREFIX}Qt5$${CMAKE_MODULE_NAME}_FIND_VERSION_EXACT)
         set(_Qt5$${CMAKE_MODULE_NAME}_FIND_VERSION_EXACT EXACT)
     endif()
 
 !!IF !equals(TEMPLATE, aux)
-    set(Qt5$${CMAKE_MODULE_NAME}_EXECUTABLE_COMPILE_FLAGS \"\")
+    set(${QT_VARIANT_PREFIX}Qt5$${CMAKE_MODULE_NAME}_EXECUTABLE_COMPILE_FLAGS \"\")
 !!ENDIF // TEMPLATE != aux
 
     foreach(_module_dep ${_Qt5$${CMAKE_MODULE_NAME}_MODULE_DEPENDENCIES})
-        if (NOT Qt5${_module_dep}_FOUND)
-            find_package(Qt5${_module_dep}
+        if (NOT ${QT_VARIANT_PREFIX}Qt5${_module_dep}_FOUND)
+            find_package(${QT_VARIANT_PREFIX}Qt5${_module_dep}
                 $$VERSION ${_Qt5$${CMAKE_MODULE_NAME}_FIND_VERSION_EXACT}
                 ${_Qt5$${CMAKE_MODULE_NAME}_DEPENDENCIES_FIND_QUIET}
                 ${_Qt5$${CMAKE_MODULE_NAME}_FIND_DEPENDENCIES_REQUIRED}
@@ -352,25 +406,25 @@ if (NOT TARGET Qt5::$${CMAKE_MODULE_NAME})
             )
         endif()
 
-        if (NOT Qt5${_module_dep}_FOUND)
-            set(Qt5$${CMAKE_MODULE_NAME}_FOUND False)
+        if (NOT ${QT_VARIANT_PREFIX}Qt5${_module_dep}_FOUND)
+            set(${QT_VARIANT_PREFIX}Qt5$${CMAKE_MODULE_NAME}_FOUND False)
             return()
         endif()
 
 !!IF !equals(TEMPLATE, aux)
-        list(APPEND Qt5$${CMAKE_MODULE_NAME}_INCLUDE_DIRS \"${Qt5${_module_dep}_INCLUDE_DIRS}\")
-        list(APPEND Qt5$${CMAKE_MODULE_NAME}_PRIVATE_INCLUDE_DIRS \"${Qt5${_module_dep}_PRIVATE_INCLUDE_DIRS}\")
-        list(APPEND Qt5$${CMAKE_MODULE_NAME}_DEFINITIONS ${Qt5${_module_dep}_DEFINITIONS})
-        list(APPEND Qt5$${CMAKE_MODULE_NAME}_COMPILE_DEFINITIONS ${Qt5${_module_dep}_COMPILE_DEFINITIONS})
-        list(APPEND Qt5$${CMAKE_MODULE_NAME}_EXECUTABLE_COMPILE_FLAGS ${Qt5${_module_dep}_EXECUTABLE_COMPILE_FLAGS})
+        list(APPEND ${QT_VARIANT_PREFIX}Qt5$${CMAKE_MODULE_NAME}_INCLUDE_DIRS \"${Qt5${_module_dep}_INCLUDE_DIRS}\")
+        list(APPEND ${QT_VARIANT_PREFIX}Qt5$${CMAKE_MODULE_NAME}_PRIVATE_INCLUDE_DIRS \"${Qt5${_module_dep}_PRIVATE_INCLUDE_DIRS}\")
+        list(APPEND ${QT_VARIANT_PREFIX}Qt5$${CMAKE_MODULE_NAME}_DEFINITIONS ${Qt5${_module_dep}_DEFINITIONS})
+        list(APPEND ${QT_VARIANT_PREFIX}Qt5$${CMAKE_MODULE_NAME}_COMPILE_DEFINITIONS ${Qt5${_module_dep}_COMPILE_DEFINITIONS})
+        list(APPEND ${QT_VARIANT_PREFIX}Qt5$${CMAKE_MODULE_NAME}_EXECUTABLE_COMPILE_FLAGS ${Qt5${_module_dep}_EXECUTABLE_COMPILE_FLAGS})
 !!ENDIF // TEMPLATE != aux
     endforeach()
 !!IF !equals(TEMPLATE, aux)
-    list(REMOVE_DUPLICATES Qt5$${CMAKE_MODULE_NAME}_INCLUDE_DIRS)
-    list(REMOVE_DUPLICATES Qt5$${CMAKE_MODULE_NAME}_PRIVATE_INCLUDE_DIRS)
-    list(REMOVE_DUPLICATES Qt5$${CMAKE_MODULE_NAME}_DEFINITIONS)
-    list(REMOVE_DUPLICATES Qt5$${CMAKE_MODULE_NAME}_COMPILE_DEFINITIONS)
-    list(REMOVE_DUPLICATES Qt5$${CMAKE_MODULE_NAME}_EXECUTABLE_COMPILE_FLAGS)
+    list(REMOVE_DUPLICATES ${QT_VARIANT_PREFIX}Qt5$${CMAKE_MODULE_NAME}_INCLUDE_DIRS)
+    list(REMOVE_DUPLICATES ${QT_VARIANT_PREFIX}Qt5$${CMAKE_MODULE_NAME}_PRIVATE_INCLUDE_DIRS)
+    list(REMOVE_DUPLICATES ${QT_VARIANT_PREFIX}Qt5$${CMAKE_MODULE_NAME}_DEFINITIONS)
+    list(REMOVE_DUPLICATES ${QT_VARIANT_PREFIX}Qt5$${CMAKE_MODULE_NAME}_COMPILE_DEFINITIONS)
+    list(REMOVE_DUPLICATES ${QT_VARIANT_PREFIX}Qt5$${CMAKE_MODULE_NAME}_EXECUTABLE_COMPILE_FLAGS)
 !!ENDIF // TEMPLATE != aux
 
     # It can happen that the same FooConfig.cmake file is included when calling find_package()
@@ -385,11 +439,16 @@ if (NOT TARGET Qt5::$${CMAKE_MODULE_NAME})
     #
     # Make sure to return early in the original Config inclusion, because the target has already
     # been defined as part of the second inclusion.
-    if(TARGET Qt5::$${CMAKE_MODULE_NAME})
+    set(TARGET_NAME ${QT_VARIANT_PREFIX}Qt5::$${CMAKE_MODULE_NAME})
+    if(TARGET ${TARGET_NAME})
         return()
     endif()
 
+!!IF !isEmpty(CMAKE_STATIC_TYPE)
+    set(_Qt5$${CMAKE_MODULE_NAME}_LIB_DEPENDENCIES \"$${CMAKE_QT5_MODULE_DEPS_STATIC}\")
+!!ELSE
     set(_Qt5$${CMAKE_MODULE_NAME}_LIB_DEPENDENCIES \"$${CMAKE_QT5_MODULE_DEPS}\")
+!!ENDIF
 
 !!IF !isEmpty(CMAKE_INTERFACE_QT5_MODULE_DEPS)
     list(APPEND _Qt5$${CMAKE_MODULE_NAME}_LIB_DEPENDENCIES \"$${CMAKE_INTERFACE_QT5_MODULE_DEPS}\")
@@ -400,13 +459,13 @@ if (NOT TARGET Qt5::$${CMAKE_MODULE_NAME})
 !!IF !isEmpty(CMAKE_DEBUG_TYPE)
 !!IF isEmpty(CMAKE_LIB_DIR_IS_ABSOLUTE)
         _qt5_$${CMAKE_MODULE_NAME}_process_prl_file(
-            \"${_qt5$${CMAKE_MODULE_NAME}_install_prefix}/$${CMAKE_LIB_DIR}$${CMAKE_PRL_FILE_LOCATION_DEBUG}\" DEBUG
+            \"${_qt5$${CMAKE_MODULE_NAME}_install_prefix}/$${CMAKE_LIB_DIR}$${CMAKE_PRL_FILE_LOCATION_DEBUG_STATIC}\" DEBUG
             _Qt5$${CMAKE_MODULE_NAME}_STATIC_DEBUG_LIB_DEPENDENCIES
             _Qt5$${CMAKE_MODULE_NAME}_STATIC_DEBUG_LINK_FLAGS
         )
 !!ELSE
         _qt5_$${CMAKE_MODULE_NAME}_process_prl_file(
-            \"$${CMAKE_LIB_DIR}$${CMAKE_PRL_FILE_LOCATION_DEBUG}\" DEBUG
+            \"$${CMAKE_LIB_DIR}$${CMAKE_PRL_FILE_LOCATION_DEBUG_STATIC}\" DEBUG
             _Qt5$${CMAKE_MODULE_NAME}_STATIC_DEBUG_LIB_DEPENDENCIES
             _Qt5$${CMAKE_MODULE_NAME}_STATIC_DEBUG_LINK_FLAGS
         )
@@ -416,13 +475,13 @@ if (NOT TARGET Qt5::$${CMAKE_MODULE_NAME})
 !!IF !isEmpty(CMAKE_RELEASE_TYPE)
 !!IF isEmpty(CMAKE_LIB_DIR_IS_ABSOLUTE)
         _qt5_$${CMAKE_MODULE_NAME}_process_prl_file(
-            \"${_qt5$${CMAKE_MODULE_NAME}_install_prefix}/$${CMAKE_LIB_DIR}$${CMAKE_PRL_FILE_LOCATION_RELEASE}\" RELEASE
+            \"${_qt5$${CMAKE_MODULE_NAME}_install_prefix}/$${CMAKE_LIB_DIR}$${CMAKE_PRL_FILE_LOCATION_RELEASE_STATIC}\" RELEASE
             _Qt5$${CMAKE_MODULE_NAME}_STATIC_RELEASE_LIB_DEPENDENCIES
             _Qt5$${CMAKE_MODULE_NAME}_STATIC_RELEASE_LINK_FLAGS
         )
 !!ELSE
         _qt5_$${CMAKE_MODULE_NAME}_process_prl_file(
-            \"$${CMAKE_LIB_DIR}$${CMAKE_PRL_FILE_LOCATION_RELEASE}\" RELEASE
+            \"$${CMAKE_LIB_DIR}$${CMAKE_PRL_FILE_LOCATION_RELEASE_STATIC}\" RELEASE
             _Qt5$${CMAKE_MODULE_NAME}_STATIC_RELEASE_LIB_DEPENDENCIES
             _Qt5$${CMAKE_MODULE_NAME}_STATIC_RELEASE_LINK_FLAGS
         )
@@ -431,49 +490,60 @@ if (NOT TARGET Qt5::$${CMAKE_MODULE_NAME})
     endif()
 
 !!IF equals(TEMPLATE, aux)
-    add_library(Qt5::$${CMAKE_MODULE_NAME} INTERFACE IMPORTED)
+    add_library(${TARGET_NAME} INTERFACE IMPORTED)
 !!ELSE
-    add_library(Qt5::$${CMAKE_MODULE_NAME} STATIC IMPORTED)
-    set_property(TARGET Qt5::$${CMAKE_MODULE_NAME} PROPERTY IMPORTED_LINK_INTERFACE_LANGUAGES "CXX")
+    add_library(${TARGET_NAME} STATIC IMPORTED)
+    set_property(TARGET ${TARGET_NAME} PROPERTY IMPORTED_LINK_INTERFACE_LANGUAGES "CXX")
 !!ENDIF
 
 !!ELSE // !isEmpty(CMAKE_STATIC_TYPE)
 !!IF equals(TEMPLATE, aux)
-    add_library(Qt5::$${CMAKE_MODULE_NAME} INTERFACE IMPORTED)
+    add_library(${TARGET_NAME} INTERFACE IMPORTED)
 !!ELSE
-    add_library(Qt5::$${CMAKE_MODULE_NAME} SHARED IMPORTED)
+    add_library(${TARGET_NAME} SHARED IMPORTED)
 !!ENDIF
 !!ENDIF // !isEmpty(CMAKE_STATIC_TYPE)
 
 !!IF !equals(TEMPLATE, aux)
 !!IF !isEmpty(CMAKE_BUILD_IS_FRAMEWORK)
-    set_property(TARGET Qt5::$${CMAKE_MODULE_NAME} PROPERTY FRAMEWORK 1)
+    set_property(TARGET ${TARGET_NAME} PROPERTY FRAMEWORK 1)
+!!ENDIF
+!!ENDIF // TEMPLATE != aux
+
+!!IF !equals(TEMPLATE, aux)
+!!IF !isEmpty(CMAKE_BUILD_IS_FRAMEWORK)
+    set_property(TARGET ${TARGET_NAME} PROPERTY FRAMEWORK 1)
 !!ENDIF
 !!ENDIF // TEMPLATE != aux
 
-    set_property(TARGET Qt5::$${CMAKE_MODULE_NAME} PROPERTY
+    set_property(TARGET ${TARGET_NAME} PROPERTY
       INTERFACE_INCLUDE_DIRECTORIES ${_Qt5$${CMAKE_MODULE_NAME}_OWN_INCLUDE_DIRS})
-    set_property(TARGET Qt5::$${CMAKE_MODULE_NAME} PROPERTY
-      INTERFACE_COMPILE_DEFINITIONS $${MODULE_DEFINES})
+!!IF !isEmpty(CMAKE_STATIC_TYPE)
+    set_property(TARGET ${TARGET_NAME} PROPERTY
+        INTERFACE_COMPILE_DEFINITIONS $${CMAKE_INTERFACE_COMPILE_DEFINITIONS_STATIC} $${MODULE_DEFINES})
+!!ELSE
+    set_property(TARGET ${TARGET_NAME} PROPERTY
+        INTERFACE_COMPILE_DEFINITIONS $${MODULE_DEFINES})
+!!ENDIF
 
-    set_property(TARGET Qt5::$${CMAKE_MODULE_NAME} PROPERTY INTERFACE_QT_ENABLED_FEATURES $$join(QT.$${MODULE}.enabled_features, ";"))
-    set_property(TARGET Qt5::$${CMAKE_MODULE_NAME} PROPERTY INTERFACE_QT_DISABLED_FEATURES $$join(QT.$${MODULE}.disabled_features, ";"))
+    set_property(TARGET ${TARGET_NAME} PROPERTY INTERFACE_QT_ENABLED_FEATURES $$join(QT.$${MODULE}.enabled_features, ";"))
+    set_property(TARGET ${TARGET_NAME} PROPERTY INTERFACE_QT_DISABLED_FEATURES $$join(QT.$${MODULE}.disabled_features, ";"))
 
     # Qt 6 forward compatible properties.
-    set_property(TARGET Qt5::$${CMAKE_MODULE_NAME}
+    set_property(TARGET ${TARGET_NAME}
                  PROPERTY $${CMAKE_FEATURE_PROPERTY_PREFIX}QT_ENABLED_PUBLIC_FEATURES
                  $$join(QT.$${MODULE}.enabled_features, ";"))
-    set_property(TARGET Qt5::$${CMAKE_MODULE_NAME}
+    set_property(TARGET ${TARGET_NAME}
                  PROPERTY $${CMAKE_FEATURE_PROPERTY_PREFIX}QT_DISABLED_PUBLIC_FEATURES
                  $$join(QT.$${MODULE}.disabled_features, ";"))
-    set_property(TARGET Qt5::$${CMAKE_MODULE_NAME}
+    set_property(TARGET ${TARGET_NAME}
                  PROPERTY $${CMAKE_FEATURE_PROPERTY_PREFIX}QT_ENABLED_PRIVATE_FEATURES
                  $$join(QT.$${MODULE}_private.enabled_features, ";"))
-    set_property(TARGET Qt5::$${CMAKE_MODULE_NAME}
+    set_property(TARGET ${TARGET_NAME}
                  PROPERTY $${CMAKE_FEATURE_PROPERTY_PREFIX}QT_DISABLED_PRIVATE_FEATURES
                  $$join(QT.$${MODULE}_private.disabled_features, ";"))
 
-    set_property(TARGET Qt5::$${CMAKE_MODULE_NAME} PROPERTY INTERFACE_QT_PLUGIN_TYPES \"$${CMAKE_MODULE_PLUGIN_TYPES}\")
+    set_property(TARGET ${TARGET_NAME} PROPERTY INTERFACE_QT_PLUGIN_TYPES \"$${CMAKE_MODULE_PLUGIN_TYPES}\")
 
     # Find plugin targets
     file(GLOB pluginTargetsMaybe \"${CMAKE_CURRENT_LIST_DIR}/*Qt5$${CMAKE_MODULE_NAME}_*.cmake\")
@@ -487,7 +557,11 @@ if (NOT TARGET Qt5::$${CMAKE_MODULE_NAME})
         endforeach()
     endif()
 
+!!IF !isEmpty(CMAKE_STATIC_TYPE)
+    macro(_populate_$${CMAKE_MODULE_NAME}_plugin_properties_static TARGET_NAME PLUGIN_TARGET_NAME PLUGIN_NAME CONFIG PLUGIN_LOCATION)
+!!ELSE
     macro(_populate_$${CMAKE_MODULE_NAME}_plugin_properties TARGET_NAME PLUGIN_TARGET_NAME PLUGIN_NAME CONFIG PLUGIN_LOCATION)
+!!ENDIF
         set_property(TARGET ${PLUGIN_TARGET_NAME} APPEND PROPERTY IMPORTED_CONFIGURATIONS ${CONFIG})
 
 !!IF isEmpty(CMAKE_PLUGIN_DIR_IS_ABSOLUTE)
@@ -495,7 +569,11 @@ if (NOT TARGET Qt5::$${CMAKE_MODULE_NAME})
 !!ELSE
         set(imported_location \"$${CMAKE_PLUGIN_DIR}${PLUGIN_LOCATION}\")
 !!ENDIF
+!!IF !isEmpty(CMAKE_STATIC_TYPE)
+        _qt5_$${CMAKE_MODULE_NAME}_check_file_exists_static(${imported_location})
+!!ELSE
         _qt5_$${CMAKE_MODULE_NAME}_check_file_exists(${imported_location})
+!!ENDIF
         set_target_properties(${PLUGIN_TARGET_NAME} PROPERTIES
             \"IMPORTED_LOCATION_${CONFIG}\" ${imported_location}
         )
@@ -525,17 +603,20 @@ if (NOT TARGET Qt5::$${CMAKE_MODULE_NAME})
         endforeach()
     endif()
 
+    # set TARGET_NAME back to current module (when loading plugin targets other modules might have been loaded in the meantime)
+    set(TARGET_NAME ${QT_VARIANT_PREFIX}Qt5::$${CMAKE_MODULE_NAME})
+
     set(_Qt5$${CMAKE_MODULE_NAME}_PRIVATE_DIRS_EXIST TRUE)
-    foreach (_Qt5$${CMAKE_MODULE_NAME}_PRIVATE_DIR ${Qt5$${CMAKE_MODULE_NAME}_OWN_PRIVATE_INCLUDE_DIRS})
+    foreach (_Qt5$${CMAKE_MODULE_NAME}_PRIVATE_DIR ${${TARGET_NAME}_OWN_PRIVATE_INCLUDE_DIRS})
         if (NOT EXISTS ${_Qt5$${CMAKE_MODULE_NAME}_PRIVATE_DIR})
             set(_Qt5$${CMAKE_MODULE_NAME}_PRIVATE_DIRS_EXIST FALSE)
         endif()
     endforeach()
 
     if (_Qt5$${CMAKE_MODULE_NAME}_PRIVATE_DIRS_EXIST)
-        add_library(Qt5::$${CMAKE_MODULE_NAME}Private INTERFACE IMPORTED)
-        set_property(TARGET Qt5::$${CMAKE_MODULE_NAME}Private PROPERTY
-            INTERFACE_INCLUDE_DIRECTORIES ${Qt5$${CMAKE_MODULE_NAME}_OWN_PRIVATE_INCLUDE_DIRS}
+        add_library(${TARGET_NAME}Private INTERFACE IMPORTED)
+        set_property(TARGET ${TARGET_NAME}Private PROPERTY
+            INTERFACE_INCLUDE_DIRECTORIES ${${TARGET_NAME}_OWN_PRIVATE_INCLUDE_DIRS}
         )
         set(_Qt5$${CMAKE_MODULE_NAME}_PRIVATEDEPS)
         foreach(dep ${_Qt5$${CMAKE_MODULE_NAME}_LIB_DEPENDENCIES})
@@ -544,17 +625,18 @@ if (NOT TARGET Qt5::$${CMAKE_MODULE_NAME})
             endif()
         endforeach()
 !!IF !isEmpty(CMAKE_STATIC_TYPE)
-        _qt5_add_dependencies(Qt5::$${CMAKE_MODULE_NAME}Private ALL \"Qt5::$${CMAKE_MODULE_NAME};${_Qt5$${CMAKE_MODULE_NAME}_PRIVATEDEPS}\")
+        _qt5_add_dependencies(${TARGET_NAME}Private ALL
+            \"${TARGET_NAME};${_Qt5$${CMAKE_MODULE_NAME}_PRIVATEDEPS}\")
 !!ELSE
-        set_property(TARGET Qt5::$${CMAKE_MODULE_NAME}Private PROPERTY
-            INTERFACE_LINK_LIBRARIES Qt5::$${CMAKE_MODULE_NAME} ${_Qt5$${CMAKE_MODULE_NAME}_PRIVATEDEPS}
+        set_property(TARGET ${TARGET_NAME}Private PROPERTY
+            INTERFACE_LINK_LIBRARIES ${TARGET_NAME} ${_Qt5$${CMAKE_MODULE_NAME}_PRIVATEDEPS}
         )
 
         # Add a versionless target, for compatibility with Qt6.
-        if(NOT \"${QT_NO_CREATE_VERSIONLESS_TARGETS}\" AND NOT TARGET Qt::$${CMAKE_MODULE_NAME}Private)
-            add_library(Qt::$${CMAKE_MODULE_NAME}Private INTERFACE IMPORTED)
-            set_target_properties(Qt::$${CMAKE_MODULE_NAME}Private PROPERTIES
-                INTERFACE_LINK_LIBRARIES \"Qt5::$${CMAKE_MODULE_NAME}Private\"
+        if(NOT \"${QT_NO_CREATE_VERSIONLESS_TARGETS}\" AND NOT TARGET ${QT_VARIANT_PREFIX}Qt::$${CMAKE_MODULE_NAME}Private)
+            add_library(${QT_VARIANT_PREFIX}Qt::$${CMAKE_MODULE_NAME}Private INTERFACE IMPORTED)
+            set_target_properties(${QT_VARIANT_PREFIX}Qt::$${CMAKE_MODULE_NAME}Private PROPERTIES
+                INTERFACE_LINK_LIBRARIES \"${TARGET_NAME}Private\"
             )
         endif()
 !!ENDIF // CMAKE_STATIC_TYPE
@@ -562,59 +644,61 @@ if (NOT TARGET Qt5::$${CMAKE_MODULE_NAME})
 
 !!IF !equals(TEMPLATE, aux)
 !!IF !isEmpty(CMAKE_RELEASE_TYPE)
-!!IF !isEmpty(CMAKE_STATIC_WINDOWS_BUILD)
-    _populate_$${CMAKE_MODULE_NAME}_target_properties(RELEASE \"$${CMAKE_IMPLIB_FILE_LOCATION_RELEASE}\" \"\" $${CMAKE_DEBUG_AND_RELEASE})
+!!IF !isEmpty(CMAKE_STATIC_TYPE)
+    _populate_$${CMAKE_MODULE_NAME}_target_properties_static(${TARGET_NAME} RELEASE \"$${CMAKE_IMPLIB_FILE_LOCATION_RELEASE_STATIC}\" \"\" $${CMAKE_DEBUG_AND_RELEASE})
 !!ELSE
-    _populate_$${CMAKE_MODULE_NAME}_target_properties(RELEASE \"$${CMAKE_LIB_FILE_LOCATION_RELEASE}\" \"$${CMAKE_IMPLIB_FILE_LOCATION_RELEASE}\" $${CMAKE_DEBUG_AND_RELEASE})
-!!ENDIF // CMAKE_STATIC_WINDOWS_BUILD
+    _populate_$${CMAKE_MODULE_NAME}_target_properties(${TARGET_NAME} RELEASE \"$${CMAKE_LIB_FILE_LOCATION_RELEASE}\" \"$${CMAKE_IMPLIB_FILE_LOCATION_RELEASE}\" $${CMAKE_DEBUG_AND_RELEASE})
+!!ENDIF // CMAKE_STATIC_TYPE
+
 
 !!IF !isEmpty(CMAKE_FIND_OTHER_LIBRARY_BUILD)
 !!IF isEmpty(CMAKE_DEBUG_TYPE)
-!!IF !isEmpty(CMAKE_STATIC_WINDOWS_BUILD)
+!!IF !isEmpty(CMAKE_STATIC_TYPE)
 !!IF isEmpty(CMAKE_LIB_DIR_IS_ABSOLUTE)
-    if (EXISTS \"${_qt5$${CMAKE_MODULE_NAME}_install_prefix}/$${CMAKE_LIB_DIR}$${CMAKE_IMPLIB_FILE_LOCATION_DEBUG}\" )
+    if (EXISTS \"${_qt5$${CMAKE_MODULE_NAME}_install_prefix}/$${CMAKE_LIB_DIR}$${CMAKE_IMPLIB_FILE_LOCATION_DEBUG_STATIC}\" )
 !!ELSE // CMAKE_LIB_DIR_IS_ABSOLUTE
     if (EXISTS \"$${CMAKE_IMPLIB_FILE_LOCATION_DEBUG}\" )
 !!ENDIF // CMAKE_LIB_DIR_IS_ABSOLUTE
-        _populate_$${CMAKE_MODULE_NAME}_target_properties(DEBUG \"$${CMAKE_IMPLIB_FILE_LOCATION_DEBUG}\" \"\" $${CMAKE_DEBUG_AND_RELEASE})
-!!ELSE // CMAKE_STATIC_WINDOWS_BUILD
+        _populate_$${CMAKE_MODULE_NAME}_target_properties_static(${TARGET_NAME} DEBUG \"$${CMAKE_IMPLIB_FILE_LOCATION_DEBUG_STATIC}\" \"\" $${CMAKE_DEBUG_AND_RELEASE})
+    endif()
+!!ELSE // CMAKE_STATIC_TYPE
     if (EXISTS
 !!IF isEmpty(CMAKE_DLL_DIR_IS_ABSOLUTE)
         \"${_qt5$${CMAKE_MODULE_NAME}_install_prefix}/$${CMAKE_DLL_DIR}$${CMAKE_LIB_FILE_LOCATION_DEBUG}\"
 !!ELSE
         \"$${CMAKE_LIB_FILE_LOCATION_DEBUG}\"
 !!ENDIF
-      AND EXISTS
+    AND EXISTS
 !!IF isEmpty(CMAKE_LIB_DIR_IS_ABSOLUTE)
         \"${_qt5$${CMAKE_MODULE_NAME}_install_prefix}/$${CMAKE_LIB_DIR}$${CMAKE_IMPLIB_FILE_LOCATION_DEBUG}\" )
 !!ELSE
         \"$${CMAKE_IMPLIB_FILE_LOCATION_DEBUG}\" )
 !!ENDIF
-        _populate_$${CMAKE_MODULE_NAME}_target_properties(DEBUG \"$${CMAKE_LIB_FILE_LOCATION_DEBUG}\" \"$${CMAKE_IMPLIB_FILE_LOCATION_DEBUG}\" $${CMAKE_DEBUG_AND_RELEASE})
-!!ENDIF // CMAKE_STATIC_WINDOWS_BUILD
+        _populate_$${CMAKE_MODULE_NAME}_target_properties(${TARGET_NAME} DEBUG \"$${CMAKE_LIB_FILE_LOCATION_DEBUG}\" \"$${CMAKE_IMPLIB_FILE_LOCATION_DEBUG}\" $${CMAKE_DEBUG_AND_RELEASE})
     endif()
+!!ENDIF // CMAKE_STATIC_TYPE
 !!ENDIF // CMAKE_DEBUG_TYPE
 !!ENDIF // CMAKE_FIND_OTHER_LIBRARY_BUILD
-
 !!ENDIF // CMAKE_RELEASE_TYPE
 
 !!IF !isEmpty(CMAKE_DEBUG_TYPE)
-!!IF !isEmpty(CMAKE_STATIC_WINDOWS_BUILD)
-    _populate_$${CMAKE_MODULE_NAME}_target_properties(DEBUG \"$${CMAKE_IMPLIB_FILE_LOCATION_DEBUG}\" \"\" $${CMAKE_DEBUG_AND_RELEASE})
+!!IF !isEmpty(CMAKE_STATIC_TYPE)
+    _populate_$${CMAKE_MODULE_NAME}_target_properties_static(DEBUG \"$${CMAKE_IMPLIB_FILE_LOCATION_DEBUG}\" \"\" $${CMAKE_DEBUG_AND_RELEASE})
 !!ELSE
     _populate_$${CMAKE_MODULE_NAME}_target_properties(DEBUG \"$${CMAKE_LIB_FILE_LOCATION_DEBUG}\" \"$${CMAKE_IMPLIB_FILE_LOCATION_DEBUG}\" $${CMAKE_DEBUG_AND_RELEASE})
-!!ENDIF // CMAKE_STATIC_WINDOWS_BUILD
+!!ENDIF // CMAKE_STATIC_TYPE
 
 !!IF !isEmpty(CMAKE_FIND_OTHER_LIBRARY_BUILD)
 !!IF isEmpty(CMAKE_RELEASE_TYPE)
-!!IF !isEmpty(CMAKE_STATIC_WINDOWS_BUILD)
+
+!!IF !isEmpty(CMAKE_STATIC_TYPE)
 !!IF isEmpty(CMAKE_LIB_DIR_IS_ABSOLUTE)
-    if (EXISTS \"${_qt5$${CMAKE_MODULE_NAME}_install_prefix}/$${CMAKE_LIB_DIR}$${CMAKE_IMPLIB_FILE_LOCATION_RELEASE}\" )
+    if (EXISTS \"${_qt5$${CMAKE_MODULE_NAME}_install_prefix}/$${CMAKE_LIB_DIR}$${CMAKE_IMPLIB_FILE_LOCATION_RELEASE_STATIC}\" )
 !!ELSE // CMAKE_LIB_DIR_IS_ABSOLUTE
-    if (EXISTS \"$${CMAKE_IMPLIB_FILE_LOCATION_RELEASE}\" )
+    if (EXISTS \"$${CMAKE_IMPLIB_FILE_LOCATION_RELEASE_STATIC}\" )
 !!ENDIF // CMAKE_LIB_DIR_IS_ABSOLUTE
-        _populate_$${CMAKE_MODULE_NAME}_target_properties(RELEASE \"$${CMAKE_IMPLIB_FILE_LOCATION_RELEASE}\" \"\" $${CMAKE_DEBUG_AND_RELEASE})
-!!ELSE // CMAKE_STATIC_WINDOWS_BUILD
+        _populate_$${CMAKE_MODULE_NAME}_target_properties_static(${TARGET_NAME} RELEASE \"$${CMAKE_IMPLIB_FILE_LOCATION_RELEASE_STATIC}\" \"\" $${CMAKE_DEBUG_AND_RELEASE})
+!!ELSE // CMAKE_STATIC_TYPE
     if (EXISTS
 !!IF isEmpty(CMAKE_DLL_DIR_IS_ABSOLUTE)
         \"${_qt5$${CMAKE_MODULE_NAME}_install_prefix}/$${CMAKE_DLL_DIR}$${CMAKE_LIB_FILE_LOCATION_RELEASE}\"
@@ -627,7 +711,7 @@ if (NOT TARGET Qt5::$${CMAKE_MODULE_NAME})
 !!ELSE
         \"$${CMAKE_IMPLIB_FILE_LOCATION_RELEASE}\" )
 !!ENDIF
-        _populate_$${CMAKE_MODULE_NAME}_target_properties(Qt5::$${CMAKE_MODULE_NAME} RELEASE \"$${CMAKE_LIB_FILE_LOCATION_RELEASE}\" \"$${CMAKE_IMPLIB_FILE_LOCATION_RELEASE}\" $${CMAKE_DEBUG_AND_RELEASE})
+        _populate_$${CMAKE_MODULE_NAME}_target_properties(${TARGET_NAME} RELEASE \"$${CMAKE_LIB_FILE_LOCATION_RELEASE}\" \"$${CMAKE_IMPLIB_FILE_LOCATION_RELEASE}\" $${CMAKE_DEBUG_AND_RELEASE})
     endif()
 !!ENDIF // CMAKE_STATIC_TYPE
 
@@ -637,26 +721,29 @@ if (NOT TARGET Qt5::$${CMAKE_MODULE_NAME})
 
 !!ENDIF // CMAKE_DEBUG_TYPE
 !!ELSE // TEMPLATE != aux
-    set_target_properties(Qt5::$${CMAKE_MODULE_NAME} PROPERTIES
+    set_target_properties(${TARGET_NAME} PROPERTIES
         INTERFACE_LINK_LIBRARIES \"${_Qt5$${CMAKE_MODULE_NAME}_LIB_DEPENDENCIES}\"
     )
 !!ENDIF // TEMPLATE != aux
 
 !!IF !isEmpty(CMAKE_MODULE_EXTRAS)
-    include(\"${CMAKE_CURRENT_LIST_DIR}/Qt5$${CMAKE_MODULE_NAME}ConfigExtras.cmake\")
+    include(\"${CMAKE_CURRENT_LIST_DIR}/../${QT_VARIANT_PREFIX}Qt5$${CMAKE_MODULE_NAME}/${QT_VARIANT_PREFIX}Qt5$${CMAKE_MODULE_NAME}ConfigExtras.cmake\")
 !!ENDIF
-
 !!IF !isEmpty(CMAKE_MODULE_MACROS)
-    include(\"${CMAKE_CURRENT_LIST_DIR}/Qt5$${CMAKE_MODULE_NAME}Macros.cmake\")
+    include(\"${CMAKE_CURRENT_LIST_DIR}/../${QT_VARIANT_PREFIX}Qt5$${CMAKE_MODULE_NAME}/${QT_VARIANT_PREFIX}Qt5$${CMAKE_MODULE_NAME}Macros.cmake\")
 !!ENDIF
 
-    _qt5_$${CMAKE_MODULE_NAME}_check_file_exists(\"${CMAKE_CURRENT_LIST_DIR}/Qt5$${CMAKE_MODULE_NAME}ConfigVersion.cmake\")
+!!IF !isEmpty(CMAKE_STATIC_TYPE)
+    _qt5_$${CMAKE_MODULE_NAME}_check_file_exists_static(\"${CMAKE_CURRENT_LIST_DIR}/../${QT_VARIANT_PREFIX}Qt5$${CMAKE_MODULE_NAME}/${QT_VARIANT_PREFIX}Qt5$${CMAKE_MODULE_NAME}ConfigVersion.cmake\")
+!!ELSE
+    _qt5_$${CMAKE_MODULE_NAME}_check_file_exists(\"${CMAKE_CURRENT_LIST_DIR}/../${QT_VARIANT_PREFIX}Qt5$${CMAKE_MODULE_NAME}/${QT_VARIANT_PREFIX}Qt5$${CMAKE_MODULE_NAME}ConfigVersion.cmake\")
+!!ENDIF
 endif()
 
 # Add a versionless target, for compatibility with Qt6.
-if(NOT \"${QT_NO_CREATE_VERSIONLESS_TARGETS}\" AND TARGET Qt5::$${CMAKE_MODULE_NAME} AND NOT TARGET Qt::$${CMAKE_MODULE_NAME})
-    add_library(Qt::$${CMAKE_MODULE_NAME} INTERFACE IMPORTED)
-    set_target_properties(Qt::$${CMAKE_MODULE_NAME} PROPERTIES
-        INTERFACE_LINK_LIBRARIES \"Qt5::$${CMAKE_MODULE_NAME}\"
+if(NOT \"${QT_NO_CREATE_VERSIONLESS_TARGETS}\" AND TARGET ${QT_VARIANT_PREFIX}Qt5::$${CMAKE_MODULE_NAME} AND NOT TARGET ${QT_VARIANT_PREFIX}Qt::$${CMAKE_MODULE_NAME})
+    add_library(${QT_VARIANT_PREFIX}Qt::$${CMAKE_MODULE_NAME} INTERFACE IMPORTED)
+    set_target_properties(${QT_VARIANT_PREFIX}Qt::$${CMAKE_MODULE_NAME} PROPERTIES
+        INTERFACE_LINK_LIBRARIES \"${QT_VARIANT_PREFIX}Qt5::$${CMAKE_MODULE_NAME}\"
     )
 endif()
diff --git a/mkspecs/features/data/cmake/Qt5PluginTarget.cmake.in b/mkspecs/features/data/cmake/Qt5PluginTarget.cmake.in
index acbe1cc33b..65869c5122 100644
--- a/mkspecs/features/data/cmake/Qt5PluginTarget.cmake.in
+++ b/mkspecs/features/data/cmake/Qt5PluginTarget.cmake.in
@@ -1,13 +1,13 @@
 # Some Qt modules also load plugin target in extra config, so check whether the target already exists
-if(NOT TARGET Qt5::$$CMAKE_PLUGIN_NAME)
-    add_library(Qt5::$$CMAKE_PLUGIN_NAME MODULE IMPORTED)
+if(NOT TARGET ${QT_VARIANT_PREFIX}Qt5::$$CMAKE_PLUGIN_NAME)
+    add_library(${QT_VARIANT_PREFIX}Qt5::$$CMAKE_PLUGIN_NAME MODULE IMPORTED)
 
 !!IF !isEmpty(CMAKE_STATIC_TYPE)
 set(_Qt5$${CMAKE_PLUGIN_NAME}_MODULE_DEPENDENCIES \"$${CMAKE_PLUGIN_MODULE_DEPS}\")
 
 foreach(_module_dep ${_Qt5$${CMAKE_PLUGIN_NAME}_MODULE_DEPENDENCIES})
-    if(NOT Qt5${_module_dep}_FOUND)
-        find_package(Qt5${_module_dep}
+    if(NOT ${QT_VARIANT_PREFIX}Qt5${_module_dep}_FOUND)
+        find_package(${QT_VARIANT_PREFIX}Qt5${_module_dep}
             $$VERSION ${_Qt5$${CMAKE_MODULE_NAME}_FIND_VERSION_EXACT}
             ${_Qt5$${CMAKE_MODULE_NAME}_DEPENDENCIES_FIND_QUIET}
             ${_Qt5$${CMAKE_MODULE_NAME}_FIND_DEPENDENCIES_REQUIRED}
@@ -17,17 +17,25 @@ foreach(_module_dep ${_Qt5$${CMAKE_PLUGIN_NAME}_MODULE_DEPENDENCIES})
 endforeach()
 
 !!IF !isEmpty(CMAKE_RELEASE_TYPE)
-    _populate_$${CMAKE_MODULE_NAME}_plugin_properties(Qt5::$$CMAKE_MODULE_NAME Qt5::$$CMAKE_PLUGIN_NAME $$CMAKE_PLUGIN_NAME RELEASE \"$${CMAKE_PLUGIN_LOCATION_RELEASE}\")
+!!IF !isEmpty(CMAKE_STATIC_TYPE)
+    _populate_$${CMAKE_MODULE_NAME}_plugin_properties_static(${QT_VARIANT_PREFIX}Qt5::$$CMAKE_MODULE_NAME ${QT_VARIANT_PREFIX}Qt5::$$CMAKE_PLUGIN_NAME $$CMAKE_PLUGIN_NAME RELEASE \"$${CMAKE_PLUGIN_LOCATION_RELEASE_STATIC}\")
+!!ELSE
+    _populate_$${CMAKE_MODULE_NAME}_plugin_properties(${QT_VARIANT_PREFIX}Qt5::$$CMAKE_MODULE_NAME ${QT_VARIANT_PREFIX}Qt5::$$CMAKE_PLUGIN_NAME $$CMAKE_PLUGIN_NAME RELEASE \"$${CMAKE_PLUGIN_LOCATION_RELEASE}\")
+!!ENDIF
 !!ENDIF
 !!ENDIF
 
 !!IF !isEmpty(CMAKE_DEBUG_TYPE)
-    _populate_$${CMAKE_MODULE_NAME}_plugin_properties(Qt5::$$CMAKE_MODULE_NAME Qt5::$$CMAKE_PLUGIN_NAME $$CMAKE_PLUGIN_NAME DEBUG \"$${CMAKE_PLUGIN_LOCATION_DEBUG}\")
+!!IF !isEmpty(CMAKE_STATIC_TYPE)
+    _populate_$${CMAKE_MODULE_NAME}_plugin_properties_static(${QT_VARIANT_PREFIX}Qt5::$$CMAKE_MODULE_NAME ${QT_VARIANT_PREFIX}Qt5::$$CMAKE_PLUGIN_NAME $$CMAKE_PLUGIN_NAME DEBUG \"$${CMAKE_PLUGIN_LOCATION_DEBUG_STATIC}\")
+!!ELSE
+    _populate_$${CMAKE_MODULE_NAME}_plugin_properties(${QT_VARIANT_PREFIX}Qt5::$$CMAKE_MODULE_NAME ${QT_VARIANT_PREFIX}Qt5::$$CMAKE_PLUGIN_NAME $$CMAKE_PLUGIN_NAME DEBUG \"$${CMAKE_PLUGIN_LOCATION_DEBUG}\")
+!!ENDIF
 !!ENDIF
 
-list(APPEND Qt5$${CMAKE_MODULE_NAME}_PLUGINS Qt5::$$CMAKE_PLUGIN_NAME)
-set_property(TARGET Qt5::$${CMAKE_MODULE_NAME} APPEND PROPERTY QT_ALL_PLUGINS_$${CMAKE_PLUGIN_TYPE_ESCAPED} Qt5::$${CMAKE_PLUGIN_NAME})
-set_property(TARGET Qt5::$${CMAKE_PLUGIN_NAME} PROPERTY QT_PLUGIN_TYPE \"$$CMAKE_PLUGIN_TYPE\")
-set_property(TARGET Qt5::$${CMAKE_PLUGIN_NAME} PROPERTY QT_PLUGIN_EXTENDS \"$$CMAKE_PLUGIN_EXTENDS\")
-set_property(TARGET Qt5::$${CMAKE_PLUGIN_NAME} PROPERTY QT_PLUGIN_CLASS_NAME \"$$CMAKE_PLUGIN_NAME\")
-endif()
\ No newline at end of file
+list(APPEND ${QT_VARIANT_PREFIX}Qt5$${CMAKE_MODULE_NAME}_PLUGINS ${QT_VARIANT_PREFIX}Qt5::$$CMAKE_PLUGIN_NAME)
+set_property(TARGET ${QT_VARIANT_PREFIX}Qt5::$${CMAKE_MODULE_NAME} APPEND PROPERTY QT_ALL_PLUGINS_$${CMAKE_PLUGIN_TYPE_ESCAPED} ${QT_VARIANT_PREFIX}Qt5::$${CMAKE_PLUGIN_NAME})
+set_property(TARGET ${QT_VARIANT_PREFIX}Qt5::$${CMAKE_PLUGIN_NAME} PROPERTY QT_PLUGIN_TYPE \"$$CMAKE_PLUGIN_TYPE\")
+set_property(TARGET ${QT_VARIANT_PREFIX}Qt5::$${CMAKE_PLUGIN_NAME} PROPERTY QT_PLUGIN_EXTENDS \"$$CMAKE_PLUGIN_EXTENDS\")
+set_property(TARGET ${QT_VARIANT_PREFIX}Qt5::$${CMAKE_PLUGIN_NAME} PROPERTY QT_PLUGIN_CLASS_NAME \"$$CMAKE_PLUGIN_NAME\")
+endif()
diff --git a/mkspecs/features/data/cmake/Qt5StaticOnlyRedirection.cmake.in b/mkspecs/features/data/cmake/Qt5StaticOnlyRedirection.cmake.in
new file mode 100644
index 0000000000..0091940fd2
--- /dev/null
+++ b/mkspecs/features/data/cmake/Qt5StaticOnlyRedirection.cmake.in
@@ -0,0 +1,11 @@
+# "redirect" to static package overriding variant prefix so it does not contain "Static" anymore
+set(ORIGINAL_OVERRIDE_QT_VARIANT_PREFIX "${OVERRIDE_QT_VARIANT_PREFIX}")
+if(OVERRIDE_QT_VARIANT_PREFIX)
+    string(REPLACE \"Static\" \"\" OVERRIDE_QT_VARIANT_PREFIX "${OVERRIDE_QT_VARIANT_PREFIX}")
+endif()
+if(NOT OVERRIDE_QT_VARIANT_PREFIX)
+    set(OVERRIDE_QT_VARIANT_PREFIX "none")
+endif()
+find_package(StaticQt5$${CMAKE_MODULE_NAME})
+set(OVERRIDE_QT_VARIANT_PREFIX "${ORIGINAL_OVERRIDE_QT_VARIANT_PREFIX}")
+
diff --git a/src/corelib/Qt5CoreConfigExtras.cmake.in b/src/corelib/Qt5CoreConfigExtras.cmake.in
index 0d02edb41c..9da1361c95 100644
--- a/src/corelib/Qt5CoreConfigExtras.cmake.in
+++ b/src/corelib/Qt5CoreConfigExtras.cmake.in
@@ -2,6 +2,8 @@ if(NOT DEFINED QT_DEFAULT_MAJOR_VERSION)
     set(QT_DEFAULT_MAJOR_VERSION 5)
 endif()
 
+set(IMPORTED_TARGET_NAME ${QT_VARIANT_PREFIX}Qt5::$${CMAKE_MODULE_NAME})
+
 if (NOT TARGET Qt5::qmake)
     add_executable(Qt5::qmake IMPORTED)
 
@@ -55,12 +57,12 @@ set(Qt5Core_QMAKE_EXECUTABLE Qt5::qmake)
 set(Qt5Core_MOC_EXECUTABLE Qt5::moc)
 set(Qt5Core_RCC_EXECUTABLE Qt5::rcc)
 
-set_property(TARGET Qt5::Core PROPERTY INTERFACE_QT_MAJOR_VERSION 5)
-set_property(TARGET Qt5::Core PROPERTY INTERFACE_QT_COORD_TYPE $$QT_COORD_TYPE)
+set_property(TARGET ${IMPORTED_TARGET_NAME} PROPERTY INTERFACE_QT_MAJOR_VERSION 5)
+set_property(TARGET ${IMPORTED_TARGET_NAME} PROPERTY INTERFACE_QT_COORD_TYPE $$QT_COORD_TYPE)
 !!IF !isEmpty(CMAKE_MIN_DARWIN_DEPLOYMENT_TARGET)
-set_property(TARGET Qt5::Core PROPERTY QT_DARWIN_MIN_DEPLOYMENT_TARGET \"$$CMAKE_MIN_DARWIN_DEPLOYMENT_TARGET\")
+set_property(TARGET ${IMPORTED_TARGET_NAME} PROPERTY QT_DARWIN_MIN_DEPLOYMENT_TARGET \"$$CMAKE_MIN_DARWIN_DEPLOYMENT_TARGET\")
 !!ENDIF
-set_property(TARGET Qt5::Core APPEND PROPERTY
+set_property(TARGET ${IMPORTED_TARGET_NAME} APPEND PROPERTY
   COMPATIBLE_INTERFACE_STRING QT_MAJOR_VERSION QT_COORD_TYPE
 )
 
@@ -71,7 +73,7 @@ foreach(_dir ${_qt5_corelib_extra_includes})
 endforeach()
 
 list(APPEND Qt5Core_INCLUDE_DIRS ${_qt5_corelib_extra_includes})
-set_property(TARGET Qt5::Core APPEND PROPERTY INTERFACE_INCLUDE_DIRECTORIES ${_qt5_corelib_extra_includes})
+set_property(TARGET ${IMPORTED_TARGET_NAME} APPEND PROPERTY INTERFACE_INCLUDE_DIRECTORIES ${_qt5_corelib_extra_includes})
 set(_qt5_corelib_extra_includes)
 
 # Targets using Qt need to use the POSITION_INDEPENDENT_CODE property. The
@@ -86,7 +88,7 @@ set(Qt5_POSITION_INDEPENDENT_CODE True)
 # Applications now need to be compiled with the -fPIC option if the Qt option
 # \"reduce relocations\" is active. For backward compatibility only, Qt accepts
 # the use of -fPIE for GCC 4.x versions.
-set_property(TARGET Qt5::Core APPEND PROPERTY INTERFACE_COMPILE_OPTIONS $$QMAKE_CXXFLAGS_APP)
+set_property(TARGET ${IMPORTED_TARGET_NAME} APPEND PROPERTY INTERFACE_COMPILE_OPTIONS $$QMAKE_CXXFLAGS_APP)
 
 # TODO Qt6: Remove
 set(Qt5Core_EXECUTABLE_COMPILE_FLAGS \"\")
@@ -94,7 +96,7 @@ set(Qt5Core_EXECUTABLE_COMPILE_FLAGS \"\")
 !!IF !isEmpty(QT_NAMESPACE)
 list(APPEND Qt5Core_DEFINITIONS -DQT_NAMESPACE=$$QT_NAMESPACE)
 list(APPEND Qt5Core_COMPILE_DEFINITIONS QT_NAMESPACE=$$QT_NAMESPACE)
-set_property(TARGET Qt5::Core APPEND PROPERTY INTERFACE_COMPILE_DEFINITIONS QT_NAMESPACE=$$QT_NAMESPACE)
+set_property(TARGET ${IMPORTED_TARGET_NAME} APPEND PROPERTY INTERFACE_COMPILE_DEFINITIONS QT_NAMESPACE=$$QT_NAMESPACE)
 !!ENDIF
 
 !!IF !isEmpty(CMAKE_DISABLED_FEATURES)
@@ -103,9 +105,9 @@ set(Qt5_DISABLED_FEATURES
 )
 !!ENDIF
 
-set_property(TARGET Qt5::Core APPEND PROPERTY INTERFACE_COMPILE_DEFINITIONS $<$<NOT:$<CONFIG:Debug>>:QT_NO_DEBUG>)
+set_property(TARGET ${IMPORTED_TARGET_NAME} APPEND PROPERTY INTERFACE_COMPILE_DEFINITIONS $<$<NOT:$<CONFIG:Debug>>:QT_NO_DEBUG>)
 
-set_property(TARGET Qt5::Core PROPERTY INTERFACE_COMPILE_FEATURES cxx_decltype)
+set_property(TARGET ${IMPORTED_TARGET_NAME} PROPERTY INTERFACE_COMPILE_FEATURES cxx_decltype)
 
 !!IF qtConfig(reduce_exports)
 set(QT_VISIBILITY_AVAILABLE \"True\")
@@ -153,14 +155,14 @@ if (NOT TARGET Qt5::WinMain)
         set(_isWin32 $<BOOL:$<TARGET_PROPERTY:WIN32_EXECUTABLE>>)
         set(_isNotExcluded $<NOT:$<BOOL:$<TARGET_PROPERTY:Qt5_NO_LINK_QTMAIN>>>)
         set(_isPolicyNEW $<TARGET_POLICY:CMP0020>)
-        get_target_property(_configs Qt5::Core IMPORTED_CONFIGURATIONS)
-        set_property(TARGET Qt5::Core APPEND PROPERTY
+        get_target_property(_configs ${IMPORTED_TARGET_NAME} IMPORTED_CONFIGURATIONS)
+        set_property(TARGET ${IMPORTED_TARGET_NAME} APPEND PROPERTY
             INTERFACE_LINK_LIBRARIES
                 $<$<AND:${_isExe},${_isWin32},${_isNotExcluded},${_isPolicyNEW}>:Qt5::WinMain>
         )
         # For backward compatibility with CMake < 2.8.12
         foreach(_config ${_configs})
-            set_property(TARGET Qt5::Core APPEND PROPERTY
+            set_property(TARGET ${IMPORTED_TARGET_NAME} APPEND PROPERTY
                 IMPORTED_LINK_INTERFACE_LIBRARIES_${_config}
                     $<$<AND:${_isExe},${_isWin32},${_isNotExcluded},${_isPolicyNEW}>:Qt5::WinMain>
             )
diff --git a/src/gui/Qt5GuiConfigExtras.cmake.in b/src/gui/Qt5GuiConfigExtras.cmake.in
index 84dbbfebd4..31fa875b6c 100644
--- a/src/gui/Qt5GuiConfigExtras.cmake.in
+++ b/src/gui/Qt5GuiConfigExtras.cmake.in
@@ -1,4 +1,6 @@
 
+set(IMPORTED_TARGET_NAME ${QT_VARIANT_PREFIX}Qt5::$${CMAKE_MODULE_NAME})
+
 !!IF !isEmpty(CMAKE_ANGLE_EGL_DLL_RELEASE)
 
 !!IF isEmpty(CMAKE_INCLUDE_DIR_IS_ABSOLUTE)
@@ -67,7 +69,7 @@ unset(_GL_INCDIRS)
 # optional.
 
 list(APPEND Qt5Gui_INCLUDE_DIRS ${_qt5gui_OPENGL_INCLUDE_DIR})
-set_property(TARGET Qt5::Gui APPEND PROPERTY INTERFACE_INCLUDE_DIRECTORIES ${_qt5gui_OPENGL_INCLUDE_DIR})
+set_property(TARGET ${IMPORTED_TARGET_NAME} APPEND PROPERTY INTERFACE_INCLUDE_DIRECTORIES ${_qt5gui_OPENGL_INCLUDE_DIR})
 
 unset(_qt5gui_OPENGL_INCLUDE_DIR CACHE)
 
@@ -183,9 +185,9 @@ _qt5gui_find_extra_libs(OPENGL \"$$CMAKE_OPENGL_LIBS\" \"$$CMAKE_OPENGL_LIBDIR\"
 
 set(Qt5Gui_OPENGL_IMPLEMENTATION $$CMAKE_QT_OPENGL_IMPLEMENTATION)
 
-get_target_property(_configs Qt5::Gui IMPORTED_CONFIGURATIONS)
+get_target_property(_configs ${IMPORTED_TARGET_NAME} IMPORTED_CONFIGURATIONS)
 foreach(_config ${_configs})
-    set_property(TARGET Qt5::Gui APPEND PROPERTY
+    set_property(TARGET ${IMPORTED_TARGET_NAME} APPEND PROPERTY
         IMPORTED_LINK_DEPENDENT_LIBRARIES_${_config}
         ${Qt5Gui_EGL_LIBRARIES} ${Qt5Gui_OPENGL_LIBRARIES}
     )
diff --git a/src/testlib/Qt5TestConfigExtras.cmake.in b/src/testlib/Qt5TestConfigExtras.cmake.in
index 2a575958ae..ca0e3be3b5 100644
--- a/src/testlib/Qt5TestConfigExtras.cmake.in
+++ b/src/testlib/Qt5TestConfigExtras.cmake.in
@@ -1,5 +1,5 @@
 
-set_property(TARGET Qt5::Test
+set_property(TARGET ${QT_VARIANT_PREFIX}Qt5::Test
   APPEND PROPERTY
     INTERFACE_COMPILE_DEFINITIONS QT_TESTCASE_BUILDDIR=\\\"\${CMAKE_BINARY_DIR}\\\"
 )
-- 
2.36.1

