summaryrefslogtreecommitdiffstats
path: root/tools/qmlcachegen/qtquickcompiler.prf
blob: 24cbe7f2e5e005cffb865c30e71dcd49beaf1465 (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
if(qtc_run|lupdate_run): return()

!contains(QT, qml) {
    qt_modules = \
        $$replace(QT, -private$, _private) \
        $$replace(QT_PRIVATE, -private$, _private)
    qt_modules = $$resolve_depends(qt_modules, "QT.", ".depends" ".run_depends")
    !contains(qt_modules, qml): \
        error("The qtquickcompiler feature cannot be used without the QML module.")
    unset(qt_modules)
}

qtPrepareTool(QML_CACHEGEN, qmlcachegen, _FILTER)
qtPrepareTool(QMAKE_RCC, rcc, _DEP)

isEmpty(QMLCACHE_DIR): QMLCACHE_DIR = .

defineReplace(qmlCacheResourceFileOutputName) {
    name = $$relative_path($$1, $$_PRO_FILE_PWD_)
    contains(name, ^\\.\\..*): name = $$relative_path($$1, $$OUT_PWD)
    name = $$replace(name,/,_)
    name = $$replace(name, \\.qrc$, _qmlcache.qrc)
    name = $$replace(name,\.\.,)
    name = $$replace(name,-,_)
    name = $$absolute_path($$name, $$OUT_PWD)
    return($${name})
}

defineTest(qtQuickRetainSources) {
    for(retainedRes, QTQUICK_COMPILER_RETAINED_RESOURCES) {
        equals(1, $$retainedRes): return(true)
    }
    return(false)
}

defineTest(qtQuickSkippedResourceFile) {
    for(skippedRes, QTQUICK_COMPILER_SKIPPED_RESOURCES) {
        equals(1, $$skippedRes): return(true)
    }
    return(false)
}

# Flatten RESOURCES that may contain individual files or objects
load(resources)

NEWRESOURCES =
QMLCACHE_RESOURCE_FILES =

for(res, RESOURCES) {
    qtQuickSkippedResourceFile($$res) {
        NEWRESOURCES += $$res
        next()
    }

    absRes = $$absolute_path($$res, $$_PRO_FILE_PWD_)
    rccContents = $$system($$QMAKE_RCC_DEP -list $$system_quote($$absRes),lines)
    contains(rccContents,.*\\.js$)|contains(rccContents,.*\\.qml$)|contains(rccContents,.*\\.mjs$) {
        new_resource = $$qmlCacheResourceFileOutputName($$res)
        mkpath($$dirname(new_resource))
        qtQuickRetainSources($$res) {
            NEWRESOURCES += $$res
            QMLCACHE_LOADER_FLAGS += --retain=$$shell_quote($$absRes)
        } else {
            remaining_files = $$system($$QML_CACHEGEN_FILTER -filter-resource-file \
                    -o $$system_quote($$new_resource) $$system_quote($$absRes),lines)
            !isEmpty(remaining_files) {
                NEWRESOURCES += $$new_resource
                QMLCACHE_LOADER_FLAGS += --resource-file-mapping=$$shell_quote($$absRes=$$new_resource)
            } else {
                QMLCACHE_LOADER_FLAGS += --resource-file-mapping=$$shell_quote($$absRes)
            }
        }

        QMLCACHE_RESOURCE_FILES += $$absRes

        for(candidate, rccContents) {
            contains(candidate,.*\\.js$)|contains(candidate,.*\\.qml$)|contains(candidate,.*\\.mjs$) {
                QMLCACHE_FILES += $$candidate
            }
        }
    } else {
        NEWRESOURCES += $$res
    }
}

RESOURCES = $$NEWRESOURCES

QMLCACHE_RESOURCE_FLAGS =
for(res, QMLCACHE_RESOURCE_FILES) {
    QMLCACHE_RESOURCE_FLAGS += --resource=$$shell_quote($$res)
}

defineReplace(qmlCacheOutputName) {
    name = $$absolute_path($$1, $$OUT_PWD)
    name = $$relative_path($$name, $$_PRO_FILE_PWD_)
    name = $$replace(name, \\.qml$, _qml)
    name = $$replace(name, \\.js$, _js)
    name = $$replace(name, \\.mjs$, _mjs)
    name = $$replace(name,/,_)
    name = $$QMLCACHE_DIR/$${name}
    return($${name})
}

qmlcache.input = QMLCACHE_FILES
qmlcache.output = ${QMAKE_FUNC_FILE_IN_qmlCacheOutputName}$${first(QMAKE_EXT_CPP)}
qmlcache.commands = $$QML_CACHEGEN $$QMLCACHE_RESOURCE_FLAGS $$QMLCACHE_FLAGS -o ${QMAKE_FILE_OUT} ${QMAKE_FILE_IN}
qmlcache.name = qmlcachegen ${QMAKE_FILE_IN}
qmlcache.variable_out = GENERATED_SOURCES
qmlcache.dependency_type = TYPE_C

qmlcache_loader.input = QMLCACHE_RESOURCE_FILES
qmlcache_loader.output = $$QMLCACHE_DIR/qmlcache_loader.cpp
qmlcache_loader.commands = $$QML_CACHEGEN $$QMLCACHE_LOADER_FLAGS $$QMLCACHE_FLAGS -o ${QMAKE_FILE_OUT} ${QMAKE_FILE_IN}
qmlcache_loader.name = qmlcachengen_loader ${QMAKE_FILE_IN}
qmlcache_loader.variable_out = SOURCES
qmlcache_loader.dependency_type = TYPE_C
qmlcache_loader.CONFIG = combine

unix:!no_qmlcache_depend {
    qmlcache.depends += $$QML_CACHEGEN
    qmlcache_loader.depends += $$QML_CACHEGEN
}

QMAKE_EXTRA_COMPILERS += qmlcache qmlcache_loader