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
|
import qbs.File
import qbs.FileInfo
import qbs.Probes
import qbs.ModUtils
import "../protobufbase.qbs" as ProtobufBase
import "../protobuf.js" as HelperFunctions
ProtobufBase {
property string includePath: includeProbe.found ? includeProbe.path : undefined
property string libraryPath: libraryProbe.found ? libraryProbe.path : undefined
property string pluginPath: pluginProbe.filePath
property string pluginName: "protoc-gen-nanopb"
readonly property string _plugin: "protoc-gen-nanopb=" + pluginPath
readonly property string _libraryName: {
var libraryName;
if (libraryProbe.found) {
libraryName = FileInfo.baseName(libraryProbe.fileName);
if (libraryName.startsWith("lib"))
libraryName = libraryName.substring(3);
}
return libraryName;
}
Depends { name: "cpp" }
cpp.libraryPaths: {
var result = [];
if (libraryProbe.found)
result.push(libraryProbe.path);
return result;
}
cpp.dynamicLibraries: {
var result = [];
if (_libraryName)
result.push(_libraryName);
return result;
}
cpp.includePaths: {
var result = [outputDir];
if (includeProbe.found)
result.push(includePath);
return result;
}
Rule {
inputs: ["protobuf.input"]
outputFileTags: ["hpp", "protobuf.hpp", "cpp"]
outputArtifacts: {
var outputDir = HelperFunctions.getOutputDir(input.protobuf.nanopb, input);
var result = [
HelperFunctions.cppArtifact(outputDir, input, ["hpp", "protobuf.hpp"],
".pb.h"),
HelperFunctions.cppArtifact(outputDir, input, ["cpp"], ".pb.c")
];
return result;
}
prepare: {
var options = input.protobuf.nanopb.importPaths.map(function (path) {
return "-I" + path;
})
var result = HelperFunctions.doPrepare(
input.protobuf.nanopb, product, input, outputs, "nanopb",
input.protobuf.nanopb._plugin, options);
return result;
}
}
Probes.IncludeProbe {
id: includeProbe
names: ["pb.h", "pb_encode.h", "pb_decode.h", "pb_common.h"]
platformSearchPaths: includePath ? [] : base
searchPaths: includePath ? [includePath] : []
}
Probes.LibraryProbe {
id: libraryProbe
names: [
"protobuf-nanopb",
"protobuf-nanopbd",
]
platformSearchPaths: libraryPath ? [] : base
searchPaths: libraryPath ? [libraryPath] : []
}
Probes.BinaryProbe {
id: pluginProbe
names: pluginName
}
validate: {
HelperFunctions.validateCompiler(compilerName, compilerPath);
if (!includeProbe.found)
throw "Can't find nanopb protobuf include files. Please set the includePath property.";
if (!libraryProbe.found)
throw "Can't find nanopb protobuf library. Please set the libraryPath property.";
if (!HelperFunctions.checkPath(pluginPath))
throw "Can't find nanopb protobuf plugin. Please set the pluginPath property.";
}
}
|