aboutsummaryrefslogtreecommitdiffstats
path: root/share/qbs/modules/protobuf/objc/protobufobjc.qbs
blob: e2c4b52608f1f3b437646a6bf909f9a9037e7b2e (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
import qbs
import qbs.File
import qbs.FileInfo
import qbs.Probes
import "../protobufbase.qbs" as ProtobufBase
import "../protobuf.js" as HelperFunctions

ProtobufBase {
    property string includePath: includeProbe.path
    property string libraryPath: libraryProbe.path
    property string frameworkPath: frameworkProbe.path

    Depends { name: "cpp" }

    // library build
    Properties {
        condition: !frameworkPath
        cpp.includePaths: [outputDir, includePath]
        cpp.libraryPaths: [libraryPath]
        cpp.frameworks: ["Foundation"]
        cpp.dynamicLibraries: ["ProtocolBuffers"]
    }

    // framework build
    Properties {
        condition: frameworkPath
        cpp.includePaths: [outputDir]
        cpp.frameworkPaths: [frameworkPath]
        cpp.frameworks: ["Foundation", "Protobuf"]
        cpp.defines: ["GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS"]
    }

    Rule {
        inputs: ["protobuf.input"]
        outputFileTags: ["hpp", "objc"]
        outputArtifacts: {
            return [
                HelperFunctions.objcArtifact(input.protobuf.objc, product, input, "hpp", ".pbobjc.h"),
                HelperFunctions.objcArtifact(input.protobuf.objc, product, input, "objc", ".pbobjc.m")
            ];
        }

        prepare: HelperFunctions.doPrepare(input.protobuf.objc, product, input, outputs, "objc")
    }

    validateFunc: {
        return function() {
            base();
            if (!HelperFunctions.checkPath(frameworkPath)) {
                if (!HelperFunctions.checkPath(includePath))
                    throw "Can't find objective-c protobuf include files. Please set the includePath or frameworkPath property.";
                if (!HelperFunctions.checkPath(libraryPath))
                    throw "Can't find objective-c protobuf library. Please set the libraryPath or frameworkPath property.";
            }
        }
    }

    Probes.IncludeProbe {
        id: includeProbe
        names: "GPBMessage.h"
    }

    Probes.LibraryProbe {
        id: libraryProbe
        names: "ProtocolBuffers"
    }

    Probes.FrameworkProbe {
        id: frameworkProbe
        names: ["Protobuf"]
    }
}