summaryrefslogtreecommitdiff
path: root/share/qbs/imports/qbs/probes/PkgConfigProbe.qbs
blob: aca42f0def2171d2565d2f3370348476f07e416b (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
import qbs 1.0
import qbs.fileinfo as FileInfo
import "utils.js" as Utils

Probe {
    // Inputs
    property string executable: 'pkg-config'
    property string name
    property string minVersion
    property string exactVersion
    property string maxVersion

    // Output
    property stringList cflags
    property stringList libs

    configure: {
        if (!name)
            throw '"name" must be specified';
        var p = new Process();
        var args = [ name ];
        if (minVersion !== undefined)
            args.push(name + ' >= ' + minVersion);
        if (exactVersion !== undefined)
            args.push(name + ' = ' + exactVersion);
        if (maxVersion !== undefined)
            args.push(name + ' <= ' + maxVersion);
        if (p.exec(executable, args.concat([ '--cflags' ])) === 0) {
            cflags = p.readAll().trim();
            if (cflags === "")
                cflags = undefined;
            else
                cflags = cflags.split(/\s/);
            if (p.exec(executable, args.concat([ '--libs' ])) === 0) {
                libs = p.readAll().trim();
                if (libs === "")
                    libs = undefined;
                else
                    libs = libs.split(/\s/);
                found = true;
                print("PkgConfigProbe: found library " + name);
                return;
            }
        }
        found = false;
        cflags = undefined;
        libs = undefined;
    }
}