diff options
author | Christian Kandeler <christian.kandeler@qt.io> | 2017-01-26 15:37:20 +0100 |
---|---|---|
committer | Christian Kandeler <christian.kandeler@qt.io> | 2017-02-17 11:10:28 +0000 |
commit | b860cd4f40b3efba8edff2b9bb87b8b999def42e (patch) | |
tree | 213796b49768675ad1793377efaa7061f9c1caa3 /share | |
parent | b78607350bcefdd75d4c41473312bf580801d0f6 (diff) |
Cpp module: Allow a set of source files to be combined into one
We introduce file tags and properties to support the concept of
"amalgamation builds" for C, C++, Objective-C and Objective-C++.
[ChangeLog] Provided the means to easily combine source files for the C
language family in order to support "amalgamation builds".
Change-Id: Ia3d248203c29418907178b47dba84ca3a18a0857
Reviewed-by: Joerg Bornemann <joerg.bornemann@qt.io>
Diffstat (limited to 'share')
-rw-r--r-- | share/qbs/imports/qbs/ModUtils/utils.js | 12 | ||||
-rw-r--r-- | share/qbs/modules/cpp/CppModule.qbs | 84 |
2 files changed, 92 insertions, 4 deletions
diff --git a/share/qbs/imports/qbs/ModUtils/utils.js b/share/qbs/imports/qbs/ModUtils/utils.js index 8fb8b7cb0..046e8adac 100644 --- a/share/qbs/imports/qbs/ModUtils/utils.js +++ b/share/qbs/imports/qbs/ModUtils/utils.js @@ -33,8 +33,20 @@ var File = require("qbs.File"); var FileInfo = require("qbs.FileInfo"); var Process = require("qbs.Process"); var TemporaryDir = require("qbs.TemporaryDir"); +var TextFile = require("qbs.TextFile"); var Utilities = require("qbs.Utilities"); +function mergeCFiles(inputs, outputFilePath) +{ + var f = new TextFile(outputFilePath, TextFile.WriteOnly); + try { + for (var i = 0; i < inputs.length; ++i) + f.writeLine('#include "' + inputs[i].filePath + '"'); + } finally { + f.close(); + } +} + function sanitizedList(list, product, fullPropertyName) { if (!Array.isArray(list)) return list; diff --git a/share/qbs/modules/cpp/CppModule.qbs b/share/qbs/modules/cpp/CppModule.qbs index dd36cc228..150d773e1 100644 --- a/share/qbs/modules/cpp/CppModule.qbs +++ b/share/qbs/modules/cpp/CppModule.qbs @@ -312,24 +312,100 @@ Module { property bool allowUnresolvedSymbols: false + property bool combineCSources: false + property bool combineCxxSources: false + property bool combineObjcSources: false + property bool combineObjcxxSources: false + + // TODO: The following four rules could use a convenience base item if rule properties + // were available in Artifact items and prepare scripts. + Rule { + multiplex: true + inputs: ["c.combine"] + Artifact { + filePath: "amalgamated_" + product.targetName + ".c" + fileTags: ["c"] + } + prepare: { + var cmd = new JavaScriptCommand(); + cmd.description = "creating " + output.fileName; + cmd.highlight = "codegen"; + cmd.sourceCode = function() { + ModUtils.mergeCFiles(inputs["c.combine"], output.filePath); + }; + return [cmd]; + } + } + Rule { + multiplex: true + inputs: ["cpp.combine"] + Artifact { + filePath: "amalgamated_" + product.targetName + ".cpp" + fileTags: ["cpp"] + } + prepare: { + var cmd = new JavaScriptCommand(); + cmd.description = "creating " + output.fileName; + cmd.highlight = "codegen"; + cmd.sourceCode = function() { + ModUtils.mergeCFiles(inputs["cpp.combine"], output.filePath); + }; + return [cmd]; + } + } + Rule { + multiplex: true + inputs: ["objc.combine"] + Artifact { + filePath: "amalgamated_" + product.targetName + ".m" + fileTags: ["objc"] + } + prepare: { + var cmd = new JavaScriptCommand(); + cmd.description = "creating " + output.fileName; + cmd.highlight = "codegen"; + cmd.sourceCode = function() { + ModUtils.mergeCFiles(inputs["objc.combine"], output.filePath); + }; + return [cmd]; + } + } + Rule { + multiplex: true + inputs: ["objcpp.combine"] + Artifact { + filePath: "amalgamated_" + product.targetName + ".mm" + fileTags: ["objccpp"] + } + prepare: { + var cmd = new JavaScriptCommand(); + cmd.description = "creating " + output.fileName; + cmd.highlight = "codegen"; + cmd.sourceCode = function() { + ModUtils.mergeCFiles(inputs["objcpp.combine"], output.filePath); + }; + return [cmd]; + } + } + FileTagger { patterns: ["*.c"] - fileTags: ["c"] + fileTags: combineCSources ? ["c.combine"] : ["c"] } FileTagger { patterns: ["*.C", "*.cpp", "*.cxx", "*.c++", "*.cc"] - fileTags: ["cpp"] + fileTags: combineCxxSources ? ["cpp.combine"] : ["cpp"] } FileTagger { patterns: ["*.m"] - fileTags: ["objc"] + fileTags: combineObjcSources ? ["objc.combine"] : ["objc"] } FileTagger { patterns: ["*.mm"] - fileTags: ["objcpp"] + fileTags: combineObjcxxSources ? ["objcpp.combine"] : ["objcpp"] } FileTagger { |