aboutsummaryrefslogtreecommitdiffstats
path: root/share/qbs/modules/qt/core/qtcore.qbs
blob: 075b462b627d69781ae5afa9b136182449c49d97 (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
import qbs.base 1.0
import qbs.fileinfo 1.0 as FileInfo
import '../../utils.js' as ModUtils
import "moc.js" 1.0 as Moc
import '../qtfunctions.js' as QtFunctions

Module {
    Depends { name: "cpp" }

    property string qtVersionName: "default"
    property string configKey: "qt/" + qtVersionName + "/"
    property string qtNamespace: qbs.configurationValue(configKey + "namespace", undefined)
    property string qtPath: qbs.configurationValue(configKey + "path", undefined)
    property string binPath: qtPath ? qtPath + "/bin" : qbs.configurationValue(configKey + "binPath", undefined)
    property string incPath: qtPath ? qtPath + "/include" : qbs.configurationValue(configKey + "incPath", undefined)
    property string libPath: qtPath ? qtPath + "/lib" : qbs.configurationValue(configKey + "libPath", undefined)
    property string mkspecsPath: qtPath ? qtPath + "/mkspecs" : qbs.configurationValue(configKey + "mkspecsPath", undefined)
    property string generatedFilesDir: 'GeneratedFiles/' + product.name // ### TODO: changing this property does not change the path in the rule ATM.
    property string libraryInfix: cpp.debugInformation ? 'd' : ''
    cpp.defines: {
        if (!qtNamespace)
            return undefined;
        return ["QT_NAMESPACE=" + qtNamespace]
    }
    cpp.includePaths: [
        mkspecsPath + '/default',
        incPath + '/QtCore',
        incPath,
        product.buildDirectory + '/' + generatedFilesDir
    ]
    cpp.libraryPaths: [libPath]
    cpp.dynamicLibraries: qbs.targetOS != 'mac' ? [QtFunctions.getLibraryName('QtCore', qbs.targetOS, cpp.debugInformation)] : []
    cpp.frameworkPaths: [libPath]
    cpp.frameworks: [QtFunctions.getLibraryName('QtCore', qbs.targetOS, cpp.debugInformation)]
    cpp.rpaths:  [libPath]

    setupBuildEnvironment: {
        // Not really a setup in this case. Just some sanity checks.
        if (!binPath)
            throw "qt/core.binPath not set. Set the configuration values qt/default/binPath or qt/default/path.";
        if (!incPath)
            throw "qt/core.incPath not set. Set the configuration values qt/default/incPath or qt/default/path.";
        if (!libPath)
            throw "qt/core.libPath not set. Set the configuration values qt/default/libPath or qt/default/path.";
        if (!mkspecsPath)
            throw "qt/core.mkspecsPath not set. Set the configuration values qt/default/mkspecsPath or qt/default/path.";
    }

    setupRunEnvironment: {
        var v = getenv('PATH') || ''
        if (v.length > 0 && v.charAt(0) != ';')
            v = ';' + v
        var y = binPath
        if (qbs.targetOS === 'windows')
            v = FileInfo.toWindowsSeparators(y) + v
        else
            v = y + v
        putenv('PATH', v)
    }

    FileTagger {
        pattern: "*.qrc"
        fileTags: ["qrc"]
    }

    Rule {
        inputs: ["moc_cpp"]

        Artifact {
            fileName: 'GeneratedFiles/' + product.name + '/' + input.baseName + '.moc'
//            fileName: input.baseDir + '/' + input.baseName + '.moc'
            fileTags: ["hpp"]
        }

        prepare: {
            var cmd = new Command(product.module.binPath + '/moc', Moc.args(input.fileName, output.fileName, input));
            cmd.description = 'moc ' + FileInfo.fileName(input.fileName);
            cmd.highlight = 'codegen';
            return cmd;
        }
    }

    Rule {
        inputs: ["moc_hpp"]

        Artifact {
            fileName: 'GeneratedFiles/' + product.name + '/moc_' + input.baseName + '.cpp'
            fileTags: [ "cpp" ]
        }

        prepare: {
            var cmd = new Command(product.module.binPath + '/moc', Moc.args(input.fileName, output.fileName, input));
            cmd.description = 'moc ' + FileInfo.fileName(input.fileName);
            cmd.highlight = 'codegen';
            return cmd;
        }
    }

    Rule {
        inputs: ["moc_hpp_inc"]

        Artifact {
            fileName: 'GeneratedFiles/' + product.name + '/moc_' + input.baseName + '.cpp'
            fileTags: [ "hpp" ]
        }

        prepare: {
            var cmd = new Command(product.module.binPath + '/moc', Moc.args(input.fileName, output.fileName, input));
            cmd.description = 'moc ' + FileInfo.fileName(input.fileName);
            cmd.highlight = 'codegen';
            return cmd;
        }
    }

    Rule {
        inputs: ["qrc"]

        Artifact {
//  ### TODO we want to access the module's property "generatedFilesDir" here. But without evaluating all available properties a priori.
            fileName: 'GeneratedFiles/' + product.name + '/qrc_' + input.baseName + '.cpp'
            fileTags: ["cpp"]
        }
        prepare: {
            var cmd = new Command(product.module.binPath + '/rcc', [input.fileName, '-name', FileInfo.baseName(input.fileName), '-o', output.fileName]);
            cmd.description = 'rcc ' + FileInfo.fileName(input.fileName);
            cmd.highlight = 'codegen';
            return cmd;
        }
    }
}