forked from qt/qtbase
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathQtTargetHelpers.cmake
1785 lines (1606 loc) · 74.8 KB
/
QtTargetHelpers.cmake
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
# Copyright (C) 2022 The Qt Company Ltd.
# SPDX-License-Identifier: BSD-3-Clause
# This function can be used to add sources/libraries/etc. to the specified CMake target
# if the provided CONDITION evaluates to true.
# One-value Arguments:
# PRECOMPILED_HEADER
# Name of the precompiled header that is used for the target.
# Multi-value Arguments:
# CONDITION
# The condition under which the target will be extended.
# CONDITION_INDEPENDENT_SOURCES
# Source files that should be added to the target unconditionally. Note that if target is Qt
# module, these files will raise a warning at configure time if the condition is not met.
# COMPILE_FLAGS
# Custom compilation flags.
# EXTRA_LINKER_SCRIPT_CONTENT
# Extra content that should be appended to a target linker script. Applicable for ld only.
# EXTRA_LINKER_SCRIPT_EXPORTS
# Extra content that should be added to export section of the linker script.
# NO_PCH_SOURCES
# Exclude the specified source files from PRECOMPILE_HEADERS and UNITY_BUILD builds.
function(qt_internal_extend_target target)
if(NOT TARGET "${target}")
message(FATAL_ERROR "${target} is not a target.")
endif()
qt_internal_is_skipped_test(skipped ${target})
if(skipped)
return()
endif()
qt_internal_is_in_test_batch(in_batch ${target})
if(in_batch)
_qt_internal_test_batch_target_name(target)
endif()
# Don't try to extend_target when cross compiling an imported host target (like a tool).
qt_is_imported_target("${target}" is_imported)
if(is_imported)
return()
endif()
set(option_args
NO_UNITY_BUILD
${__qt_internal_sbom_optional_args}
)
set(single_args
PRECOMPILED_HEADER
EXTRA_LINKER_SCRIPT_CONTENT
${__qt_internal_sbom_single_args}
)
set(multi_args
${__default_public_args}
${__default_private_args}
${__default_private_module_args}
CONDITION
CONDITION_INDEPENDENT_SOURCES
COMPILE_FLAGS
EXTRA_LINKER_SCRIPT_EXPORTS
${__qt_internal_sbom_multi_args}
)
cmake_parse_arguments(PARSE_ARGV 1 arg
"${option_args}"
"${single_args}"
"${multi_args}"
)
_qt_internal_validate_all_args_are_parsed(arg)
if("x${arg_CONDITION}" STREQUAL "x")
set(arg_CONDITION ON)
endif()
qt_evaluate_config_expression(result ${arg_CONDITION})
if(${result})
if(QT_CMAKE_DEBUG_EXTEND_TARGET)
message("qt_extend_target(${target} CONDITION ${arg_CONDITION} ...): Evaluated")
endif()
set(dbus_sources "")
foreach(adaptor ${arg_DBUS_ADAPTOR_SOURCES})
_qt_internal_forward_function_args(
FORWARD_PREFIX arg_DBUS_ADAPTOR
FORWARD_OUT_VAR forwarded_args
FORWARD_SINGLE
BASENAME
FLAGS
)
qt_create_qdbusxml2cpp_command("${target}" "${adaptor}" ADAPTOR ${forwarded_args})
list(APPEND dbus_sources "${adaptor}")
endforeach()
foreach(interface ${arg_DBUS_INTERFACE_SOURCES})
_qt_internal_forward_function_args(
FORWARD_PREFIX arg_DBUS_INTERFACE
FORWARD_OUT_VAR forwarded_args
FORWARD_SINGLE
BASENAME
FLAGS
)
qt_create_qdbusxml2cpp_command("${target}" "${interface}" INTERFACE ${forwarded_args})
list(APPEND dbus_sources "${interface}")
endforeach()
set(all_sources
${arg_SOURCES}
${dbus_sources}
)
get_target_property(target_type ${target} TYPE)
set(is_library FALSE)
set(is_interface_lib FALSE)
set(is_executable FALSE)
if(${target_type} STREQUAL "STATIC_LIBRARY" OR ${target_type} STREQUAL "SHARED_LIBRARY")
set(is_library TRUE)
elseif(target_type STREQUAL "INTERFACE_LIBRARY")
set(is_interface_lib TRUE)
elseif(target_type STREQUAL "EXECUTABLE")
set(is_executable TRUE)
endif()
foreach(lib ${arg_PUBLIC_LIBRARIES} ${arg_LIBRARIES})
# Automatically generate PCH for 'target' using public dependencies.
# But only if 'target' is a library/module that does not specify its own PCH file.
if(NOT arg_PRECOMPILED_HEADER AND ${is_library})
qt_update_precompiled_header_with_library("${target}" "${lib}")
endif()
string(REGEX REPLACE "_nolink$" "" base_lib "${lib}")
if(NOT base_lib STREQUAL lib)
qt_create_nolink_target("${base_lib}" ${target})
endif()
# Collect _sync_headers targets from libraries that the target depends on. This is
# heuristic way of building the dependency tree between the _sync_headers targets of
# different Qt modules.
if(TARGET "${lib}")
get_target_property(is_imported ${lib} IMPORTED)
if(NOT is_imported)
get_target_property(is_private ${lib} _qt_is_private_module)
if(is_private)
get_target_property(lib ${lib} _qt_public_module_target_name)
endif()
set(out_genex "$<TARGET_PROPERTY:${lib},_qt_internal_sync_headers_target>")
set_property(TARGET ${target}
APPEND PROPERTY _qt_internal_sync_headers_deps "${out_genex}")
endif()
endif()
endforeach()
list(TRANSFORM arg_PUBLIC_LIBRARIES REPLACE "^Qt::" "${QT_CMAKE_EXPORT_NAMESPACE}::")
list(TRANSFORM arg_LIBRARIES REPLACE "^Qt::" "${QT_CMAKE_EXPORT_NAMESPACE}::")
# Set-up the target
# CMake versions less than 3.19 don't support adding the source files to the PRIVATE scope
# of the INTERFACE libraries. These PRIVATE sources are only needed by IDEs to display
# them in a project tree, so to avoid build issues and appearing the sources in
# INTERFACE_SOURCES property of INTERFACE_LIBRARY. Collect them inside the
# _qt_internal_target_sources property, since they can be useful in the source processing
# functions. The property itself is not exported and should only be used in the Qt internal
# build tree.
if(NOT is_interface_lib OR CMAKE_VERSION VERSION_GREATER_EQUAL "3.19")
target_sources("${target}" PRIVATE ${all_sources})
if(arg_COMPILE_FLAGS)
set_source_files_properties(${all_sources} PROPERTIES
COMPILE_FLAGS "${arg_COMPILE_FLAGS}")
endif()
else()
set_property(TARGET ${target} APPEND PROPERTY
_qt_internal_target_sources ${all_sources})
endif()
set(public_visibility_option "PUBLIC")
set(private_visibility_option "PRIVATE")
if(is_interface_lib)
set(public_visibility_option "INTERFACE")
set(private_visibility_option "INTERFACE")
endif()
target_include_directories("${target}"
${public_visibility_option} ${arg_PUBLIC_INCLUDE_DIRECTORIES}
${private_visibility_option} ${arg_INCLUDE_DIRECTORIES})
target_include_directories("${target}" SYSTEM
${private_visibility_option} ${arg_SYSTEM_INCLUDE_DIRECTORIES})
target_compile_definitions("${target}"
${public_visibility_option} ${arg_PUBLIC_DEFINES}
${private_visibility_option} ${arg_DEFINES})
target_link_libraries("${target}"
${public_visibility_option} ${arg_PUBLIC_LIBRARIES}
${private_visibility_option} ${arg_LIBRARIES})
target_compile_options("${target}"
${public_visibility_option} ${arg_PUBLIC_COMPILE_OPTIONS}
${private_visibility_option} ${arg_COMPILE_OPTIONS})
target_link_options("${target}"
${public_visibility_option} ${arg_PUBLIC_LINK_OPTIONS}
${private_visibility_option} ${arg_LINK_OPTIONS})
if(NOT is_interface_lib)
set_property(TARGET "${target}" APPEND PROPERTY
AUTOMOC_MOC_OPTIONS "${arg_MOC_OPTIONS}"
)
# Plugin types associated to a module
if(NOT "x${arg_PLUGIN_TYPES}" STREQUAL "x")
qt_internal_add_plugin_types("${target}" "${arg_PLUGIN_TYPES}")
endif()
endif()
# When computing the private library dependencies, we need to check not only the known
# modules added by this repo's qt_build_repo(), but also all module dependencies that
# were found via find_package().
qt_internal_get_qt_all_known_modules(known_modules)
# When a public module depends on a private module (Gui on CorePrivate)
# make its private module depend on the other private module (GuiPrivate will depend on
# CorePrivate).
set(qt_libs_private "")
foreach(it ${known_modules})
list(FIND arg_LIBRARIES "Qt::${it}Private" pos)
if(pos GREATER -1)
list(APPEND qt_libs_private "Qt::${it}Private")
endif()
endforeach()
if(arg_LIBRARIES)
_qt_internal_append_to_target_property_without_duplicates(${target}
_qt_extend_target_libraries "${arg_LIBRARIES}"
)
endif()
if(arg_PUBLIC_LIBRARIES)
_qt_internal_append_to_target_property_without_duplicates(${target}
_qt_extend_target_public_libraries "${arg_PUBLIC_LIBRARIES}"
)
endif()
if(QT_GENERATE_SBOM)
set(sbom_args "")
_qt_internal_forward_function_args(
FORWARD_APPEND
FORWARD_PREFIX arg
FORWARD_OUT_VAR sbom_args
FORWARD_OPTIONS
${__qt_internal_sbom_optional_args}
FORWARD_SINGLE
${__qt_internal_sbom_single_args}
FORWARD_MULTI
${__qt_internal_sbom_multi_args}
)
_qt_internal_extend_sbom(${target} ${sbom_args})
endif()
set(target_private "${target}Private")
get_target_property(is_internal_module ${target} _qt_is_internal_module)
# Internal modules don't have Private targets but we still need to
# propagate their private dependencies.
if(is_internal_module)
set(target_private "${target}")
endif()
if(TARGET "${target_private}")
target_link_libraries("${target_private}"
INTERFACE ${arg_PRIVATE_MODULE_INTERFACE})
elseif(arg_PRIVATE_MODULE_INTERFACE)
set(warning_message "")
string(APPEND warning_message
"The PRIVATE_MODULE_INTERFACE option was provided the values:"
"'${arg_PRIVATE_MODULE_INTERFACE}' "
"but there is no ${target}Private target to assign them to."
"Ensure the target exists or remove the option.")
message(AUTHOR_WARNING "${warning_message}")
endif()
set(qt_register_target_dependencies_args "")
if(arg_PUBLIC_LIBRARIES OR arg_PRIVATE_MODULE_INTERFACE)
list(APPEND qt_register_target_dependencies_args
PUBLIC ${arg_PUBLIC_LIBRARIES} ${arg_PRIVATE_MODULE_INTERFACE})
endif()
if(qt_libs_private OR arg_LIBRARIES)
list(APPEND qt_register_target_dependencies_args
PRIVATE ${qt_libs_private} ${arg_LIBRARIES})
endif()
qt_internal_register_target_dependencies("${target}"
${qt_register_target_dependencies_args})
qt_autogen_tools(${target}
ENABLE_AUTOGEN_TOOLS ${arg_ENABLE_AUTOGEN_TOOLS}
DISABLE_AUTOGEN_TOOLS ${arg_DISABLE_AUTOGEN_TOOLS})
qt_update_precompiled_header("${target}" "${arg_PRECOMPILED_HEADER}")
## Also exclude them from unity build
qt_update_ignore_pch_source("${target}" "${arg_NO_PCH_SOURCES}")
## Ignore objective-c files for PCH (not supported atm)
qt_ignore_pch_obj_c_sources("${target}" "${arg_SOURCES}")
if(arg_NO_UNITY_BUILD)
set_target_properties("${target}" PROPERTIES UNITY_BUILD OFF)
qt_update_ignore_unity_build_sources("${target}" "${arg_SOURCES}")
endif()
if(arg_NO_UNITY_BUILD_SOURCES)
qt_update_ignore_unity_build_sources("${target}" "${arg_NO_UNITY_BUILD_SOURCES}")
endif()
else()
if(QT_CMAKE_DEBUG_EXTEND_TARGET)
message("qt_extend_target(${target} CONDITION ${arg_CONDITION} ...): Skipped")
endif()
endif()
if(arg_CONDITION_INDEPENDENT_SOURCES)
set_source_files_properties(${arg_CONDITION_INDEPENDENT_SOURCES} PROPERTIES
_qt_extend_target_condition "${arg_CONDITION}"
SKIP_AUTOGEN TRUE
)
qt_internal_get_target_sources_property(sources_property)
set_property(TARGET ${target} APPEND PROPERTY
${sources_property} "${arg_CONDITION_INDEPENDENT_SOURCES}")
endif()
if(arg_EXTRA_LINKER_SCRIPT_CONTENT)
set_target_properties(${target} PROPERTIES
_qt_extra_linker_script_content "${arg_EXTRA_LINKER_SCRIPT_CONTENT}")
endif()
if(arg_EXTRA_LINKER_SCRIPT_EXPORTS)
set_target_properties(${target} PROPERTIES
_qt_extra_linker_script_exports "${arg_EXTRA_LINKER_SCRIPT_EXPORTS}")
endif()
if(is_executable)
# If linking against Gui, make sure to also build the default QPA plugin.
# This makes the experience of an initial Qt configuration to build and run one single
# test / executable nicer.
set(linked_libs ${arg_PUBLIC_LIBRARIES} ${arg_LIBRARIES})
if(linked_libs MATCHES "(^|;)(${QT_CMAKE_EXPORT_NAMESPACE}::|Qt::)?Gui($|;)" AND
TARGET qpa_default_plugins)
add_dependencies("${target}" qpa_default_plugins)
endif()
# For executables collect static plugins that these targets depend on.
qt_internal_import_plugins(${target} ${linked_libs})
endif()
endfunction()
# Given CMAKE_CONFIG and ALL_CMAKE_CONFIGS, determines if a directory suffix needs to be appended
# to each destination, and sets the computed install target destination arguments in OUT_VAR.
# Defaults used for each of the destination types, and can be configured per destination type.
function(qt_get_install_target_default_args)
cmake_parse_arguments(PARSE_ARGV 0 arg
""
"OUT_VAR;OUT_VAR_RUNTIME;CMAKE_CONFIG;RUNTIME;LIBRARY;ARCHIVE;INCLUDES;BUNDLE"
"ALL_CMAKE_CONFIGS")
_qt_internal_validate_all_args_are_parsed(arg)
if(NOT arg_CMAKE_CONFIG)
message(FATAL_ERROR "No value given for CMAKE_CONFIG.")
endif()
if(NOT arg_ALL_CMAKE_CONFIGS)
message(FATAL_ERROR "No value given for ALL_CMAKE_CONFIGS.")
endif()
list(LENGTH arg_ALL_CMAKE_CONFIGS all_configs_count)
list(GET arg_ALL_CMAKE_CONFIGS 0 first_config)
set(suffix "")
if(all_configs_count GREATER 1 AND NOT arg_CMAKE_CONFIG STREQUAL first_config)
set(suffix "/${arg_CMAKE_CONFIG}")
endif()
set(runtime "${INSTALL_BINDIR}")
if(arg_RUNTIME)
set(runtime "${arg_RUNTIME}")
endif()
set(library "${INSTALL_LIBDIR}")
if(arg_LIBRARY)
set(library "${arg_LIBRARY}")
endif()
set(archive "${INSTALL_LIBDIR}")
if(arg_ARCHIVE)
set(archive "${arg_ARCHIVE}")
endif()
set(includes "${INSTALL_INCLUDEDIR}")
if(arg_INCLUDES)
set(includes "${arg_INCLUDES}")
endif()
set(bundle "${INSTALL_BINDIR}")
if(arg_BUNDLE)
set(bundle "${arg_BUNDLE}")
endif()
set(args
RUNTIME DESTINATION "${runtime}${suffix}"
LIBRARY DESTINATION "${library}${suffix}"
ARCHIVE DESTINATION "${archive}${suffix}" COMPONENT Devel
BUNDLE DESTINATION "${bundle}${suffix}"
INCLUDES DESTINATION "${includes}${suffix}")
set(${arg_OUT_VAR} "${args}" PARENT_SCOPE)
if(arg_OUT_VAR_RUNTIME)
set(args
"${runtime}${suffix}"
)
set(${arg_OUT_VAR_RUNTIME} "${args}" PARENT_SCOPE)
endif()
endfunction()
macro(qt_internal_setup_default_target_function_options)
set(__default_private_args
SOURCES
LIBRARIES
INCLUDE_DIRECTORIES
SYSTEM_INCLUDE_DIRECTORIES
DEFINES
DBUS_ADAPTOR_BASENAME
DBUS_ADAPTOR_FLAGS
DBUS_ADAPTOR_SOURCES
DBUS_INTERFACE_BASENAME
DBUS_INTERFACE_FLAGS
DBUS_INTERFACE_SOURCES
FEATURE_DEPENDENCIES
COMPILE_OPTIONS
LINK_OPTIONS
MOC_OPTIONS
DISABLE_AUTOGEN_TOOLS
ENABLE_AUTOGEN_TOOLS
PLUGIN_TYPES
NO_PCH_SOURCES
NO_UNITY_BUILD_SOURCES
)
set(__default_public_args
PUBLIC_LIBRARIES
PUBLIC_INCLUDE_DIRECTORIES
PUBLIC_DEFINES
PUBLIC_COMPILE_OPTIONS
PUBLIC_LINK_OPTIONS
)
set(__default_private_module_args
PRIVATE_MODULE_INTERFACE
)
set(__default_target_info_args
TARGET_VERSION
TARGET_PRODUCT
TARGET_DESCRIPTION
TARGET_COMPANY
TARGET_COPYRIGHT
)
_qt_internal_get_sbom_add_target_common_options(
__qt_internal_sbom_optional_args
__qt_internal_sbom_single_args
__qt_internal_sbom_multi_args
)
# Collection of arguments so they can be shared across qt_internal_add_executable
# and qt_internal_add_test_helper.
set(__qt_internal_add_executable_optional_args
GUI
NO_INSTALL
EXCEPTIONS
DELAY_RC
DELAY_TARGET_INFO
QT_APP
QT_TEST
QT_MANUAL_TEST
QT_BENCHMARK_TEST
NO_UNITY_BUILD
${__qt_internal_sbom_optional_args}
)
set(__qt_internal_add_executable_single_args
CORE_LIBRARY
OUTPUT_DIRECTORY
INSTALL_DIRECTORY
VERSION
${__default_target_info_args}
${__qt_internal_sbom_single_args}
)
set(__qt_internal_add_executable_multi_args
${__default_private_args}
${__default_public_args}
${__qt_internal_sbom_multi_args}
)
endmacro()
# Append a config-specific postfix to library names to ensure distinct names
# in a multi-config build.
# e.g. lib/libQt6DBus_relwithdebinfo.6.3.0.dylib
# Don't apply the postfix to the first encountered release-like config, so we have at least one
# config without a postifx.
# If postfixes are set by user warn about potential issues.
function(qt_internal_setup_cmake_config_postfix)
# Collect configuration that require postfix in Qt library names.
if(QT_GENERATOR_IS_MULTI_CONFIG)
set(postfix_configurations ${CMAKE_CONFIGURATION_TYPES})
else()
set(postfix_configurations ${CMAKE_BUILD_TYPE})
# Set the default postfix to empty by default for single-config builds.
string(TOLOWER "${CMAKE_BUILD_TYPE}" build_type_lower)
set(default_cmake_${build_type_lower}_postfix "")
endif()
# Override the generic debug postfixes above with custom debug postfixes (even in a single
# config build) to follow the conventions we had since Qt 5.
# e.g. lib/libQt6DBus_debug.6.3.0.dylib
if(WIN32)
if(MINGW)
# On MinGW we don't have "d" suffix for debug libraries like on Linux,
# unless we're building debug and release libraries in one go.
if(QT_GENERATOR_IS_MULTI_CONFIG)
set(default_cmake_debug_postfix "d")
endif()
else()
set(default_cmake_debug_postfix "d")
endif()
elseif(APPLE)
# Only add a suffix for explicit no-framework builds.
# For framework builds the library inside the framework
# is always unsuffixed, and we want to match that for
# plugins and other non-framework (static) libraries.
if(NOT (QT_FEATURE_framework OR FEATURE_framework
# Account for default in configure.json being ON
OR (NOT DEFINED QT_FEATURE_framework AND NOT DEFINED FEATURE_framework)))
set(default_cmake_debug_postfix "_debug")
endif()
endif()
set(custom_postfix_vars "")
set(release_configs Release RelWithDebInfo MinSizeRel)
set(found_first_release_config FALSE)
foreach(config_type IN LISTS postfix_configurations)
string(TOLOWER "${config_type}" config_type_lower)
string(TOUPPER "${config_type}" config_type_upper)
set(postfix_var CMAKE_${config_type_upper}_POSTFIX)
# Skip assigning postfix for the first release-like config.
if(NOT found_first_release_config
AND config_type IN_LIST release_configs)
set(found_first_release_config TRUE)
if(NOT "${${postfix_var}}" STREQUAL "")
list(APPEND custom_postfix_vars ${postfix_var})
endif()
continue()
endif()
# Check if the default postfix is set, use '_<config_type_lower>' otherwise.
set(default_postfix_var
default_cmake_${config_type_lower}_postfix)
if(NOT DEFINED ${default_postfix_var})
set(${default_postfix_var}
"_${config_type_lower}")
endif()
# If postfix is set by user avoid changing it, but save postfix variable that has
# a non-default value for further warning.
if("${${postfix_var}}" STREQUAL "")
set(${postfix_var} "${${default_postfix_var}}")
set(${postfix_var} "${${default_postfix_var}}" PARENT_SCOPE)
elseif(NOT "${${postfix_var}}" STREQUAL "${${default_postfix_var}}")
list(APPEND custom_postfix_vars ${postfix_var})
endif()
# Adjust framework postfixes accordingly
if(APPLE)
set(CMAKE_FRAMEWORK_MULTI_CONFIG_POSTFIX_${config_type_upper}
"${${postfix_var}}" PARENT_SCOPE)
endif()
endforeach()
if(custom_postfix_vars)
list(REMOVE_DUPLICATES custom_postfix_vars)
list(JOIN custom_postfix_vars ", " postfix_vars_string)
message(WARNING "You are using custom library postfixes: '${postfix_vars_string}' which are"
" considered experimental and are not officially supported by Qt."
" Expect unforeseen issues and user projects built with qmake to be broken."
)
endif()
endfunction()
function(qt_is_imported_target target out_var)
if(NOT TARGET "${target}")
set(target "${QT_CMAKE_EXPORT_NAMESPACE}::${target}")
endif()
if(NOT TARGET "${target}")
message(FATAL_ERROR "Invalid target given to qt_is_imported_target: ${target}")
endif()
get_target_property(is_imported "${target}" IMPORTED)
set(${out_var} "${is_imported}" PARENT_SCOPE)
endfunction()
# Add Qt::target and Qt6::target as aliases for the target
function(qt_internal_add_target_aliases target)
set(versionless_alias "Qt::${target}")
set(versionfull_alias "Qt${PROJECT_VERSION_MAJOR}::${target}")
set_target_properties("${target}" PROPERTIES _qt_versionless_alias "${versionless_alias}")
set_target_properties("${target}" PROPERTIES _qt_versionfull_alias "${versionfull_alias}")
get_target_property(type "${target}" TYPE)
if (type STREQUAL EXECUTABLE)
add_executable("${versionless_alias}" ALIAS "${target}")
add_executable("${versionfull_alias}" ALIAS "${target}")
else()
add_library("${versionless_alias}" ALIAS "${target}")
add_library("${versionfull_alias}" ALIAS "${target}")
endif()
endfunction()
function(qt_get_cmake_configurations out_var)
set(possible_configs "${CMAKE_BUILD_TYPE}")
if(CMAKE_CONFIGURATION_TYPES)
set(possible_configs "${CMAKE_CONFIGURATION_TYPES}")
endif()
set(${out_var} "${possible_configs}" PARENT_SCOPE)
endfunction()
function(qt_clone_property_for_configs target property configs)
get_target_property(value "${target}" "${property}")
foreach(config ${configs})
string(TOUPPER "${config}" upper_config)
set_property(TARGET "${target}" PROPERTY "${property}_${upper_config}" "${value}")
endforeach()
endfunction()
function(qt_handle_multi_config_output_dirs target)
qt_get_cmake_configurations(possible_configs)
qt_clone_property_for_configs(${target} LIBRARY_OUTPUT_DIRECTORY "${possible_configs}")
qt_clone_property_for_configs(${target} RUNTIME_OUTPUT_DIRECTORY "${possible_configs}")
qt_clone_property_for_configs(${target} ARCHIVE_OUTPUT_DIRECTORY "${possible_configs}")
endfunction()
# Set target properties that are the same for all modules, plugins, executables
# and 3rdparty libraries.
function(qt_set_common_target_properties target)
if(QT_FEATURE_reduce_exports)
set_target_properties(${target} PROPERTIES
C_VISIBILITY_PRESET hidden
CXX_VISIBILITY_PRESET hidden
OBJC_VISIBILITY_PRESET hidden
OBJCXX_VISIBILITY_PRESET hidden
VISIBILITY_INLINES_HIDDEN 1)
endif()
qt_internal_set_compile_pdb_names("${target}")
endfunction()
# Set common, informational target properties.
#
# On Windows, these properties are used to generate the version information resource.
function(qt_set_target_info_properties target)
cmake_parse_arguments(arg "" "${__default_target_info_args}" "" ${ARGN})
if(NOT arg_TARGET_VERSION)
set(arg_TARGET_VERSION "${PROJECT_VERSION}.0")
endif()
if(NOT arg_TARGET_PRODUCT)
set(arg_TARGET_PRODUCT "Qt6")
endif()
if(NOT arg_TARGET_DESCRIPTION)
set(arg_TARGET_DESCRIPTION "C++ Application Development Framework")
endif()
if(NOT arg_TARGET_COMPANY)
set(arg_TARGET_COMPANY "The Qt Company Ltd.")
endif()
if(NOT arg_TARGET_COPYRIGHT)
set(arg_TARGET_COPYRIGHT "${QT_COPYRIGHT}")
endif()
set_target_properties(${target} PROPERTIES
QT_TARGET_VERSION "${arg_TARGET_VERSION}"
QT_TARGET_COMPANY_NAME "${arg_TARGET_COMPANY}"
QT_TARGET_DESCRIPTION "${arg_TARGET_DESCRIPTION}"
QT_TARGET_COPYRIGHT "${arg_TARGET_COPYRIGHT}"
QT_TARGET_PRODUCT_NAME "${arg_TARGET_PRODUCT}")
endfunction()
# Uses the QT_DELAYED_TARGET_* property values to set the final QT_TARGET_* properties.
# Needed when doing executable finalization at the end of a subdirectory scope
# (aka scope finalization).
function(qt_internal_set_target_info_properties_from_delayed_properties target)
set(args "")
foreach(prop ${__default_target_info_args})
get_target_property(prop_value "${target}" "QT_DELAYED_${prop}")
list(APPEND args "${prop}" "${prop_value}")
endforeach()
qt_set_target_info_properties(${target} ${args})
endfunction()
# Updates the QT_DELAYED_ properties with values from the QT_ variants, in case if they were
# set in-between a qt_add_* call and before scope finalization.
function(qt_internal_update_delayed_target_info_properties target)
foreach(prop ${__default_target_info_args})
get_target_property(prop_value "${target}" "QT_${prop}")
get_target_property(delayed_prop_value ${target} "QT_DELAYED_${prop}")
set(final_value "${delayed_prop_value}")
if(prop_value)
set(final_value "${prop_value}")
endif()
set_target_properties(${target} PROPERTIES "QT_DELAYED_${prop}" "${final_value}")
endforeach()
endfunction()
function(qt_internal_check_directory_or_type name dir type default result_var)
if ("x${dir}" STREQUAL x)
if("x${type}" STREQUAL x)
message(FATAL_ERROR
"qt_internal_add_plugin called without setting either PLUGIN_TYPE or ${name}.")
endif()
set(${result_var} "${default}" PARENT_SCOPE)
else()
set(${result_var} "${dir}" PARENT_SCOPE)
endif()
endfunction()
macro(qt_internal_get_export_additional_targets_keywords option_args single_args multi_args)
set(${option_args}
)
set(${single_args}
EXPORT_NAME_PREFIX
)
set(${multi_args}
TARGETS
TARGET_EXPORT_NAMES
)
endmacro()
# Create a Qt*AdditionalTargetInfo.cmake file that is included by Qt*Config.cmake
# and sets IMPORTED_*_<CONFIG> properties on the exported targets.
#
# The file also makes the targets global if the QT_PROMOTE_TO_GLOBAL_TARGETS property is set in the
# consuming project.
# When using a CMake version lower than 3.21, only the specified TARGETS are made global.
# E.g. transitive non-Qt 3rd party targets of the specified targets are not made global.
#
# EXPORT_NAME_PREFIX:
# The portion of the file name before AdditionalTargetInfo.cmake
# CONFIG_INSTALL_DIR:
# Installation location for the target info file
# TARGETS:
# The internal target names. Those must be actual targets.
# TARGET_EXPORT_NAMES:
# The target names how they appear in the QtXXXTargets.cmake files.
# The names get prefixed by ${QT_CMAKE_EXPORT_NAMESPACE}:: unless they already are.
# This argument may be empty, then the target export names are the same as the internal ones.
#
# TARGETS and TARGET_EXPORT_NAMES must contain exactly the same number of elements.
# Example: TARGETS = qmljs_native
# TARGET_EXPORT_NAMES = Qt6::qmljs
#
function(qt_internal_export_additional_targets_file)
qt_internal_get_export_additional_targets_keywords(option_args single_args multi_args)
cmake_parse_arguments(arg
"${option_args}"
"${single_args};CONFIG_INSTALL_DIR"
"${multi_args}"
${ARGN})
qt_internal_append_export_additional_targets()
set_property(GLOBAL APPEND PROPERTY _qt_export_additional_targets_ids "${id}")
set_property(GLOBAL APPEND
PROPERTY _qt_export_additional_targets_export_name_prefix_${id} "${arg_EXPORT_NAME_PREFIX}")
set_property(GLOBAL APPEND
PROPERTY _qt_export_additional_targets_config_install_dir_${id} "${arg_CONFIG_INSTALL_DIR}")
qt_add_list_file_finalizer(qt_internal_export_additional_targets_file_finalizer)
endfunction()
function(qt_internal_get_export_additional_targets_id export_name out_var)
string(MAKE_C_IDENTIFIER "${export_name}" id)
set(${out_var} "${id}" PARENT_SCOPE)
endfunction()
# Uses outer-scope variables to keep the implementation less verbose.
macro(qt_internal_append_export_additional_targets)
qt_internal_validate_export_additional_targets(
EXPORT_NAME_PREFIX "${arg_EXPORT_NAME_PREFIX}"
TARGETS ${arg_TARGETS}
TARGET_EXPORT_NAMES ${arg_TARGET_EXPORT_NAMES})
qt_internal_get_export_additional_targets_id("${arg_EXPORT_NAME_PREFIX}" id)
set_property(GLOBAL APPEND
PROPERTY _qt_export_additional_targets_${id} "${arg_TARGETS}")
set_property(GLOBAL APPEND
PROPERTY _qt_export_additional_target_export_names_${id} "${arg_TARGET_EXPORT_NAMES}")
endmacro()
# Can be called to add additional targets to the file after the initial setup call.
# Used for resources.
function(qt_internal_add_targets_to_additional_targets_export_file)
qt_internal_get_export_additional_targets_keywords(option_args single_args multi_args)
cmake_parse_arguments(arg
"${option_args}"
"${single_args}"
"${multi_args}"
${ARGN})
qt_internal_append_export_additional_targets()
endfunction()
function(qt_internal_validate_export_additional_targets)
qt_internal_get_export_additional_targets_keywords(option_args single_args multi_args)
cmake_parse_arguments(arg
"${option_args}"
"${single_args}"
"${multi_args}"
${ARGN})
if(NOT arg_EXPORT_NAME_PREFIX)
message(FATAL_ERROR "qt_internal_validate_export_additional_targets: "
"Missing EXPORT_NAME_PREFIX argument.")
endif()
list(LENGTH arg_TARGETS num_TARGETS)
list(LENGTH arg_TARGET_EXPORT_NAMES num_TARGET_EXPORT_NAMES)
if(num_TARGET_EXPORT_NAMES GREATER 0)
if(NOT num_TARGETS EQUAL num_TARGET_EXPORT_NAMES)
message(FATAL_ERROR "qt_internal_validate_export_additional_targets: "
"TARGET_EXPORT_NAMES is set but has ${num_TARGET_EXPORT_NAMES} elements while "
"TARGETS has ${num_TARGETS} elements. "
"They must contain the same number of elements.")
endif()
else()
set(arg_TARGET_EXPORT_NAMES ${arg_TARGETS})
endif()
set(arg_TARGETS "${arg_TARGETS}" PARENT_SCOPE)
set(arg_TARGET_EXPORT_NAMES "${arg_TARGET_EXPORT_NAMES}" PARENT_SCOPE)
endfunction()
# The finalizer might be called multiple times in the same scope, but only the first one will
# process all the ids.
function(qt_internal_export_additional_targets_file_finalizer)
get_property(ids GLOBAL PROPERTY _qt_export_additional_targets_ids)
foreach(id ${ids})
qt_internal_export_additional_targets_file_handler("${id}")
endforeach()
set_property(GLOBAL PROPERTY _qt_export_additional_targets_ids "")
endfunction()
function(qt_internal_export_additional_targets_file_handler id)
get_property(arg_EXPORT_NAME_PREFIX GLOBAL PROPERTY
_qt_export_additional_targets_export_name_prefix_${id})
get_property(arg_CONFIG_INSTALL_DIR GLOBAL PROPERTY
_qt_export_additional_targets_config_install_dir_${id})
get_property(arg_TARGETS GLOBAL PROPERTY
_qt_export_additional_targets_${id})
get_property(arg_TARGET_EXPORT_NAMES GLOBAL PROPERTY
_qt_export_additional_target_export_names_${id})
list(LENGTH arg_TARGETS num_TARGETS)
# Determine the release configurations we're currently building
if(QT_GENERATOR_IS_MULTI_CONFIG)
set(active_configurations ${CMAKE_CONFIGURATION_TYPES})
else()
set(active_configurations ${CMAKE_BUILD_TYPE})
endif()
unset(active_release_configurations)
foreach(config ${active_configurations})
string(TOUPPER ${config} ucconfig)
if(NOT ucconfig STREQUAL "DEBUG")
list(APPEND active_release_configurations ${config})
endif()
endforeach()
if(active_release_configurations)
# Use the first active release configuration as *the* release config for imported targets
# and for QT_DEFAULT_IMPORT_CONFIGURATION.
list(GET active_release_configurations 0 release_cfg)
string(TOUPPER ${release_cfg} uc_release_cfg)
set(uc_default_cfg ${uc_release_cfg})
# Determine the release configurations we do *not* build currently
set(configurations_to_export Release;RelWithDebInfo;MinSizeRel)
list(REMOVE_ITEM configurations_to_export ${active_configurations})
else()
# There are no active release configurations.
# Use the first active configuration for QT_DEFAULT_IMPORT_CONFIGURATION.
unset(uc_release_cfg)
list(GET active_configurations 0 default_cfg)
string(TOUPPER ${default_cfg} uc_default_cfg)
unset(configurations_to_export)
endif()
set(content "# Additional target information for ${arg_EXPORT_NAME_PREFIX}
if(NOT DEFINED QT_DEFAULT_IMPORT_CONFIGURATION)
set(QT_DEFAULT_IMPORT_CONFIGURATION ${uc_default_cfg})
endif()
")
math(EXPR n "${num_TARGETS} - 1")
foreach(i RANGE ${n})
list(GET arg_TARGETS ${i} target)
list(GET arg_TARGET_EXPORT_NAMES ${i} target_export_name)
set(full_target ${target_export_name})
if(NOT full_target MATCHES "^${QT_CMAKE_EXPORT_NAMESPACE}::")
string(PREPEND full_target "${QT_CMAKE_EXPORT_NAMESPACE}::")
endif()
# Tools are already made global unconditionally in QtFooToolsConfig.cmake.
# And the
get_target_property(target_type ${target} TYPE)
if(NOT target_type STREQUAL "EXECUTABLE")
string(APPEND content
"__qt_internal_promote_target_to_global_checked(${full_target})\n")
endif()
# INTERFACE libraries don't have IMPORTED_LOCATION-like properties.
# Skip the rest of the processing for those.
if(target_type STREQUAL "INTERFACE_LIBRARY")
continue()
endif()
set(properties_retrieved TRUE)
get_target_property(is_configure_time_target ${target} _qt_internal_configure_time_target)
if(is_configure_time_target)
# For Multi-config developer builds we should simply reuse IMPORTED_LOCATION of the
# target.
if(NOT QT_WILL_INSTALL AND QT_FEATURE_debug_and_release)
set(configure_time_target_build_location "")
get_target_property(configure_time_target_install_location ${target}
IMPORTED_LOCATION)
else()
if(IS_ABSOLUTE "${arg_CONFIG_INSTALL_DIR}")
file(RELATIVE_PATH reverse_relative_prefix_path
"${arg_CONFIG_INSTALL_DIR}" "${CMAKE_INSTALL_PREFIX}")
else()
file(RELATIVE_PATH reverse_relative_prefix_path
"${CMAKE_INSTALL_PREFIX}/${arg_CONFIG_INSTALL_DIR}"
"${CMAKE_INSTALL_PREFIX}")
endif()
get_target_property(configure_time_target_build_location ${target}
_qt_internal_configure_time_target_build_location)
string(TOUPPER "${QT_CMAKE_EXPORT_NAMESPACE}_INSTALL_PREFIX" install_prefix_var)
string(JOIN "" configure_time_target_build_location
"$\{CMAKE_CURRENT_LIST_DIR}/"
"${reverse_relative_prefix_path}"
"${configure_time_target_build_location}")
get_target_property(configure_time_target_install_location ${target}
_qt_internal_configure_time_target_install_location)
string(JOIN "" configure_time_target_install_location
"$\{CMAKE_CURRENT_LIST_DIR}/"
"${reverse_relative_prefix_path}"
"${configure_time_target_install_location}")
endif()
if(configure_time_target_install_location)
string(APPEND content "
# Import configure-time executable ${full_target}
if(NOT TARGET ${full_target})
set(_qt_imported_build_location \"${configure_time_target_build_location}\")
set(_qt_imported_install_location \"${configure_time_target_install_location}\")
set(_qt_imported_location \"\${_qt_imported_install_location}\")
if(NOT EXISTS \"$\{_qt_imported_location}\"
AND NOT \"$\{_qt_imported_build_location}\" STREQUAL \"\")
set(_qt_imported_location \"\${_qt_imported_build_location}\")
endif()
if(NOT EXISTS \"$\{_qt_imported_location}\")
message(FATAL_ERROR \"Unable to add configure time executable ${full_target}\"
\" $\{_qt_imported_location} doesn't exists\")
endif()
add_executable(${full_target} IMPORTED)
set_property(TARGET ${full_target} APPEND PROPERTY IMPORTED_CONFIGURATIONS ${default_cfg})
set_target_properties(${full_target} PROPERTIES IMPORTED_LOCATION_${uc_default_cfg}
\"$\{_qt_imported_location}\")
set_property(TARGET ${full_target} PROPERTY IMPORTED_GLOBAL TRUE)
unset(_qt_imported_location)
unset(_qt_imported_build_location)
unset(_qt_imported_install_location)
endif()
\n")
endif()
endif()
# Non-prefix debug-and-release builds: add check for the existence of the debug binary of
# the target. It is not built by default.
if(NOT QT_WILL_INSTALL AND QT_FEATURE_debug_and_release)
get_target_property(excluded_genex ${target} EXCLUDE_FROM_ALL)
if(excluded_genex)
string(APPEND content "
# ${full_target} is not built by default in the Debug configuration. Check existence.
get_target_property(_qt_imported_location ${full_target} IMPORTED_LOCATION_DEBUG)
if(NOT EXISTS \"$\{_qt_imported_location}\")
get_target_property(_qt_imported_configs ${full_target} IMPORTED_CONFIGURATIONS)
list(REMOVE_ITEM _qt_imported_configs DEBUG)
set_property(TARGET ${full_target} PROPERTY IMPORTED_CONFIGURATIONS $\{_qt_imported_configs})
set_property(TARGET ${full_target} PROPERTY IMPORTED_LOCATION_DEBUG)
endif()\n")
endif()
endif()
set(write_implib FALSE)
set(write_soname FALSE)
set(write_objects FALSE)
set(write_link_dependencies FALSE)
set(write_location TRUE)
if(target_type STREQUAL "SHARED_LIBRARY")
if(WIN32)