summaryrefslogtreecommitdiff
path: root/Tools/qmake/mkspecs/features/functions.prf
blob: a086e769bba66939829c86afa46dd56bec5593bd (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
# -------------------------------------------------------------------
# This file defines a few useful functions that are exposed to the
# real project files.
#
# See 'Tools/qmake/README' for an overview of the build system
# -------------------------------------------------------------------

defineReplace(toSanitizedPath) {
    path = $$1
    win32-msvc* {
        components = $$split(path, :)
        count(components, 2): path = $$lower($$first(components)):$$last(components)
        return($$replace(path, \\\\, /))
    } else {
        return($$path)
    }
}

defineReplace(toSystemPath) {
    return($$replace(1, [/\\\\], $${QMAKE_DIR_SEP}))
}

defineReplace(toEvaluatablePath) {
    return($$replace(1, \\\\, \\\\\\\\))
}

defineReplace(activeBuildConfig) {
    CONFIG(debug, debug|release): return(debug)
    else: return(release)
}

defineReplace(computeSubdirVariables) {
    unset(subdir)
    subdir = $$1

    scope = $$subdir
    path = $$eval($${subdir}.file)
    isEmpty(path): path = $$eval($${subdir}.subdir)
    isEmpty(path) {
        path = $${subdir}
        # We can't use scope as a variable scope, so unset it for
        # now and we'll compute a new scope based on the target.
        unset(scope)
    }

    # Technically this could be a directory, but we assume sane naming.
    is_file = $$find(path, \\.pr[io]$)
    isEmpty(is_file) {
        subdirectory = $$path
    } else {
        subdirectory = $$dirname(path)
        filename = $$basename(path)
    }

    # Make directory relative
    !isEmpty(subdirectory):subdirectory = $$replace(subdirectory, ^$${_PRO_FILE_PWD_}/,)

    !isEmpty(subdirectory) {
        subdir_command = cd $$toSystemPath($${subdirectory}$${QMAKE_DIR_SEP}) &&
    }

    target = $$eval($${subdir}.target)
    isEmpty(target) {
        sanitizedPath = $$toSanitizedPath($$path)
        target = sub-$$replace(sanitizedPath, [^a-zA-Z0-9_], -)
    }

    isEmpty(scope): scope = $$target

    makefile = $$eval($${subdir}.makefile)
    isEmpty(makefile) {
        !isEmpty(filename) {
            filebase = $$replace(filename, \\..*$,)
            dirbase = $$basename(subdirectory)
            !equals(filebase, $$dirbase) {
                makefile = $(MAKEFILE).$$filebase
            } else {
                makefile = $(MAKEFILE)
            }
        } else {
            makefile = $(MAKEFILE)
        }
    }

    subdir_command = $$toEvaluatablePath($$subdir_command)
    eval($${scope}.subdir_command = $$subdir_command)
    export($${scope}.subdir_command)

    eval($${scope}.target = $$target)
    export($${scope}.target)

    eval($${scope}.makefile = $$makefile)
    export($${scope}.makefile)

    return($$scope)
}

# Qmake has QMAKE_FILE_IN_PATH, but nothing for the out file
# This allows you do do ${QMAKE_FUNC_FILE_OUT_PATH}
defineReplace(PATH) {
    return($$dirname(1))
}

# We need both versions, in case the first one returns an empty string
defineReplace(FILE_OUT_PATH) {
    return($$dirname(2))
}

# addStrictSubdirOrderBetween(firstSubdir, secondSubdir)
defineTest(addStrictSubdirOrderBetween) {
    unset(firstSubdir)
    unset(secondSubdir)

    firstSubdir = $$1
    secondSubdir = $$2

    firstVariables = $$computeSubdirVariables($${firstSubdir})
    secondVariables = $$computeSubdirVariables($${secondSubdir})

    !contains(TEMPLATE, subdirs) {
        error("Strict subdir dependencies can only be used with subdirs template")
    }

    firstSubdirFile = $$eval($${firstSubdir}.file)
    secondSubdirFile = $$eval($${secondSubdir}.file)

    isEmpty(firstSubdirFile)|isEmpty(secondSubdirFile) {
        error("Missing subdir file ($$firstSubdirFile, $$secondSubdirFile)")
    }

    # Make sure the order is right
    SUBDIRS -= $$firstSubdir $$secondSubdir
    SUBDIRS += $$firstSubdir $$secondSubdir
    NO_RECURSIVE_QMAKE_SUBDIRS += $$firstSubdir $$secondSubdir
    CONFIG *= ordered

    first_base_target = sub-$$replace(firstSubdirFile, [^a-zA-Z0-9_], -)
    second_base_target = sub-$$replace(secondSubdirFile, [^a-zA-Z0-9_], -)

    haveQt(4) {
        # Use a custom target for making the derived sources instead of the default ones,
        # as the default ones depend on $(MAKEFILE), while we want to depend on *qmake_all.
        # Without this rule we end up running qmake twice for the derived sources, as well as
        # introducing a race condition where we run "qmake -o Makefile.DerivedSources" at the
        # same time as we run "make -f Makefile.DerivedSources", resulting in make reading a
        # half-written makefile.
        derived_make_for_qmake.target = $${first_base_target}-make_for_qmake
        derived_make_for_qmake.depends = $${first_base_target}-qmake_all
        derived_make_for_qmake.commands = $(MAKE) -f $$eval($${firstSubdir}.makefile)
        QMAKE_EXTRA_TARGETS += derived_make_for_qmake

        # This target ensures that running "make qmake" will force both qmake and make
        # to be run on the derived sources before running qmake on the target, so that
        # qmake can pick up the right dependencies for the target based on the derived
        # sources that were generated.
        target_make_qmake.target = $${second_base_target}-qmake_all
        target_make_qmake.depends = $${derived_make_for_qmake.target}
        QMAKE_EXTRA_TARGETS += target_make_qmake

        GNUmake {
            # This target ensures that running make before any makefiles have been created
            # will still force qmake and make to be run on the derived sources first.
            target_make.target = $$eval($${secondSubdir}.makefile)

            # We use order-only-prerequisites so that we can run make on the derived sources
            # without triggering a qmake run on the target due to updated dependencies.
            target_make.depends = "| $${first_base_target}-make_default-ordered"

            QMAKE_EXTRA_TARGETS += target_make
        }
    } else {
        # Qt5's qmake does most of the above for us already.

        # This target ensures that running "make qmake_all" will force both qmake and make
        # to be run on the derived sources before running qmake on the target, so that
        # qmake can pick up the right dependencies for the target based on the derived
        # sources that were generated. Just "make qmake" is non-recursive anyway.
        target_make_qmake.target = $${second_base_target}-qmake_all
        target_make_qmake.depends = $${first_base_target}
        QMAKE_EXTRA_TARGETS += target_make_qmake

        # Make things work even if qmake -r is used.
        CONFIG += dont_recurse
    }

    export(SUBDIRS)
    export(NO_RECURSIVE_QMAKE_SUBDIRS)
    export(CONFIG)
    export(target_make_qmake.target)
    export(target_make_qmake.depends)
    export(derived_make_for_qmake.target)
    export(derived_make_for_qmake.depends)
    export(derived_make_for_qmake.commands)
    export(target_make.target)
    export(target_make.depends)
    export(QMAKE_EXTRA_TARGETS)
    return(true)
}

# Check if we have the given Qt version. The major version needs
# to be exact, the minor and patch version is same or higher
defineTest(haveQt) {
    count(ARGS, 1, lessThan)|count(ARGS, 3, greaterThan) {
        error("Unexpected number of arguments: haveQt($$ARGS)")
    }

    !equals(QT_MAJOR_VERSION, $$1): return(false)

    count(ARGS, 1, greaterThan) {
        lessThan(QT_MINOR_VERSION, $$2): return(false)
        greaterThan(QT_MINOR_VERSION, $$2): return(true)

        count(ARGS, 2, greaterThan) {
            lessThan(QT_PATCH_VERSION, $$3): return(false)
            greaterThan(QT_PATCH_VERSION, $$3): return(true)
        }
    }

    return(true)
}

defineTest(haveQtModule) {
    unset(module)
    module = $$1

    haveQt(4):contains(QT_CONFIG, $${module}): return(true)
    haveQt(5):!isEmpty(QT.$${module}.name): return(true)
    return(false)
}

defineTest(prependEach) {
    unset(variable)
    unset(prefix)

    variable = $$1
    prefix = $$2

    original_values = $$unique($$variable)

    for(value, original_values) {
        values += $${prefix}$${value}
    }

    eval($$variable = $$values)
    export($$variable)

    return(true)
}

defineReplace(resolveFinalLibraryName) {
    !debug_and_release: return($$1)

    original_framework_name = $$QMAKE_FRAMEWORK_BUNDLE_NAME

    TEMPLATE = lib # So that qtLibraryTarget works
    target = $$qtLibraryTarget($$1)

    # qtLibraryTarget will export QMAKE_FRAMEWORK_BUNDLE_NAME, which gets
    # exported not only to this function scope, but to our call site.
    QMAKE_FRAMEWORK_BUNDLE_NAME = $$original_framework_name
    export(QMAKE_FRAMEWORK_BUNDLE_NAME)

    return($$target)
}

defineTest(linkAgainstLibrary) {
    unset(target)
    target = $$1

    unset(source_dir)
    source_dir = $$2

    library = $$lower($$target)

    target = $$resolveFinalLibraryName($$target)

    path = $$replace(source_dir, $${ROOT_WEBKIT_DIR}, $${ROOT_BUILD_DIR})/$$activeBuildConfig()

    force_static_libs_as_shared {
            LIBS += -L$${ROOT_BUILD_DIR}/lib -l$$target
    } else {

        mac {
            LIBS += -Wl,-force_load,$${path}$${QMAKE_DIR_SEP}lib$${target}.a
        } else:win32-msvc*|wince*|win32-icc {
            LIBS += /OPT:REF -l$$target
        } else {
            LIBS += -Wl,-whole-archive -l$$target -Wl,-no-whole-archive
        }

        win32-msvc*|wince*|win32-icc {
            LIBS += -L$$path
            POST_TARGETDEPS += $${path}$${QMAKE_DIR_SEP}$${target}.lib
        } else {
            QMAKE_LIBDIR += $$path
            POST_TARGETDEPS += $${path}$${QMAKE_DIR_SEP}lib$${target}.a
        }

        # The following line is to prevent qmake from adding jscore to libQtWebKit's prl dependencies.
        # The compromise we have to accept by disabling explicitlib is to drop support to link QtWebKit
        # statically in applications (which isn't used often because, among other things, of licensing obstacles).
        CONFIG -= explicitlib
        CONFIG -= staticlib
    }

    export(LIBS)
    export(QMAKE_LIBDIR)
    export(POST_TARGETDEPS)
    export(CONFIG)
    return(true)
}

defineTest(runSyncQt) {

    build_pass:return(true)

    haveQt(5) {
        # Qt 5 will run synqt as part of defaults_pre, so no need to do anything
    } else {
        # Use our own copy of syncqt from Qt 4.8 to generate forwarding headers
        syncqt = $$toSystemPath($${ROOT_WEBKIT_DIR}/Tools/qmake/syncqt-4.8)
        command = $$syncqt
        win32-msvc*: command = $$command -windows

        outdir = $$toSystemPath($${ROOT_BUILD_DIR})

        # The module root has to be the same as directory of the pro-file that generates
        # the install rules (api.pri), otherwise the relative paths in the generated
        # headers.pri will be incorrect.
        module_rootdir = $$toSystemPath($${_PRO_FILE_PWD_})

        module = $${TARGET}$${DIRLIST_SEPARATOR}$${module_rootdir}$${DIRLIST_SEPARATOR}$$toSystemPath(WebKit/qt/Api)
        command = perl $${command} -outdir $${outdir} -separate-module $${module}
        message(Running $$command)
        !system($$command) {
            error(Failed to run $${command})
        }
    }

    return(true)
}

defineTest(xlibAvailable) {
    haveQt(5) {
        contains(QT_CONFIG, xcb-xlib) {
            return(true)
        } else {
            return(false)
        }
    } else {
        unix:!mac:!embedded {
            return(true)
        } else {
            return(false)
        }
    }
}