aboutsummaryrefslogtreecommitdiffstats
path: root/share
diff options
context:
space:
mode:
Diffstat (limited to 'share')
-rw-r--r--share/qbs/imports/qbs/Probes/FrameworkProbe.qbs12
-rw-r--r--share/qbs/imports/qbs/Probes/LibraryProbe.qbs60
-rw-r--r--share/qbs/modules/protobuf/cpp/protobufcpp.qbs48
-rw-r--r--share/qbs/modules/protobuf/objc/protobufobjc.qbs70
-rw-r--r--share/qbs/modules/protobuf/protobuf.js111
-rw-r--r--share/qbs/modules/protobuf/protobufbase.qbs30
6 files changed, 325 insertions, 6 deletions
diff --git a/share/qbs/imports/qbs/Probes/FrameworkProbe.qbs b/share/qbs/imports/qbs/Probes/FrameworkProbe.qbs
index 544759150..da5557cc9 100644
--- a/share/qbs/imports/qbs/Probes/FrameworkProbe.qbs
+++ b/share/qbs/imports/qbs/Probes/FrameworkProbe.qbs
@@ -29,12 +29,12 @@
****************************************************************************/
PathProbe {
- platformPaths: [
- "~/Library/Frameworks",
- "/usr/local/lib",
- "/Library/Frameworks",
- "/System/Library/Frameworks"
- ]
+ platformPaths: (qbs.sysroot ? [qbs.sysroot + "/System/Library/Frameworks"] : []).concat([
+ "~/Library/Frameworks",
+ "/usr/local/lib",
+ "/Library/Frameworks",
+ "/System/Library/Frameworks"
+ ])
nameFilter: {
return function(name) {
diff --git a/share/qbs/imports/qbs/Probes/LibraryProbe.qbs b/share/qbs/imports/qbs/Probes/LibraryProbe.qbs
new file mode 100644
index 000000000..b81a15dcb
--- /dev/null
+++ b/share/qbs/imports/qbs/Probes/LibraryProbe.qbs
@@ -0,0 +1,60 @@
+/****************************************************************************
+**
+** Copyright (C) 2018 Ivan Komissarov.
+** Contact: http://www.qt.io/licensing
+**
+** This file is part of Qbs.
+**
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms and
+** conditions see http://www.qt.io/terms-conditions. For further information
+** use the contact form at http://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 or version 3 as published by the Free
+** Software Foundation and appearing in the file LICENSE.LGPLv21 and
+** LICENSE.LGPLv3 included in the packaging of this file. Please review the
+** following information to ensure the GNU Lesser General Public License
+** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, The Qt Company gives you certain additional
+** rights. These rights are described in The Qt Company LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+****************************************************************************/
+
+PathProbe {
+ nameSuffixes: {
+ if (qbs.targetOS.contains("windows"))
+ return [".lib"];
+ if (qbs.targetOS.contains("macos"))
+ return [".dylib", ".a"];
+ return [".so", ".a"];
+ }
+ platformPaths: qbs.targetOS.contains("unix") ? [
+ "/usr/lib",
+ "/usr/local/lib",
+ ] : []
+ nameFilter: {
+ if (qbs.targetOS.contains("unix")) {
+ return function(name) {
+ return "lib" + name;
+ }
+ } else {
+ return function(name) {
+ return name;
+ }
+ }
+ }
+ platformEnvironmentPaths: {
+ if (qbs.targetOS.contains("windows"))
+ return [ "PATH" ];
+ else
+ return [ "LIBRARY_PATH" ];
+ }
+}
diff --git a/share/qbs/modules/protobuf/cpp/protobufcpp.qbs b/share/qbs/modules/protobuf/cpp/protobufcpp.qbs
new file mode 100644
index 000000000..5cb3257d4
--- /dev/null
+++ b/share/qbs/modules/protobuf/cpp/protobufcpp.qbs
@@ -0,0 +1,48 @@
+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
+
+ Depends { name: "cpp" }
+
+ cpp.libraryPaths: [libraryPath]
+ cpp.dynamicLibraries: qbs.targetOS.contains("unix") ? ["protobuf", "pthread"] : ["protobuf"]
+ cpp.includePaths: [outputDir, includePath]
+
+ Rule {
+ inputs: ["protobuf.input"]
+ outputFileTags: ["hpp", "cpp"]
+ outputArtifacts: {
+ return [
+ HelperFunctions.cppArtifact(input.protobuf.cpp, product, input, "hpp", ".pb.h"),
+ HelperFunctions.cppArtifact(input.protobuf.cpp, product, input, "cpp", ".pb.cc")
+ ];
+ }
+
+ prepare: HelperFunctions.doPrepare(input.protobuf.cpp, product, input, outputs, "cpp")
+ }
+
+ validate: {
+ baseValidate();
+ if (!HelperFunctions.checkPath(includePath))
+ throw "Can't find cpp protobuf include files. Please set the includePath property.";
+ if (!HelperFunctions.checkPath(libraryPath))
+ throw "Can't find cpp protobuf library. Please set the libraryPath property.";
+ }
+
+ Probes.IncludeProbe {
+ id: includeProbe
+ names: "google/protobuf/message.h"
+ }
+
+ Probes.LibraryProbe {
+ id: libraryProbe
+ names: "protobuf"
+ }
+}
diff --git a/share/qbs/modules/protobuf/objc/protobufobjc.qbs b/share/qbs/modules/protobuf/objc/protobufobjc.qbs
new file mode 100644
index 000000000..c252d9949
--- /dev/null
+++ b/share/qbs/modules/protobuf/objc/protobufobjc.qbs
@@ -0,0 +1,70 @@
+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")
+ }
+
+ validate: {
+ baseValidate();
+ 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"]
+ }
+}
diff --git a/share/qbs/modules/protobuf/protobuf.js b/share/qbs/modules/protobuf/protobuf.js
new file mode 100644
index 000000000..576a5ec07
--- /dev/null
+++ b/share/qbs/modules/protobuf/protobuf.js
@@ -0,0 +1,111 @@
+/****************************************************************************
+**
+** Copyright (C) 2018 Ivan Komissarov
+** Contact: abbapoh@gmail.com
+**
+** This file is part of Qbs.
+**
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms and
+** conditions see http://www.qt.io/terms-conditions. For further information
+** use the contact form at http://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 or version 3 as published by the Free
+** Software Foundation and appearing in the file LICENSE.LGPLv21 and
+** LICENSE.LGPLv3 included in the packaging of this file. Please review the
+** following information to ensure the GNU Lesser General Public License
+** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, The Qt Company gives you certain additional
+** rights. These rights are described in The Qt Company LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+****************************************************************************/
+
+var File = require("qbs.File");
+var FileInfo = require("qbs.FileInfo");
+
+var checkPath = function(path) {
+ return path && File.exists(path)
+};
+
+function toCamelCase(str){
+ return str.split('_').map(function(word, index) {
+ // If it is the first word make sure to lowercase all the chars.
+ if (index === 0) {
+ return word.toLowerCase();
+ }
+ // If it is not the first word only upper case the first char and lowercase the rest.
+ return word.charAt(0).toUpperCase() + word.slice(1).toLowerCase();
+ }).join('');
+}
+
+function getOutputDir(module, product, input) {
+ var outputDir = module.outputDir;
+ var importPaths = module.importPaths;
+ if (importPaths.length !== 0) {
+ var canonicalInput = File.canonicalFilePath(FileInfo.path(input.filePath));
+ for (var i = 0; i < importPaths.length; ++i) {
+ path = File.canonicalFilePath(importPaths[i]);
+
+ if (canonicalInput.startsWith(path)) {
+ return outputDir + "/" + FileInfo.relativePath(path, canonicalInput);
+ }
+ }
+ }
+ return outputDir;
+}
+
+function cppArtifact(module, product, input, tag, suffix) {
+ var outputDir = getOutputDir(module, product, input);
+ return {
+ fileTags: [tag],
+ filePath: outputDir + "/" + FileInfo.baseName(input.fileName) + suffix,
+ cpp: {
+ includePaths: [].concat(input.cpp.includePaths, outputDir),
+ warningLevel: "none",
+ }
+ };
+}
+
+function objcArtifact(module, product, input, tag, suffix) {
+ var outputDir = getOutputDir(module, product, input);
+ return {
+ fileTags: [tag],
+ filePath: outputDir + "/" + toCamelCase(FileInfo.baseName(input.fileName)) + suffix,
+ cpp: {
+ includePaths: [].concat(input.cpp.includePaths, outputDir),
+ warningLevel: "none",
+ }
+ }
+}
+
+function doPrepare(module, product, input, outputs, lang)
+{
+ var outputDir = module.outputDir;
+ var args = [];
+
+ args.push("--" + lang + "_out", outputDir);
+
+ var importPaths = module.importPaths;
+ if (importPaths.length === 0)
+ importPaths = [FileInfo.path(input.filePath)];
+ importPaths.forEach(function(path) {
+ if (!FileInfo.isAbsolutePath(path))
+ path = FileInfo.joinPaths(product.sourceDirectory, path);
+ args.push("--proto_path", path);
+ });
+
+ args.push(input.filePath);
+
+ var cmd = new Command(module.protocBinary, args);
+ cmd.highlight = "codegen";
+ cmd.description = "generating " + lang + " files for " + input.fileName;
+ return [cmd];
+}
diff --git a/share/qbs/modules/protobuf/protobufbase.qbs b/share/qbs/modules/protobuf/protobufbase.qbs
new file mode 100644
index 000000000..1c2e68800
--- /dev/null
+++ b/share/qbs/modules/protobuf/protobufbase.qbs
@@ -0,0 +1,30 @@
+import qbs
+import qbs.File
+import qbs.FileInfo
+import qbs.Probes
+import "protobuf.js" as HelperFunctions
+
+Module {
+ property string protocBinary: protocProbe.filePath
+ property pathList importPaths: []
+
+ property string outputDir: product.buildDirectory + "/protobuf"
+ readonly property string protobufRoot: FileInfo.path(FileInfo.path(protocBinary))
+
+ readonly property var baseValidate: {
+ return function() {
+ if (!File.exists(protocBinary))
+ throw "Can't find protoc binary. Please set the protocBinary property or make sure it is found in PATH";
+ }
+ }
+
+ FileTagger {
+ patterns: ["*.proto"]
+ fileTags: ["protobuf.input"];
+ }
+
+ Probes.BinaryProbe {
+ id: protocProbe
+ names: ["protoc"]
+ }
+}