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
|
import qbs.File
import qbs.FileInfo
import qbs.Probes
import qbs.ModUtils
import "../protobufbase.qbs" as ProtobufBase
import "../protobuf.js" as HelperFunctions
ProtobufBase {
property bool useGrpc: false
property bool _linkLibraries: true
readonly property bool _hasModules: protobuflib.present && (!useGrpc || grpcpp.present)
property string _cxxLanguageVersion: "c++17"
cpp.includePaths: outputDir
Depends { name: "cpp" }
Depends {
name: "protobuflib";
condition: _linkLibraries;
required: false;
enableFallback: false
}
Depends {
name: "grpcpp";
condition: _linkLibraries && useGrpc;
required: false;
enableFallback: false
}
property path grpcPluginPath: grpcPluginProbe.filePath
Probes.BinaryProbe {
condition: useGrpc
id: grpcPluginProbe
names: "grpc_cpp_plugin"
}
cpp.cxxLanguageVersion: _cxxLanguageVersion
Rule {
inputs: ["protobuf.input", "protobuf.grpc"]
outputFileTags: ["hpp", "protobuf.hpp", "cpp"]
outputArtifacts: {
var outputDir = HelperFunctions.getOutputDir(input.protobuf.cpp, input);
var result = [
HelperFunctions.cppArtifact(outputDir, input, ["hpp", "protobuf.hpp"],
".pb.h"),
HelperFunctions.cppArtifact(outputDir, input, "cpp", ".pb.cc")
];
if (input.fileTags.includes("protobuf.grpc")) {
result.push(
HelperFunctions.cppArtifact(outputDir, input, ["hpp", "protobuf.hpp"],
".grpc.pb.h"),
HelperFunctions.cppArtifact(outputDir, input, ["cpp"], ".grpc.pb.cc"));
}
return result;
}
prepare: {
var result = HelperFunctions.doPrepare(
input.protobuf.cpp, product, input, outputs, "cpp");
if (input.fileTags.includes("protobuf.grpc")) {
result = ModUtils.concatAll(result, HelperFunctions.doPrepare(
input.protobuf.cpp, product, input, outputs, "grpc",
"protoc-gen-grpc=" + input.protobuf.cpp.grpcPluginPath));
}
return result;
}
}
validate: {
HelperFunctions.validateCompiler(compilerName, compilerPath);
if (_linkLibraries && ! _hasModules) {
throw "Can't find cpp protobuf runtime. Make sure .pc files are present";
}
if (useGrpc) {
if (!File.exists(grpcPluginPath))
throw "Can't find grpc_cpp_plugin plugin. Please set the grpcPluginPath property.";
}
}
}
|