aboutsummarylogtreecommitdiffstats
path: root/0023-Allow-usage-of-static-version-with-CMake.patch
blob: a530bbb69148c8a748fb7e0fa9817a6afc565e80 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
From c49f1674465685e03c0d95b869d6cea45dcf5447 Mon Sep 17 00:00:00 2001
From: Martchus <martchus@gmx.net>
Date: Sat, 5 Aug 2017 21:14:26 +0200
Subject: [PATCH 23/34] 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)
---
 mkspecs/features/create_cmake.prf             | 103 +++---
 .../data/cmake/Qt5BasicConfig.cmake.in        | 302 ++++++++++++------
 .../data/cmake/Qt5PluginTarget.cmake.in       |  18 +-
 .../cmake/Qt5StaticOnlyRedirection.cmake.in   |  11 +
 src/corelib/Qt5CoreConfigExtras.cmake.in      |  24 +-
 src/gui/Qt5GuiConfigExtras.cmake.in           |   8 +-
 src/testlib/Qt5TestConfigExtras.cmake.in      |   2 +-
 7 files changed, 315 insertions(+), 153 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 2a94964b49..839a51f377 100644
--- a/mkspecs/features/create_cmake.prf
+++ b/mkspecs/features/create_cmake.prf
@@ -42,7 +42,7 @@ split_incpath {
             $$QT_MODULE_INCLUDE_BASE/Qt$${CMAKE_MODULE_NAME}/$$eval(QT.$${MODULE}.VERSION)/Qt$${CMAKE_MODULE_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
@@ -92,6 +92,8 @@ win32:!static:!staticlib {
 }
 
 static|staticlib:CMAKE_STATIC_TYPE = true
+static|staticlib:DEFAULT_QT_VARIANT_PREFIX = "Static"
+else:DEFAULT_QT_VARIANT_PREFIX = ""
 
 CMAKE_DEBUG_TYPE =
 CMAKE_RELEASE_TYPE =
@@ -137,17 +139,19 @@ contains(CONFIG, plugin) {
     CMAKE_PLUGIN_NAME = $$PLUGIN_CLASS_NAME
 
     win32 {
-        isEmpty(CMAKE_STATIC_TYPE) {
+        mingw {
             CMAKE_PLUGIN_LOCATION_RELEASE = $$PLUGIN_TYPE/$${TARGET}.dll
             CMAKE_PLUGIN_LOCATION_DEBUG = $$PLUGIN_TYPE/$${TARGET}d.dll
-        } else:mingw {
-            CMAKE_PLUGIN_LOCATION_RELEASE = $$PLUGIN_TYPE/lib$${TARGET}.a
-            CMAKE_PLUGIN_LOCATION_DEBUG = $$PLUGIN_TYPE/lib$${TARGET}d.a
+            CMAKE_PLUGIN_LOCATION_RELEASE_STATIC = $$PLUGIN_TYPE/lib$${TARGET}.a
+            CMAKE_PLUGIN_LOCATION_DEBUG_STATIC = $$PLUGIN_TYPE/lib$${TARGET}d.a
         } else {                         # MSVC static
             CMAKE_PLUGIN_LOCATION_RELEASE = $$PLUGIN_TYPE/$${TARGET}.lib
             CMAKE_PLUGIN_LOCATION_DEBUG = $$PLUGIN_TYPE/$${TARGET}d.lib
+            CMAKE_PLUGIN_LOCATION_RELEASE_STATIC = $$PLUGIN_TYPE/$${TARGET}.lib
+            CMAKE_PLUGIN_LOCATION_DEBUG_STATIC = $$PLUGIN_TYPE/$${TARGET}d.lib
         }
     } 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
@@ -163,13 +167,13 @@ 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
 
     !build_pass:QMAKE_SUBSTITUTES += \
       cmake_target_file
 
     cmake_qt5_plugin_file.files = $$cmake_target_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()
@@ -182,27 +186,36 @@ 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_INTERFACE_QT5_MODULE_DEPS_STATIC = $$join(aux_lib_deps_static, ";")
+CMAKE_INTERFACE_COMPILE_DEFINITIONS_STATIC = $$join(aux_compile_defs_static, ";")
+
 
 CMAKE_QT_STEM = Qt$$QT_MAJOR_VERSION$${CMAKE_MODULE_NAME}$${QT_LIBINFIX}
 
 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
@@ -230,35 +243,33 @@ mac {
         CMAKE_WINMAIN_FILE_LOCATION_DEBUG = libqt5main$${QT_LIBINFIX}.a
         CMAKE_WINMAIN_FILE_LOCATION_RELEASE = libqt5main$${QT_LIBINFIX}.a
 
-        !isEmpty(CMAKE_STATIC_TYPE) {
-            CMAKE_STATIC_WINDOWS_BUILD = "true"
-            CMAKE_IMPLIB_FILE_LOCATION_DEBUG = lib$${CMAKE_QT_STEM}d.a
-            CMAKE_IMPLIB_FILE_LOCATION_RELEASE = lib$${CMAKE_QT_STEM}.a
+        isEmpty(QMAKE_EXTENSION_IMPORTLIB): QMAKE_EXTENSION_IMPORTLIB = dll.a
+        CMAKE_IMPLIB_FILE_LOCATION_DEBUG = lib$${CMAKE_QT_STEM}d.$${QMAKE_EXTENSION_IMPORTLIB}
+        CMAKE_IMPLIB_FILE_LOCATION_RELEASE = lib$${CMAKE_QT_STEM}.$${QMAKE_EXTENSION_IMPORTLIB}
+        CMAKE_PRL_FILE_LOCATION_DEBUG = $${CMAKE_QT_STEM}d.prl
+        CMAKE_PRL_FILE_LOCATION_RELEASE = $${CMAKE_QT_STEM}.prl
+
+        CMAKE_IMPLIB_FILE_LOCATION_DEBUG_STATIC = lib$${CMAKE_QT_STEM}d.a
+        CMAKE_IMPLIB_FILE_LOCATION_RELEASE_STATIC = lib$${CMAKE_QT_STEM}.a
+        CMAKE_PRL_FILE_LOCATION_DEBUG_STATIC = $${CMAKE_QT_STEM}d.static.prl
+        CMAKE_PRL_FILE_LOCATION_RELEASE_STATIC = $${CMAKE_QT_STEM}.static.prl
 
-            CMAKE_PRL_FILE_LOCATION_DEBUG = lib$${CMAKE_QT_STEM}d.prl
-            CMAKE_PRL_FILE_LOCATION_RELEASE = lib$${CMAKE_QT_STEM}.prl
-        } else {
-            isEmpty(QMAKE_EXTENSION_IMPORTLIB): QMAKE_EXTENSION_IMPORTLIB = a
-            CMAKE_IMPLIB_FILE_LOCATION_DEBUG = lib$${CMAKE_QT_STEM}d.$${QMAKE_EXTENSION_IMPORTLIB}
-            CMAKE_IMPLIB_FILE_LOCATION_RELEASE = lib$${CMAKE_QT_STEM}.$${QMAKE_EXTENSION_IMPORTLIB}
-        }
     } else {
         CMAKE_WINMAIN_FILE_LOCATION_DEBUG = qtmain$${QT_LIBINFIX}d.lib
         CMAKE_WINMAIN_FILE_LOCATION_RELEASE = qtmain$${QT_LIBINFIX}.lib
 
-        !isEmpty(CMAKE_STATIC_TYPE) {
-            CMAKE_STATIC_WINDOWS_BUILD = "true"
-            CMAKE_IMPLIB_FILE_LOCATION_DEBUG = $${CMAKE_QT_STEM}d.lib
-            CMAKE_IMPLIB_FILE_LOCATION_RELEASE = $${CMAKE_QT_STEM}.lib
+        CMAKE_IMPLIB_FILE_LOCATION_DEBUG = $${CMAKE_QT_STEM}d.lib
+        CMAKE_IMPLIB_FILE_LOCATION_RELEASE = $${CMAKE_QT_STEM}.lib
+        CMAKE_PRL_FILE_LOCATION_DEBUG = $${CMAKE_QT_STEM}d.prl
+        CMAKE_PRL_FILE_LOCATION_RELEASE = $${CMAKE_QT_STEM}.prl
 
-            CMAKE_PRL_FILE_LOCATION_DEBUG = $${CMAKE_QT_STEM}d.prl
-            CMAKE_PRL_FILE_LOCATION_RELEASE = $${CMAKE_QT_STEM}.prl
-        } else {
-            CMAKE_IMPLIB_FILE_LOCATION_DEBUG = $${CMAKE_QT_STEM}d.lib
-            CMAKE_IMPLIB_FILE_LOCATION_RELEASE = $${CMAKE_QT_STEM}.lib
-        }
+        CMAKE_IMPLIB_FILE_LOCATION_DEBUG_STATIC = $${CMAKE_QT_STEM}d.lib
+        CMAKE_IMPLIB_FILE_LOCATION_RELEASE_STATIC = $${CMAKE_QT_STEM}.lib
+        CMAKE_PRL_FILE_LOCATION_DEBUG_STATIC = $${CMAKE_QT_STEM}d.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
@@ -278,12 +289,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 \
@@ -293,11 +304,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
 
@@ -309,7 +338,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
@@ -317,7 +346,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 15d8b8372e..939e55dfd8 100644
--- a/mkspecs/features/data/cmake/Qt5BasicConfig.cmake.in
+++ b/mkspecs/features/data/cmake/Qt5BasicConfig.cmake.in
@@ -3,6 +3,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]\")
@@ -29,15 +56,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.
@@ -48,23 +79,60 @@ but not all the files it references.
     endif()
 endmacro()
 
+!!IF !isEmpty(CMAKE_STATIC_TYPE)
+# 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 TARGET_CONFIG LIB_LOCATION IMPLIB_LOCATION)
-    set_property(TARGET Qt5::$${CMAKE_MODULE_NAME} APPEND PROPERTY IMPORTED_CONFIGURATIONS ${TARGET_CONFIG})
+!!IF !isEmpty(CMAKE_STATIC_TYPE)
+macro(_populate_$${CMAKE_MODULE_NAME}_target_properties_static TARGET_NAME TARGET_CONFIG LIB_LOCATION IMPLIB_LOCATION)
+!!ELSE
+macro(_populate_$${CMAKE_MODULE_NAME}_target_properties TARGET_NAME TARGET_CONFIG LIB_LOCATION IMPLIB_LOCATION)
+!!ENDIF
+    set_property(TARGET ${TARGET_NAME} APPEND PROPERTY IMPORTED_CONFIGURATIONS ${TARGET_CONFIG})
 
 !!IF isEmpty(CMAKE_DLL_DIR_IS_ABSOLUTE)
+
+!!IF !isEmpty(CMAKE_WINDOWS_BUILD)
+!!IF !isEmpty(CMAKE_STATIC_TYPE)
+    set(imported_location \"${_qt5$${CMAKE_MODULE_NAME}_install_prefix}/lib/${LIB_LOCATION}\")
+!!ELSE
+    set(imported_location \"${_qt5$${CMAKE_MODULE_NAME}_install_prefix}/bin/${LIB_LOCATION}\")
+!!ENDIF
+!!ELSE
     set(imported_location \"${_qt5$${CMAKE_MODULE_NAME}_install_prefix}/$${CMAKE_DLL_DIR}${LIB_LOCATION}\")
+!!ENDIF
+
+!!ELSE // isEmpty(CMAKE_DLL_DIR_IS_ABSOLUTE)
+
+!!IF !isEmpty(CMAKE_WINDOWS_BUILD)
+!!IF !isEmpty(CMAKE_STATIC_TYPE)
+    set(imported_location \"lib/${LIB_LOCATION}\")
+!!ELSE
+    set(imported_location \"bin/${LIB_LOCATION}\")
+!!ENDIF
 !!ELSE
     set(imported_location \"$${CMAKE_DLL_DIR}${LIB_LOCATION}\")
 !!ENDIF
 
+!!ENDIF // isEmpty(CMAKE_DLL_DIR_IS_ABSOLUTE)
+
+!!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
 
 !!IF !isEmpty(CMAKE_STATIC_TYPE)
     if (_Qt5$${CMAKE_MODULE_NAME}_LIB_DEPENDENCIES)
         set(_list_sep \";\")
     endif()
-    set_target_properties(Qt5::$${CMAKE_MODULE_NAME} PROPERTIES
+    set_target_properties(${TARGET_NAME} PROPERTIES
         \"INTERFACE_LINK_LIBRARIES_${TARGET_CONFIG}\" \"${_Qt5$${CMAKE_MODULE_NAME}_LIB_DEPENDENCIES}${_list_sep}${_Qt5$${CMAKE_MODULE_NAME}_STATIC_${TARGET_CONFIG}_LIB_DEPENDENCIES}\"
         \"IMPORTED_LOCATION_${TARGET_CONFIG}\" ${imported_location}
 !!IF !isEmpty(CMAKE_LIB_SONAME)
@@ -74,7 +142,7 @@ macro(_populate_$${CMAKE_MODULE_NAME}_target_properties TARGET_CONFIG LIB_LOCATI
         \"IMPORTED_LINK_INTERFACE_LIBRARIES_${TARGET_CONFIG}\" \"${_Qt5$${CMAKE_MODULE_NAME}_LIB_DEPENDENCIES}${_list_sep}${_Qt5$${CMAKE_MODULE_NAME}_STATIC_${TARGET_CONFIG}_LIB_DEPENDENCIES}\"
     )
 !!ELSE
-    set_target_properties(Qt5::$${CMAKE_MODULE_NAME} PROPERTIES
+    set_target_properties(${TARGET_NAME} PROPERTIES
         \"INTERFACE_LINK_LIBRARIES_${TARGET_CONFIG}\" \"${_Qt5$${CMAKE_MODULE_NAME}_LIB_DEPENDENCIES}\"
         \"IMPORTED_LOCATION_${TARGET_CONFIG}\" ${imported_location}
 !!IF !isEmpty(CMAKE_LIB_SONAME)
@@ -91,9 +159,13 @@ macro(_populate_$${CMAKE_MODULE_NAME}_target_properties TARGET_CONFIG LIB_LOCATI
 !!ELSE
     set(imported_implib \"IMPORTED_IMPLIB_${TARGET_CONFIG}\" \"$${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_${TARGET_CONFIG}\" ${imported_implib}
         )
     endif()
@@ -101,8 +173,9 @@ macro(_populate_$${CMAKE_MODULE_NAME}_target_properties TARGET_CONFIG LIB_LOCATI
 endmacro()
 !!ENDIF
 
-if (NOT TARGET Qt5::$${CMAKE_MODULE_NAME})
+set(TARGET_NAME ${QT_VARIANT_PREFIX}Qt5::$${CMAKE_MODULE_NAME})
 
+if(NOT TARGET ${TARGET_NAME})
 !!IF !no_module_headers
 !!IF !isEmpty(CMAKE_BUILD_IS_FRAMEWORK)
     set(_Qt5$${CMAKE_MODULE_NAME}_OWN_INCLUDE_DIRS
@@ -110,46 +183,50 @@ if (NOT TARGET Qt5::$${CMAKE_MODULE_NAME})
       \"${_qt5$${CMAKE_MODULE_NAME}_install_prefix}/$${CMAKE_LIB_DIR}Qt$${CMAKE_MODULE_NAME}.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}Qt$${CMAKE_MODULE_NAME}.framework/Versions/$$section(VERSION, ., 0, 0)/Headers/$$VERSION/\"
         \"${_qt5$${CMAKE_MODULE_NAME}_install_prefix}/$${CMAKE_LIB_DIR}Qt$${CMAKE_MODULE_NAME}.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 \"\")
-!!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_INCLUDE_DIR_IS_ABSOLUTE)
     set(_Qt5$${CMAKE_MODULE_NAME}_OWN_INCLUDE_DIRS \"$$CMAKE_INCLUDE_DIR\" \"$${CMAKE_INCLUDE_DIR}Qt$${CMAKE_MODULE_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)
@@ -158,16 +235,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}\")
 
@@ -175,10 +256,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)
@@ -186,17 +267,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}
@@ -204,36 +285,41 @@ 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
 
+!!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}\")
 !!ENDIF
 
 !!IF !isEmpty(CMAKE_STATIC_TYPE)
-    add_library(Qt5::$${CMAKE_MODULE_NAME} STATIC IMPORTED)
-    set_property(TARGET Qt5::$${CMAKE_MODULE_NAME} PROPERTY IMPORTED_LINK_INTERFACE_LANGUAGES "CXX")
+    add_library(${QT_VARIANT_PREFIX}Qt5::$${CMAKE_MODULE_NAME} STATIC IMPORTED)
+    set_property(TARGET ${QT_VARIANT_PREFIX}Qt5::$${CMAKE_MODULE_NAME} PROPERTY IMPORTED_LINK_INTERFACE_LANGUAGES "CXX")
+
     macro(_process_prl_file PRL_FILE_LOCATION CONFIGURATION)
         if (EXISTS \"${PRL_FILE_LOCATION}\")
             file(STRINGS \"${PRL_FILE_LOCATION}\" prl_strings REGEX \"QMAKE_PRL_LIBS_FOR_CMAKE\")
@@ -257,37 +343,48 @@ if (NOT TARGET Qt5::$${CMAKE_MODULE_NAME})
     endmacro()
 
 !!IF isEmpty(CMAKE_LIB_DIR_IS_ABSOLUTE)
-    _process_prl_file(\"${_qt5$${CMAKE_MODULE_NAME}_install_prefix}/$${CMAKE_LIB_DIR}$${CMAKE_PRL_FILE_LOCATION_DEBUG}\" DEBUG)
+    _process_prl_file(\"${_qt5$${CMAKE_MODULE_NAME}_install_prefix}/$${CMAKE_LIB_DIR}$${CMAKE_PRL_FILE_LOCATION_DEBUG_STATIC}\" DEBUG)
 !!ELSE
-    _process_prl_file(\"$${CMAKE_LIB_DIR}$${CMAKE_PRL_FILE_LOCATION_DEBUG}\" DEBUG)
+    _process_prl_file(\"$${CMAKE_LIB_DIR}$${CMAKE_PRL_FILE_LOCATION_DEBUG_STATIC}\" DEBUG)
 !!ENDIF
 !!IF isEmpty(CMAKE_LIB_DIR_IS_ABSOLUTE)
-    _process_prl_file(\"${_qt5$${CMAKE_MODULE_NAME}_install_prefix}/$${CMAKE_LIB_DIR}$${CMAKE_PRL_FILE_LOCATION_RELEASE}\" RELEASE)
+    _process_prl_file(\"${_qt5$${CMAKE_MODULE_NAME}_install_prefix}/$${CMAKE_LIB_DIR}$${CMAKE_PRL_FILE_LOCATION_RELEASE_STATIC}\" RELEASE)
 !!ELSE
-    _process_prl_file(\"$${CMAKE_LIB_DIR}$${CMAKE_PRL_FILE_LOCATION_RELEASE}\" RELEASE)
+    _process_prl_file(\"$${CMAKE_LIB_DIR}$${CMAKE_PRL_FILE_LOCATION_RELEASE_STATIC}\" RELEASE)
 !!ENDIF
 
 !!ELSE // !isEmpty(CMAKE_STATIC_TYPE)
 !!IF equals(TEMPLATE, aux)
-    add_library(Qt5::$${CMAKE_MODULE_NAME} INTERFACE IMPORTED)
+    add_library(${QT_VARIANT_PREFIX}Qt5::$${CMAKE_MODULE_NAME} INTERFACE IMPORTED)
 !!ELSE
-    add_library(Qt5::$${CMAKE_MODULE_NAME} SHARED IMPORTED)
+    add_library(${QT_VARIANT_PREFIX}Qt5::$${CMAKE_MODULE_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 ${QT_VARIANT_PREFIX}Qt5::$${CMAKE_MODULE_NAME} PROPERTY FRAMEWORK 1)
 !!ENDIF
 !!ENDIF // TEMPLATE != aux
 
-    set_property(TARGET Qt5::$${CMAKE_MODULE_NAME} PROPERTY
+!!IF !equals(TEMPLATE, aux)
+!!IF !isEmpty(CMAKE_BUILD_IS_FRAMEWORK)
+    set_property(TARGET ${QT_VARIANT_PREFIX}Qt5::$${CMAKE_MODULE_NAME} PROPERTY FRAMEWORK 1)
+!!ENDIF
+!!ENDIF // TEMPLATE != aux
+
+    set_property(TARGET ${QT_VARIANT_PREFIX}Qt5::$${CMAKE_MODULE_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 ${QT_VARIANT_PREFIX}Qt5::$${CMAKE_MODULE_NAME} PROPERTY
+        INTERFACE_COMPILE_DEFINITIONS $${CMAKE_INTERFACE_COMPILE_DEFINITIONS_STATIC} $${MODULE_DEFINES})
+!!ELSE
+    set_property(TARGET ${QT_VARIANT_PREFIX}Qt5::$${CMAKE_MODULE_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 ${QT_VARIANT_PREFIX}Qt5::$${CMAKE_MODULE_NAME} PROPERTY INTERFACE_QT_ENABLED_FEATURES $$join(QT.$${MODULE}.enabled_features, ";"))
+    set_property(TARGET ${QT_VARIANT_PREFIX}Qt5::$${CMAKE_MODULE_NAME} PROPERTY INTERFACE_QT_DISABLED_FEATURES $$join(QT.$${MODULE}.disabled_features, ";"))
 
     # Find plugin targets
     file(GLOB pluginTargetsMaybe \"${CMAKE_CURRENT_LIST_DIR}/*Qt5$${CMAKE_MODULE_NAME}_*.cmake\")
@@ -301,7 +398,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)
@@ -309,7 +410,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}
         )
@@ -340,16 +445,16 @@ if (NOT TARGET Qt5::$${CMAKE_MODULE_NAME})
     endif()
 
     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 ${${QT_VARIANT_PREFIX}Qt5$${CMAKE_MODULE_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(${QT_VARIANT_PREFIX}Qt5::$${CMAKE_MODULE_NAME}Private INTERFACE IMPORTED)
+        set_property(TARGET ${QT_VARIANT_PREFIX}Qt5::$${CMAKE_MODULE_NAME}Private PROPERTY
+            INTERFACE_INCLUDE_DIRECTORIES ${${QT_VARIANT_PREFIX}Qt5$${CMAKE_MODULE_NAME}_OWN_PRIVATE_INCLUDE_DIRS}
         )
         set(_Qt5$${CMAKE_MODULE_NAME}_PRIVATEDEPS)
         foreach(dep ${_Qt5$${CMAKE_MODULE_NAME}_LIB_DEPENDENCIES})
@@ -357,66 +462,68 @@ if (NOT TARGET Qt5::$${CMAKE_MODULE_NAME})
                 list(APPEND _Qt5$${CMAKE_MODULE_NAME}_PRIVATEDEPS ${dep}Private)
             endif()
         endforeach()
-        set_property(TARGET Qt5::$${CMAKE_MODULE_NAME}Private PROPERTY
-            INTERFACE_LINK_LIBRARIES Qt5::$${CMAKE_MODULE_NAME} ${_Qt5$${CMAKE_MODULE_NAME}_PRIVATEDEPS}
+        set_property(TARGET ${QT_VARIANT_PREFIX}Qt5::$${CMAKE_MODULE_NAME}Private PROPERTY
+            INTERFACE_LINK_LIBRARIES ${QT_VARIANT_PREFIX}Qt5::$${CMAKE_MODULE_NAME} ${_Qt5$${CMAKE_MODULE_NAME}_PRIVATEDEPS}
         )
     endif()
 
 !!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}\" \"\" )
+!!IF !isEmpty(CMAKE_STATIC_TYPE)
+    _populate_$${CMAKE_MODULE_NAME}_target_properties_static(${QT_VARIANT_PREFIX}Qt5::$${CMAKE_MODULE_NAME} RELEASE \"$${CMAKE_IMPLIB_FILE_LOCATION_RELEASE_STATIC}\" \"\" )
 !!ELSE
-    _populate_$${CMAKE_MODULE_NAME}_target_properties(RELEASE \"$${CMAKE_LIB_FILE_LOCATION_RELEASE}\" \"$${CMAKE_IMPLIB_FILE_LOCATION_RELEASE}\" )
-!!ENDIF // CMAKE_STATIC_WINDOWS_BUILD
+    _populate_$${CMAKE_MODULE_NAME}_target_properties(${QT_VARIANT_PREFIX}Qt5::$${CMAKE_MODULE_NAME} RELEASE \"$${CMAKE_LIB_FILE_LOCATION_RELEASE}\" \"$${CMAKE_IMPLIB_FILE_LOCATION_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}\" \"\" )
-!!ELSE // CMAKE_STATIC_WINDOWS_BUILD
+        _populate_$${CMAKE_MODULE_NAME}_target_properties_static(${QT_VARIANT_PREFIX}Qt5::$${CMAKE_MODULE_NAME} DEBUG \"$${CMAKE_IMPLIB_FILE_LOCATION_DEBUG_STATIC}\" \"\" )
+    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}\" )
-!!ENDIF // CMAKE_STATIC_WINDOWS_BUILD
+        _populate_$${CMAKE_MODULE_NAME}_target_properties(${QT_VARIANT_PREFIX}Qt5::$${CMAKE_MODULE_NAME} DEBUG \"$${CMAKE_LIB_FILE_LOCATION_DEBUG}\" \"$${CMAKE_IMPLIB_FILE_LOCATION_DEBUG}\" )
     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}\" \"\" )
+!!IF !isEmpty(CMAKE_STATIC_TYPE)
+    _populate_$${CMAKE_MODULE_NAME}_target_properties_static(DEBUG \"$${CMAKE_IMPLIB_FILE_LOCATION_DEBUG}\" \"\" )
 !!ELSE
     _populate_$${CMAKE_MODULE_NAME}_target_properties(DEBUG \"$${CMAKE_LIB_FILE_LOCATION_DEBUG}\" \"$${CMAKE_IMPLIB_FILE_LOCATION_DEBUG}\" )
-!!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}\" \"\" )
-!!ELSE // CMAKE_STATIC_WINDOWS_BUILD
+        _populate_$${CMAKE_MODULE_NAME}_target_properties_static(${QT_VARIANT_PREFIX}Qt5::$${CMAKE_MODULE_NAME} RELEASE \"$${CMAKE_IMPLIB_FILE_LOCATION_RELEASE_STATIC}\" \"\" )
+!!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}\"
@@ -429,7 +536,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}\" )
+        _populate_$${CMAKE_MODULE_NAME}_target_properties(${QT_VARIANT_PREFIX}Qt5::$${CMAKE_MODULE_NAME} RELEASE \"$${CMAKE_LIB_FILE_LOCATION_RELEASE}\" \"$${CMAKE_IMPLIB_FILE_LOCATION_RELEASE}\" )
     endif()
 !!ENDIF // CMAKE_STATIC_TYPE
 
@@ -439,19 +546,22 @@ 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(${QT_VARIANT_PREFIX}Qt5::$${CMAKE_MODULE_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()
diff --git a/mkspecs/features/data/cmake/Qt5PluginTarget.cmake.in b/mkspecs/features/data/cmake/Qt5PluginTarget.cmake.in
index ec5f3cc437..1e4d98086c 100644
--- a/mkspecs/features/data/cmake/Qt5PluginTarget.cmake.in
+++ b/mkspecs/features/data/cmake/Qt5PluginTarget.cmake.in
@@ -1,14 +1,22 @@
 # 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_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
 !!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)
+list(APPEND ${QT_VARIANT_PREFIX}Qt5$${CMAKE_MODULE_NAME}_PLUGINS ${QT_VARIANT_PREFIX}Qt5::$$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 e0652fdcf9..f0add757bb 100644
--- a/src/corelib/Qt5CoreConfigExtras.cmake.in
+++ b/src/corelib/Qt5CoreConfigExtras.cmake.in
@@ -1,4 +1,6 @@
 
+set(IMPORTED_TARGET_NAME ${QT_VARIANT_PREFIX}Qt5::$${CMAKE_MODULE_NAME})
+
 if (NOT TARGET Qt5::qmake)
     add_executable(Qt5::qmake IMPORTED)
 
@@ -50,9 +52,9 @@ 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 Qt5::Core APPEND PROPERTY
+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)
+set_property(TARGET ${IMPORTED_TARGET_NAME} APPEND PROPERTY
   COMPATIBLE_INTERFACE_STRING QT_MAJOR_VERSION QT_COORD_TYPE
 )
 
@@ -63,7 +65,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
@@ -78,7 +80,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 \"\")
@@ -86,7 +88,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)
@@ -95,9 +97,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\")
@@ -145,14 +147,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 2e32911a64..6b02a12944 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)
 
@@ -170,9 +172,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.20.1