summaryrefslogtreecommitdiffstats
path: root/mkspecs/features/qt.prf
blob: 3b71eea6bc60033f880d1eae7b6918b0e4413d7d (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
# This avoids spurious errors when a project is explicitly disabled
# due to required Qt modules being missing.
!isEmpty(QMAKE_FAILED_REQUIREMENTS): return()

# hardcoded defaults
QT_CONFIG *= c99 c11 c++11 c++14 c++1z c++17

qtConfig(thread): CONFIG *= thread

#handle defines
win32 {
   qtConfig(shared) {
      # this variable is read by qmake in qmake/generators/win32/msvc_vcproj.cpp
      # function VcprojGenerator::initDeploymentTool()
      QMAKE_DLL_PATHS += $$[QT_INSTALL_BINS/get]
   }
}
CONFIG(release, debug|release):DEFINES += QT_NO_DEBUG
no_keywords:DEFINES += QT_NO_KEYWORDS
plugin { #Qt plugins
   static:DEFINES += QT_STATICPLUGIN
   DEFINES += QT_PLUGIN
}

qtestlib {
    warning("CONFIG+=qtestlib is deprecated. Use QT+=testlib instead.")
    QT += testlib
}
qdbus {
    warning("CONFIG+=qdbus is deprecated. Use QT+=dbus instead.")
    QT += dbus
}
help {
    warning("CONFIG+=help is deprecated. Use QT+=help instead.")
    QT += help-private   # sic!
}
designer {
    warning("CONFIG+=designer is deprecated. Use QT+=designer instead.")
    QT += designer
}
uitools {
    warning("CONFIG+=uitools is deprecated. Use QT+=uitools instead.")
    QT += uitools
}
qaxcontainer {
    warning("CONFIG+=qaxcontainer is deprecated. Use QT+=axcontainer instead.")
    QT += axcontainer
}
qaxserver {
    warning("CONFIG+=qaxserver is deprecated. Use QT+=axserver instead.")
    QT += axserver
}

!import_qpa_plugin {
    warning("CONFIG-=import_qpa_plugin is deprecated. Use QTPLUGIN.platforms=- instead.")
    QTPLUGIN.platforms = -
} else: qpa_minimal_plugin {
    warning("CONFIG+=qpa_minimal_plugin is deprecated. Use QTPLUGIN.platforms=qminimal instead.")
    QTPLUGIN.platforms = qminimal
}

!force_import_plugins:!contains(TEMPLATE, ".*app"):!if(contains(TEMPLATE, ".*lib"):dll): \
    CONFIG -= import_plugins
unix {
    contains(QT_CONFIG, no_direct_extern_access): CONFIG += no_direct_extern_access
    else:contains(QT_CONFIG, reduce_relocations):!contains(TEMPLATE, .*lib): {
        QMAKE_CFLAGS += $$QMAKE_CFLAGS_PIC
        QMAKE_CXXFLAGS += $$QMAKE_CFLAGS_PIC
    }
}

# Load the entrypoint module if requested
entrypoint {
    win32 {
        !console:contains(TEMPLATE, ".*app"): \
            QT_PRIVATE += entrypoint_private
    } else:uikit {
        qt_depends = $$resolve_depends(QT, "QT.")
        !watchos:equals(TEMPLATE, app):contains(qt_depends, gui(-private)?): \
            QT_PRIVATE += entrypoint_private
    }
}

# Will automatically add plugins, so run first
contains(QT_CONFIG, permissions): load(permissions)

# qmake variables cannot contain dashes, so normalize the names first
CLEAN_QT = $$replace(QT, -private$, _private)
CLEAN_QT_PRIVATE = $$replace(QT_PRIVATE, -private$, _private)

qt_module_deps = $$CLEAN_QT $$CLEAN_QT_PRIVATE
all_qt_module_deps = $$resolve_depends(qt_module_deps, "QT.", ".depends" ".run_depends")

QTPLUGIN = $$unique($$list($$lower($$QTPLUGIN)))

# Sanitize requested plugins, and add any default plugins
import_plugins {
    manualplugs = $$QTPLUGIN  # User may specify plugins. Mostly legacy.
    autoplugs =  # Auto-added plugins.
    # First round: explicitly specified modules.
    all_plugin_deps = $$all_qt_module_deps
    plugin_deps = $$all_plugin_deps
    for(ever) {
        # Automatically add the default plugins for the linked Qt modules.
        for (qtmod, plugin_deps) {
            for (ptype, QT.$${qtmod}.plugin_types) {
                nptype = $$replace(ptype, [-/], _)
                isEmpty(QTPLUGIN.$$nptype) {
                    for (plug, QT_PLUGINS) {
                        equals(QT_PLUGIN.$${plug}.TYPE, $$ptype) {
                            for (dep, QT_PLUGIN.$${plug}.EXTENDS) {
                                !contains(all_plugin_deps, $$dep) {
                                    plug =
                                    break()
                                }
                            }
                            autoplugs += $$plug
                        }
                    }
                } else {
                    plug = $$eval(QTPLUGIN.$$nptype)
                    !equals(plug, -): \
                        autoplugs += $$plug
                }
            }
        }
        QTPLUGIN = $$manualplugs $$autoplugs
        QTPLUGIN = $$unique(QTPLUGIN)

        # Obtain the plugins' Qt dependencies ...
        plugin_deps =
        for (plug, QTPLUGIN): \
            plugin_deps += $$eval(QT_PLUGIN.$${plug}.DEPENDS)
        plugin_deps = $$resolve_depends(plugin_deps, "QT.", ".depends" ".run_depends")
        plugin_deps -= $$all_plugin_deps

        isEmpty(plugin_deps): \
            break()
        # ... and start over if any new Qt modules appeared,
        # as these may want to load plugins in turn.
        all_plugin_deps += $$plugin_deps
    }
    extraplugs = $$manualplugs
    manualplugs -= $$autoplugs
    extraplugs -= $$manualplugs
    !isEmpty(extraplugs): \
        warning("Redundant entries in QTPLUGIN: $$extraplugs")
}

# Link static plugins
!isEmpty(QTPLUGIN) {
    for (plug, QTPLUGIN) {
        module_config = $$eval(QT_PLUGIN.$${plug}.module_config)
        isEmpty(module_config):!qtConfig(static): \
            next() # Compatibility with older modules

        !contains(module_config, staticlib): \
            next()

        plug_class = $$eval(QT_PLUGIN.$${plug}.CLASS_NAME)
        !isEmpty(plug_class): \
            IMPORT_FILE_CONT += "Q_IMPORT_PLUGIN($$plug_class)"
        else: \
            warning("Plugin class name could not be determined for plugin '$$plug'.")

        plugin_deps = $$eval(QT_PLUGIN.$${plug}.DEPENDS)
        plugin_deps = $$resolve_depends(plugin_deps, "QT.", ".depends" ".run_depends")
        all_qt_module_deps *= $$plugin_deps

        # Check if the plugin is known to Qt. We can use this to determine
        # the plugin path. Unknown plugins must rely on the default link path.
        plug_type = $$eval(QT_PLUGIN.$${plug}.TYPE)
        !isEmpty(plug_type) {
            # Respect target config if Qt provides both debug and release versions
            # of each plugin. Otherwise, respect what Qt was configured with.
            qtConfig(debug_and_release): config_variable = CONFIG
            else: config_variable = QT_CONFIG

            plug_name = $$QMAKE_PREFIX_STATICLIB$${plug}$$qtPlatformTargetSuffix($$config_variable).$$QMAKE_EXTENSION_STATICLIB
            plug_path = $$eval(QT_PLUGIN.$${plug}.PATH)
            isEmpty(plug_path): \
                plug_path = $$[QT_INSTALL_PLUGINS/get]
            LIBS += $$plug_path/$$plug_type/$$plug_name
        } else {
            LIBS += -l$${plug}$$qtPlatformTargetSuffix(CONFIG)
        }
    }

    !isEmpty(IMPORT_FILE_CONT) {
        IMPORT_FILE_CONT = \
            "// This file is autogenerated by qmake. It imports static plugin classes for" \
            "// static plugins specified using QTPLUGIN and QT_PLUGIN_CLASS.<plugin> variables." \
            "$${LITERAL_HASH}include <QtPlugin>" \
            "$$IMPORT_FILE_CONT"

        TARGET_BASENAME = $$lower($$basename(TARGET))
        TARGET_BASENAME ~= s/\s/_/g
        IMPORT_CPP = $$OUT_PWD/$${TARGET_BASENAME}_plugin_import.cpp
        write_file($$IMPORT_CPP, IMPORT_FILE_CONT)|error()
        GENERATED_SOURCES += $$IMPORT_CPP
        QMAKE_DISTCLEAN += $$IMPORT_CPP
    }
}

# target variable, flag source variable
defineTest(qtProcessModuleFlags) {
    for(flag, $$2) {
        contains(flag, ^-.*): \
            $$1 -= $$replace(flag, ^-, )
        else: \
            $$1 += $$flag
    }
    export($$1)
}

unset(using_private_headers)
var_sfx =
for(ever) {
    # Topological resolution of modules based on their QT.<module>.depends variable
    FULL_QT$$var_sfx = $$resolve_depends(CLEAN_QT$$var_sfx, "QT.")
    # Finally actually add the modules
    unset(BAD_QT)
    for(QTLIB, FULL_QT$$var_sfx) {
        MODULE_NAME = $$eval(QT.$${QTLIB}.name)
        MODULE_MODULE = $$eval(QT.$${QTLIB}.module)
        MODULE_INCLUDES = $$eval(QT.$${QTLIB}.includes)
        MODULE_LDFLAGS = $$eval(QT.$${QTLIB}.ldflags)
        MODULE_LIBS = $$eval(QT.$${QTLIB}.libs)
        MODULE_FRAMEWORKS = $$eval(QT.$${QTLIB}.frameworks)
        MODULE_USES = $$eval(QT.$${QTLIB}.uses)
        MODULE_CONFIG = $$eval(QT.$${QTLIB}.module_config)

        isEmpty(MODULE_NAME) {
            BAD_QT += $$QTLIB
            next()
        }

        contains(MODULE_CONFIG, internal_module):!isEmpty(MODULE_INCLUDES): \
            using_private_headers = true
        contains(MODULE_CONFIG, ltcg): \
            CONFIG += link_ltcg

        qtProcessModuleFlags(CONFIG, QT.$${QTLIB}.CONFIG)
        qtProcessModuleFlags(DEFINES, QT.$${QTLIB}.DEFINES)

        MODULE_INCLUDES -= $$QMAKE_DEFAULT_INCDIRS

        # Add linker flags before lib
        LIBS$$var_sfx += $$MODULE_LDFLAGS

        # Frameworks shouldn't need include paths, but much code does not use
        # module-qualified #includes, so by default we add paths which point
        # directly into the frameworks. Private modules have somewhat convoluted
        # header paths, so adding them is necessary in every case.
        !if(contains(MODULE_CONFIG, lib_bundle):qt_no_framework_direct_includes) \
                |contains(MODULE_CONFIG, internal_module): \
            INCLUDEPATH *= $$MODULE_INCLUDES
        QMAKE_FRAMEWORKPATH *= $$MODULE_FRAMEWORKS
        !isEmpty(MODULE_MODULE) {
            contains(MODULE_CONFIG, lib_bundle) {
                framework = $$MODULE_MODULE
                # Linking frameworks by absolute path does not work.
                LIBS$$var_sfx += -framework $$framework
            } else {
                lib_bases = $$MODULE_MODULE$$qtPlatformTargetSuffix()
                darwin: lib_bases *= $$MODULE_MODULE
                add_lib_to_pretargetdeps = false
                win32|contains(MODULE_CONFIG, staticlib) {
                    lib_prefix = $$MODULE_LIBS/$$QMAKE_PREFIX_STATICLIB
                    lib_suffixes = $$QMAKE_EXTENSION_STATICLIB
                    lib_suffixes *= $$QMAKE_LIB_EXTENSIONS
                    !xcodebuild: \
                        add_lib_to_pretargetdeps = true
                } else {
                    lib_prefix = $$MODULE_LIBS/$$QMAKE_PREFIX_SHLIB
                    lib_suffixes = $$QMAKE_EXTENSION_SHLIB
                }
                candidates =
                for(lib_base, lib_bases) {
                    for(lib_suffix, lib_suffixes) {
                        candidates += $${lib_prefix}$${lib_base}.$${lib_suffix}
                    }
                }
                lib =
                for(candidate, candidates) {
                    exists("$$candidate") {
                        lib = "$$candidate"
                        break()
                    }
                }
                isEmpty(lib): \
                    lib = $$first(candidates)
                $$add_lib_to_pretargetdeps: \
                    PRE_TARGETDEPS += $$lib
                LIBS$$var_sfx += $$lib
            }
        }
        QMAKE_USE$$var_sfx += $$MODULE_USES
    }
    !isEmpty(BAD_QT):error("Unknown module(s) in QT$$var_sfx: $$replace(BAD_QT, _private$, -private)")

    !isEmpty(var_sfx): break()
    var_sfx = _PRIVATE
}
!isEmpty(using_private_headers):!no_private_qt_headers_warning:!build_pass {
    message("This project is using private headers and will therefore be tied to this specific Qt module build version.")
    message("Running this project against other versions of the Qt modules may crash at any arbitrary point.")
    message("This is not a bug, but a result of using Qt internals. You have been warned!")
}

!no_qt_rpath:!static:qtConfig(rpath):!qtConfig(static):\
        contains(all_qt_module_deps, core) {
    relative_qt_rpath:!isEmpty(QMAKE_REL_RPATH_BASE):contains(INSTALLS, target):\
            isEmpty(target.files):isEmpty(target.commands):isEmpty(target.extra) {
        # NOT the /dev property, as INSTALLS use host paths
        QMAKE_RPATHDIR += $$relative_path($$[QT_INSTALL_LIBS], $$qtRelativeRPathBase())
    } else {
        QMAKE_RPATHDIR += $$[QT_INSTALL_LIBS/dev]
    }
}

!isEmpty(QMAKE_LFLAGS_RPATHLINK):!qtConfig(static) {
    # -rpath-link is used by the linker to find dependencies of dynamic
    # libraries which were NOT specified on the command line.
    # This means that paths of direct dependencies (QT & QT_PRIVATE)
    # don't need to be listed, unlike their private dependencies' paths.
    privdep = $$all_qt_module_deps
    privdep -= $$resolve_depends(qt_module_deps, "QT.")
    rpaths =
    for(dep, privdep): \
        rpaths += $$eval(QT.$${dep}.libs)
    QMAKE_RPATHLINKDIR *= $$unique(rpaths)
}

# static builds: link qml import plugins into the target.
contains(all_qt_module_deps, qml): \
        qtConfig(static):import_plugins:!host_build:!no_import_scan {
    exists($$[QT_INSTALL_QML/get]): \
        QMLPATHS *= $$[QT_INSTALL_QML/get]

    # run qmlimportscanner
    qtPrepareLibExecTool(QMLIMPORTSCANNER, qmlimportscanner, , system)
    for (QMLPATH, QMLPATHS): \
        IMPORTPATHS += -importPath $$system_quote($$QMLPATH)

    # add resources to qmlimportscanner
    for (RESOURCE, RESOURCES) {
        defined($${RESOURCE}.files, var) {
            # in case of a "struct", add the struct's files
            base = $$RESOURCE.base
            for (f, $$RESOURCE.files): SCANNERRESOURCES += "$$base/$$f"
        } else {
            # if the resource is a file, just add it
            SCANNERRESOURCES += $$RESOURCE
        }
    }

    !isEmpty(SCANNERRESOURCES) {
        IMPORTPATHS += -qrcFiles
        for (RESOURCE, SCANNERRESOURCES): \
            IMPORTPATHS += $$absolute_path($$system_quote($$RESOURCE), $$_PRO_FILE_PWD_)
    }


    # message(run $$QMLIMPORTSCANNER $$_PRO_FILE_PWD_  $$IMPORTPATHS)
    JSON = $$system($$QMLIMPORTSCANNER $$system_quote($$_PRO_FILE_PWD_) $$IMPORTPATHS)

    parseJson(JSON, IMPORTS)| error("Failed to parse qmlimportscanner output.")

    !isEmpty(IMPORTS._KEYS_) {
        # add import plugins to LIBS line
        for (key, IMPORTS._KEYS_) {
            PATH = $$eval(IMPORTS.$${key}.path)
            PLUGIN = $$eval(IMPORTS.$${key}.plugin)
            !isEmpty(PATH):!isEmpty(PLUGIN): \
                LIBS += $$PATH/$$QMAKE_PREFIX_STATICLIB$${PLUGIN}$$qtPlatformTargetSuffix().$$QMAKE_EXTENSION_STATICLIB
        }

        # create qml_plugin_import.cpp
        IMPORT_FILE_CONT = \
            "// This file is autogenerated by qmake. It imports static plugin classes for" \
            "// static plugins used by QML imports." \
            "$${LITERAL_HASH}include <QtPlugin>"
        for (key, IMPORTS._KEYS_) {
            PLUGIN = $$eval(IMPORTS.$${key}.plugin)
            CLASSNAME = $$eval(IMPORTS.$${key}.classname)
            !isEmpty(PLUGIN) {
                !isEmpty(CLASSNAME) {
                    !contains(ADDED_IMPORTS, $$PLUGIN)  {
                        ADDED_IMPORTS += $$PLUGIN
                        IMPORT_FILE_CONT += "Q_IMPORT_PLUGIN($$CLASSNAME)"
                    }
                } else {
                    error("Plugin $$PLUGIN is missing a classname entry, please add one to the qmldir file.")
                }
            }
        }
        TARGET_BASENAME = $$lower($$basename(TARGET))
        TARGET_BASENAME ~= s/\s/_/g

        QML_IMPORT_CPP = $$OUT_PWD/$${TARGET_BASENAME}_qml_plugin_import.cpp
        write_file($$QML_IMPORT_CPP, IMPORT_FILE_CONT)|error()
        GENERATED_SOURCES += $$QML_IMPORT_CPP
        QMAKE_DISTCLEAN += $$QML_IMPORT_CPP
    }
}