summaryrefslogtreecommitdiffstats
path: root/Tools/qmake/mkspecs/features/functions.prf
blob: 2f5b87c7cb69d369243c214ec57f7c5cf55d94ff (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
# -------------------------------------------------------------------
# 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*|wince* {
        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(targetSubDir) {
    # The paths to the elements of the thin archive are stored
    # relative to the archive itself, thus we have to prevent
    # qmake from moving the archive after creation.
    gnu_thin_archives: return()
    else: 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, ^$$re_escape($${_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 -= $$secondSubdir
    SUBDIRS += $$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_], -)

    # Use a custom target for making the derived sources, as the default target
    # will do 'test -f $(MAKEFILE).DerivedSources || $(QMAKE) ...', which clashes
    # with the qmake-run of the -qmake_all target, and we end up with a race
    # and potentially half-written makefiles. The custom target depends explicitly
    # on -qmake_all, to ensure that we have a makefile, and then calls make.
    derived_make_for_qmake = $${first_base_target}-make_for_qmake
    eval($${derived_make_for_qmake}.depends = $${first_base_target}-qmake_all)
    eval($${derived_make_for_qmake}.commands = $(MAKE) -f $$eval($${firstSubdir}.makefile))
    QMAKE_EXTRA_TARGETS += $${derived_make_for_qmake}

    # 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.
    target_make_qmake = $${second_base_target}-qmake_all
    eval($${target_make_qmake}.depends = $${derived_make_for_qmake})
    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}.depends)
    export($${derived_make_for_qmake}.commands)
    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(programExistsInPath) {
    equals(QMAKE_HOST.os, Windows): program = $${1}.exe
    else: program = $$1

    PATH = "$$(PATH)"
    paths=$$split(PATH, $$QMAKE_DIRLIST_SEP)

    GNUTOOLS_DIR=$$[QT_HOST_DATA]/../gnuwin32/bin
    exists($$GNUTOOLS_DIR): paths += $$GNUTOOLS_DIR

    for(p, paths): exists($$p/$$program):return(true)
    return(false)
}

defineTest(addReasonForSkippingBuild) {
    skipBuildReason = "$$skipBuildReason$${EOL}    * $$1"
    export(skipBuildReason)
}

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, $$re_escape($${ROOT_WEBKIT_DIR}), $${ROOT_BUILD_DIR})/$$targetSubDir()

    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 += -l$$target
            QMAKE_LFLAGS += /OPT:REF
        } else {
            CONFIG *= no_smart_library_merge
            LIBS += -Wl,-whole-archive -l$$target -Wl,-no-whole-archive
        }

        LIBS += -L$$path

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

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

defineTest(xlibAvailable) {
    qtConfig(xcb):qtConfig(xcb-xlib) {
        return(true)
    } else {
        return(false)
    }
}

defineTest(build?) {
    contains(WEBKIT_CONFIG, build_$$lower($$1)): return(true)
    return(false)
}

defineTest(have?) {
    contains(WEBKIT_CONFIG, have_$$lower($$1)): return(true)
    return(false)
}

defineTest(use?) {
    contains(WEBKIT_CONFIG, use_$$lower($$1)): return(true)
    return(false)
}

defineTest(enable?) {
    contains(WEBKIT_CONFIG, $$lower($$1)): return(true)
    return(false)
}

# Used by configDefines below
include(features.pri)

# Turn Webkit config into defines
defineReplace(configDefines) {
    unset(defines)

    args = $$split(1, |)

    possible_args = enable have use plugin_architecture
    !isEmpty(args) {
        for(arg, possible_args): contains(args, $$arg): CONFIG += $$arg
    } else {
        CONFIG += $$possible_args
    }

    for(config, WEBKIT_CONFIG) {
        match = $$find(config, "^build_")
        !isEmpty(match) {
            # We don't translate build_ to defines
            next()
        }
        match = $$find(config, "^have_")
        !isEmpty(match) {
            have: defines += $$upper($$config)=1
            next()
        }
        match = $$find(config, "^plugin_architecture_")
        !isEmpty(match) {
            plugin_architecture: defines += $$upper($$config)=1
            next()
        }
        equals(config, "use_system_malloc") {
            use: defines += $$upper($$config)=1
            next()
        }
        match = $$find(config, "^use_")
        !isEmpty(match) {
            use: defines += WTF_$$upper($$config)=1
            next()
        }

        enable: defines += ENABLE_$$upper($$config)=1
    }

    # To prevent clashes with Platform.h, we have to explicitly
    # disable features that are not enabled.
    for(define, FEATURE_DEFAULTS) {
        anyFeatureDefine = $$find(define, =.$)
        isEmpty(anyFeatureDefine): next()

        enabledFeature = $$replace(anyFeatureDefine, =.$, =1)
        disabledFeature = $$replace(anyFeatureDefine, =.$, =0)

        !contains(defines, $$enabledFeature) {
            defines += $$disabledFeature
        }
    }

    return($$defines)
}

defineReplace(javascriptFeatureDefines) {
    defines = LANGUAGE_JAVASCRIPT=1 $$configDefines(enable)

    # Omit disabled features when generating bindings to shrink the
    # generator's command line on Windows.
    disabledFeatures = $$find(defines, ^.+=0$)
    for (disabledFeature, disabledFeatures) {
        defines -= $$disabledFeature
    }

    return($$defines)
}

defineReplace(setEnvironmentVariable) {
  variable = $$1
  value = $$2
  win_cmd_shell {
      return((set \"$$variable=$$value\"))
  }
  return(export \"$$variable=$$value\")
}