aboutsummaryrefslogtreecommitdiffstats
path: root/share
diff options
context:
space:
mode:
authorDenis Shienkov <denis.shienkov@gmail.com>2021-05-19 19:35:17 +0300
committerDenis Shienkov <denis.shienkov@gmail.com>2021-05-25 16:26:11 +0000
commitff04acd64d85d460e0f52a7ead233ae503e616d7 (patch)
tree208e81fee63b63fbca70dabaa2f62389bb2fc6ce /share
parent8ac3865fe9b9cdcd0f58bf0b6e7b08b60a8d374c (diff)
Use separate functions for repetitive actions
It makes sense to minimize the copy-paste errors by moving the repetitive code into the separate functions to the cpp.js file. This will simplify the code and improve the maintenance. Change-Id: Id5a2914ff28619553b855cc6f09810ad370c408c Reviewed-by: Ivan Komissarov <ABBAPOH@gmail.com>
Diffstat (limited to 'share')
-rw-r--r--share/qbs/modules/cpp/CppModule.qbs8
-rw-r--r--share/qbs/modules/cpp/GenericGCC.qbs8
-rw-r--r--share/qbs/modules/cpp/cpp.js140
-rw-r--r--share/qbs/modules/cpp/gcc.js95
-rw-r--r--share/qbs/modules/cpp/iar.js169
-rw-r--r--share/qbs/modules/cpp/iar.qbs8
-rw-r--r--share/qbs/modules/cpp/keil.js190
-rw-r--r--share/qbs/modules/cpp/keil.qbs8
-rw-r--r--share/qbs/modules/cpp/msvc.js88
-rw-r--r--share/qbs/modules/cpp/sdcc.js155
-rw-r--r--share/qbs/modules/cpp/sdcc.qbs8
-rw-r--r--share/qbs/modules/cpp/windows-msvc-base.qbs6
12 files changed, 431 insertions, 452 deletions
diff --git a/share/qbs/modules/cpp/CppModule.qbs b/share/qbs/modules/cpp/CppModule.qbs
index 39077bec8..98bf72e9f 100644
--- a/share/qbs/modules/cpp/CppModule.qbs
+++ b/share/qbs/modules/cpp/CppModule.qbs
@@ -204,6 +204,14 @@ Module {
property bool discardUnusedData
property bool removeDuplicateLibraries: true
+ property string defineFlag
+ property string includeFlag
+ property string systemIncludeFlag
+ property string preincludeFlag
+ property string libraryDependencyFlag
+ property string libraryPathFlag
+ property string linkerScriptFlag
+
property string linkerMode: "automatic"
PropertyOptions {
name: "linkerMode"
diff --git a/share/qbs/modules/cpp/GenericGCC.qbs b/share/qbs/modules/cpp/GenericGCC.qbs
index db45c8683..a84716019 100644
--- a/share/qbs/modules/cpp/GenericGCC.qbs
+++ b/share/qbs/modules/cpp/GenericGCC.qbs
@@ -205,8 +205,12 @@ CppModule {
property stringList dsymutilFlags
property bool alwaysUseLipo: false
- property string includeFlag: "-I"
- property string systemIncludeFlag: "-isystem"
+ defineFlag: "-D"
+ includeFlag: "-I"
+ systemIncludeFlag: "-isystem"
+ preincludeFlag: "-include"
+ libraryPathFlag: "-L"
+ linkerScriptFlag: "-T"
readonly property bool shouldCreateSymlinks: {
return createSymlinks && internalVersion && ["macho", "elf"].contains(cpp.imageFormat);
diff --git a/share/qbs/modules/cpp/cpp.js b/share/qbs/modules/cpp/cpp.js
index 30b097d03..da433f254 100644
--- a/share/qbs/modules/cpp/cpp.js
+++ b/share/qbs/modules/cpp/cpp.js
@@ -186,3 +186,143 @@ function collectLibraryDependencies(product) {
addExternalStaticLibs(product);
return result;
}
+
+function collectDefines(input) {
+ var allDefines = [];
+ var platformDefines = input.cpp.platformDefines;
+ if (platformDefines)
+ allDefines = allDefines.uniqueConcat(platformDefines);
+ var defines = input.cpp.defines;
+ if (defines)
+ allDefines = allDefines.uniqueConcat(defines);
+ return allDefines;
+}
+
+function collectIncludePaths(input) {
+ var allIncludePaths = [];
+ var includePaths = input.cpp.includePaths;
+ if (includePaths)
+ allIncludePaths = allIncludePaths.uniqueConcat(includePaths);
+ return allIncludePaths;
+}
+
+function collectSystemIncludePaths(input) {
+ var allIncludePaths = [];
+ var systemIncludePaths = input.cpp.systemIncludePaths;
+ if (systemIncludePaths)
+ allIncludePaths = allIncludePaths.uniqueConcat(systemIncludePaths);
+ var distributionIncludePaths = input.cpp.distributionIncludePaths;
+ if (distributionIncludePaths)
+ allIncludePaths = allIncludePaths.uniqueConcat(distributionIncludePaths);
+ return allIncludePaths;
+}
+
+function collectPreincludePaths(input) {
+ return input.cpp.prefixHeaders;
+}
+
+function collectLibraryPaths(product) {
+ var allLibraryPaths = [];
+ var libraryPaths = product.cpp.libraryPaths;
+ if (libraryPaths)
+ allLibraryPaths = allLibraryPaths.uniqueConcat(libraryPaths);
+ var distributionLibraryPaths = product.cpp.distributionLibraryPaths;
+ if (distributionLibraryPaths)
+ allLibraryPaths = allLibraryPaths.uniqueConcat(distributionLibraryPaths);
+ return allLibraryPaths;
+}
+
+function collectLinkerScriptPaths(inputs) {
+ return inputs.linkerscript
+ ? inputs.linkerscript.map(function(script) { return script.filePath; })
+ : [];
+}
+
+function collectLinkerObjectPaths(inputs) {
+ return inputs.obj ? inputs.obj.map(function(obj) { return obj.filePath; }) : [];
+}
+
+function collectLibraryDependenciesArguments(product) {
+ var deps = collectLibraryDependencies(product);
+ return deps.map(function(dep) { return product.cpp.libraryDependencyFlag + dep.filePath })
+}
+
+function collectDefinesArguments(input) {
+ var defines = collectDefines(input);
+ return defines.map(function(define) { return input.cpp.defineFlag + define });
+}
+
+function collectIncludePathsArguments(input) {
+ var paths = collectIncludePaths(input);
+ return paths.map(function(path) { return input.cpp.includeFlag + path });
+}
+
+function collectSystemIncludePathsArguments(input, flag) {
+ flag = (flag === undefined) ? input.cpp.systemIncludeFlag : flag;
+ var paths = collectSystemIncludePaths(input);
+ return paths.map(function(path) { return flag + path });
+}
+
+function collectPreincludePathsArguments(input, split) {
+ var paths = collectPreincludePaths(input);
+ if (split) {
+ var args = [];
+ for (var i = 0; i < paths.length; ++i)
+ args.push(input.cpp.preincludeFlag, paths[i]);
+ return args;
+ } else {
+ return paths.map(function(path) { return input.cpp.preincludeFlag + path });
+ }
+}
+
+function collectLibraryPathsArguments(product, flag) {
+ flag = (flag === undefined) ? product.cpp.libraryPathFlag : flag;
+ var paths = collectLibraryPaths(product);
+ return paths.map(function(path) { return flag + path });
+}
+
+function collectLinkerScriptPathsArguments(product, inputs, split, flag) {
+ flag = (flag === undefined) ? product.cpp.linkerScriptFlag : flag;
+ var paths = collectLinkerScriptPaths(inputs);
+ if (split) {
+ var args = [];
+ for (var i = 0; i < paths.length; ++i)
+ args.push(flag, paths[i]);
+ return args;
+ } else {
+ return paths.map(function(path) { return flag + path });
+ }
+}
+
+function collectLinkerObjectPathsArguments(product, inputs, flag) {
+ flag = (flag === undefined) ? "" : flag;
+ var paths = collectLinkerObjectPaths(product);
+ return paths.map(function(path) { return flag + path });
+}
+
+function collectMiscCompilerArguments(input, tag) {
+ return [].concat(ModUtils.moduleProperty(input, "platformFlags"),
+ ModUtils.moduleProperty(input, "flags"),
+ ModUtils.moduleProperty(input, "platformFlags", tag),
+ ModUtils.moduleProperty(input, "flags", tag));
+}
+
+function collectMiscAssemblerArguments(input, tag) {
+ return [].concat(ModUtils.moduleProperty(input, "platformFlags", tag),
+ ModUtils.moduleProperty(input, "flags", tag));
+}
+
+function collectMiscDriverArguments(config) {
+ return [].concat(ModUtils.moduleProperty(config, "platformDriverFlags"),
+ ModUtils.moduleProperty(config, "driverFlags"),
+ ModUtils.moduleProperty(config, "targetDriverFlags"));
+}
+
+function collectMiscLinkerArguments(product) {
+ return [].concat(ModUtils.moduleProperty(product, "driverLinkerFlags"));
+}
+
+function collectMiscEscapableLinkerArguments(product) {
+ return [].concat(ModUtils.moduleProperty(product, "platformLinkerFlags"),
+ ModUtils.moduleProperty(product, "linkerFlags"));
+}
diff --git a/share/qbs/modules/cpp/gcc.js b/share/qbs/modules/cpp/gcc.js
index 51a8ee64a..09ff4981d 100644
--- a/share/qbs/modules/cpp/gcc.js
+++ b/share/qbs/modules/cpp/gcc.js
@@ -261,8 +261,6 @@ function escapeLinkerFlags(product, inputs, linkerFlags) {
}
function linkerFlags(project, product, inputs, outputs, primaryOutput, linkerPath) {
- var libraryPaths = product.cpp.libraryPaths;
- var distributionLibraryPaths = product.cpp.distributionLibraryPaths;
var isDarwin = product.qbs.targetOS.contains("darwin");
var libraryDependencies = collectLibraryDependencies(product, isDarwin);
var frameworks = product.cpp.frameworks;
@@ -403,19 +401,12 @@ function linkerFlags(project, product, inputs, outputs, primaryOutput, linkerPat
args.push("-stdlib=" + stdlib);
// Flags for library search paths
- var allLibraryPaths = [];
- if (libraryPaths)
- allLibraryPaths = allLibraryPaths.uniqueConcat(libraryPaths);
- if (distributionLibraryPaths)
- allLibraryPaths = allLibraryPaths.uniqueConcat(distributionLibraryPaths);
+ var allLibraryPaths = Cpp.collectLibraryPaths(product);
if (systemRunPaths.length > 0)
allLibraryPaths = allLibraryPaths.filter(isNotSystemRunPath);
- args = args.concat(allLibraryPaths.map(function(path) { return '-L' + path }));
+ args = args.concat(allLibraryPaths.map(function(path) { return product.cpp.libraryPathFlag + path }));
- var linkerScripts = inputs.linkerscript
- ? inputs.linkerscript.map(function(a) { return a.filePath; }) : [];
- Array.prototype.push.apply(escapableLinkerFlags, [].uniqueConcat(linkerScripts)
- .map(function(path) { return '-T' + path }));
+ escapableLinkerFlags = escapableLinkerFlags.concat(Cpp.collectLinkerScriptPathsArguments(product, inputs));
var versionScripts = inputs.versionscript
? inputs.versionscript.map(function(a) { return a.filePath; }) : [];
@@ -427,16 +418,14 @@ function linkerFlags(project, product, inputs, outputs, primaryOutput, linkerPat
var useCompilerDriver = useCompilerDriverLinker(product, inputs);
args = args.concat(configFlags(product, useCompilerDriver));
- Array.prototype.push.apply(escapableLinkerFlags, product.cpp.platformLinkerFlags);
- Array.prototype.push.apply(escapableLinkerFlags, product.cpp.linkerFlags);
+ escapableLinkerFlags = escapableLinkerFlags.concat(Cpp.collectMiscEscapableLinkerArguments(product));
// Note: due to the QCC response files hack in prepareLinker(), at least one object file or
// library file must follow the output file path so that QCC has something to process before
// sending the rest of the arguments through the response file.
args.push("-o", primaryOutput.filePath);
- if (inputs.obj)
- args = args.concat(inputs.obj.map(function (obj) { return obj.filePath }));
+ args = args.concat(Cpp.collectLinkerObjectPaths(inputs));
for (i in frameworks) {
frameworkExecutablePath = PathTools.frameworkExecutablePath(frameworks[i]);
@@ -537,9 +526,8 @@ function linkerFlags(project, product, inputs, outputs, primaryOutput, linkerPat
var escapedLinkerFlags = escapeLinkerFlags(product, inputs, escapableLinkerFlags);
Array.prototype.push.apply(escapedLinkerFlags, args);
- var driverLinkerFlags = useCompilerDriver ? product.cpp.driverLinkerFlags : undefined;
- if (driverLinkerFlags)
- Array.prototype.push.apply(escapedLinkerFlags, driverLinkerFlags);
+ if (useCompilerDriver)
+ escapedLinkerFlags = escapedLinkerFlags.concat(Cpp.collectMiscLinkerArguments(product));
return escapedLinkerFlags;
}
@@ -547,11 +535,8 @@ function linkerFlags(project, product, inputs, outputs, primaryOutput, linkerPat
function configFlags(config, isDriver) {
var args = [];
- if (isDriver !== false) {
- args = args.concat(config.cpp.platformDriverFlags);
- args = args.concat(config.cpp.driverFlags);
- args = args.concat(config.cpp.targetDriverFlags);
- }
+ if (isDriver !== false)
+ args = args.concat(Cpp.collectMiscDriverArguments(config));
var frameworkPaths = config.cpp.frameworkPaths;
if (frameworkPaths)
@@ -756,13 +741,6 @@ function standardFallbackValueOrDefault(toolchain, compilerVersion, languageVers
function compilerFlags(project, product, input, output, explicitlyDependsOn) {
var i;
- var includePaths = input.cpp.includePaths;
- var systemIncludePaths = input.cpp.systemIncludePaths;
- var distributionIncludePaths = input.cpp.distributionIncludePaths;
-
- var platformDefines = input.cpp.platformDefines;
- var defines = input.cpp.defines;
-
// Determine which C-language we're compiling
var tag = ModUtils.fileTagForTargetLanguage(input.fileTags.concat(output.fileTags));
if (!["c", "cpp", "objc", "objcpp", "asm_cpp"].contains(tag))
@@ -853,10 +831,7 @@ function compilerFlags(project, product, input, output, explicitlyDependsOn) {
// Only push language arguments if we have to.
Array.prototype.push.apply(args, compilerInfo.language);
- args = args.concat(ModUtils.moduleProperty(input, 'platformFlags'),
- ModUtils.moduleProperty(input, 'flags'),
- ModUtils.moduleProperty(input, 'platformFlags', tag),
- ModUtils.moduleProperty(input, 'flags', tag));
+ args = args.concat(Cpp.collectMiscCompilerArguments(input, tag));
var pchTag = compilerInfo.tag + "_pch";
var pchOutput = output.fileTags.contains(pchTag);
@@ -866,14 +841,10 @@ function compilerFlags(project, product, input, output, explicitlyDependsOn) {
var pchInput = pchInputs[0];
var pchFilePath = FileInfo.joinPaths(FileInfo.path(pchInput.filePath),
pchInput.completeBaseName);
- args.push('-include', pchFilePath);
+ args.push(input.cpp.preincludeFlag, pchFilePath);
}
- var prefixHeaders = input.cpp.prefixHeaders;
- for (i in prefixHeaders) {
- args.push('-include');
- args.push(prefixHeaders[i]);
- }
+ args = args.concat(Cpp.collectPreincludePathsArguments(input));
var positionIndependentCode = input.cpp.positionIndependentCode;
if (positionIndependentCode && !product.qbs.targetOS.contains("windows"))
@@ -883,24 +854,9 @@ function compilerFlags(project, product, input, output, explicitlyDependsOn) {
for (i in cppFlags)
args.push('-Wp,' + cppFlags[i])
- var allDefines = [];
- if (platformDefines)
- allDefines = allDefines.uniqueConcat(platformDefines);
- if (defines)
- allDefines = allDefines.uniqueConcat(defines);
- args = args.concat(allDefines.map(function(define) { return '-D' + define }));
- if (includePaths) {
- args = args.concat([].uniqueConcat(includePaths).map(function(path) {
- return input.cpp.includeFlag + path;
- }));
- }
-
- var allSystemIncludePaths = [];
- if (systemIncludePaths)
- allSystemIncludePaths = allSystemIncludePaths.uniqueConcat(systemIncludePaths);
- if (distributionIncludePaths)
- allSystemIncludePaths = allSystemIncludePaths.uniqueConcat(distributionIncludePaths);
- allSystemIncludePaths.forEach(function(v) { args.push(input.cpp.systemIncludeFlag, v); });
+ args = args.concat(Cpp.collectDefinesArguments(input));
+ args = args.concat(Cpp.collectIncludePathsArguments(input));
+ args = args.concat(Cpp.collectSystemIncludePathsArguments(input));
var minimumWindowsVersion = input.cpp.minimumWindowsVersion;
if (minimumWindowsVersion && product.qbs.targetOS.contains("windows")) {
@@ -908,7 +864,7 @@ function compilerFlags(project, product, input, output, explicitlyDependsOn) {
if (hexVersion) {
var versionDefs = [ 'WINVER', '_WIN32_WINNT', '_WIN32_WINDOWS' ];
for (i in versionDefs)
- args.push('-D' + versionDefs[i] + '=' + hexVersion);
+ args.push(input.cpp.defineFlag + versionDefs[i] + '=' + hexVersion);
}
}
@@ -978,10 +934,6 @@ function languageName(fileTag) {
function prepareAssembler(project, product, inputs, outputs, input, output) {
var assemblerPath = product.cpp.assemblerPath;
- var includePaths = input.cpp.includePaths;
- var systemIncludePaths = input.cpp.systemIncludePaths;
- var distributionIncludePaths = input.cpp.distributionIncludePaths;
-
var args = product.cpp.targetAssemblerFlags;
if (input.cpp.debugInformation)
@@ -992,17 +944,10 @@ function prepareAssembler(project, product, inputs, outputs, input, output) {
args.push('-W');
var tag = "asm";
- args = args.concat(ModUtils.moduleProperty(input, 'platformFlags', tag),
- ModUtils.moduleProperty(input, 'flags', tag));
-
- var allIncludePaths = [];
- if (includePaths)
- allIncludePaths = allIncludePaths.uniqueConcat(includePaths);
- if (systemIncludePaths)
- allIncludePaths = allIncludePaths.uniqueConcat(systemIncludePaths);
- if (distributionIncludePaths)
- allIncludePaths = allIncludePaths.uniqueConcat(distributionIncludePaths);
- args = args.concat(allIncludePaths.map(function(path) { return input.cpp.includeFlag + path }));
+ args = args.concat(Cpp.collectMiscAssemblerArguments(input, tag));
+
+ args = args.concat(Cpp.collectIncludePathsArguments(input));
+ args = args.concat(Cpp.collectSystemIncludePathsArguments(input));
args.push("-o", output.filePath);
args.push(input.filePath);
diff --git a/share/qbs/modules/cpp/iar.js b/share/qbs/modules/cpp/iar.js
index 2d6c36db1..6da431766 100644
--- a/share/qbs/modules/cpp/iar.js
+++ b/share/qbs/modules/cpp/iar.js
@@ -362,6 +362,56 @@ function imageFormat(qbs) {
return (code !== "") ? "ubrof" : "elf";
}
+function libraryPathFlag(qbs) {
+ var architecture = qbs.architecture;
+ if (supportILinker(architecture))
+ return "-L";
+ else if (supportXLinker((architecture)))
+ return "-I";
+ throw "Unable to deduce library path flag for unsupported architecture: '"
+ + architecture + "'";
+}
+
+function linkerScriptFlag(qbs) {
+ var architecture = qbs.architecture;
+ if (supportILinker(architecture))
+ return "--config";
+ else if (supportXLinker((architecture)))
+ return "-f";
+ throw "Unable to deduce linker script flag for unsupported architecture: '"
+ + architecture + "'";
+}
+
+function linkerSilentFlag(qbs) {
+ var architecture = qbs.architecture;
+ if (supportILinker(architecture))
+ return "--silent";
+ else if (supportXLinker(architecture))
+ return "-S";
+ throw "Unable to deduce linker silent flag for unsupported architecture: '"
+ + architecture + "'";
+}
+
+function linkerMapFileFlag(qbs) {
+ var architecture = qbs.architecture;
+ if (supportILinker(architecture))
+ return "--map";
+ else if (supportXLinker(architecture))
+ return "-l";
+ throw "Unable to deduce linker map flag for unsupported architecture: '"
+ + architecture + "'";
+}
+
+function linkerEntryPointFlag(qbs) {
+ var architecture = qbs.architecture;
+ if (supportILinker(architecture))
+ return "--entry";
+ else if (supportXLinker(architecture))
+ return "-s";
+ throw "Unable to deduce linker entry point flag for unsupported architecture: '"
+ + architecture + "'";
+}
+
function guessArmArchitecture(core) {
var arch = "arm";
if (core === "__ARM4M__")
@@ -566,32 +616,15 @@ function compilerFlags(project, product, input, outputs, explicitlyDependsOn) {
// Output.
args.push("-o", outputs.obj[0].filePath);
- var prefixHeaders = input.cpp.prefixHeaders;
- for (var i in prefixHeaders)
- args.push("--preinclude", prefixHeaders[i]);
+ // Preinclude headers.
+ args = args.concat(Cpp.collectPreincludePathsArguments(input, true));
// Defines.
- var allDefines = [];
- var platformDefines = input.cpp.platformDefines;
- if (platformDefines)
- allDefines = allDefines.uniqueConcat(platformDefines);
- var defines = input.cpp.defines;
- if (defines)
- allDefines = allDefines.uniqueConcat(defines);
- args = args.concat(allDefines.map(function(define) { return "-D" + define }));
+ args = args.concat(Cpp.collectDefinesArguments(input));
// Includes.
- var allIncludePaths = [];
- var includePaths = input.cpp.includePaths;
- if (includePaths)
- allIncludePaths = allIncludePaths.uniqueConcat(includePaths);
- var systemIncludePaths = input.cpp.systemIncludePaths;
- if (systemIncludePaths)
- allIncludePaths = allIncludePaths.uniqueConcat(systemIncludePaths);
- var distributionIncludePaths = input.cpp.distributionIncludePaths;
- if (distributionIncludePaths)
- allIncludePaths = allIncludePaths.uniqueConcat(distributionIncludePaths);
- args = args.concat(allIncludePaths.map(function(include) { return "-I" + include }));
+ args = args.concat(Cpp.collectIncludePathsArguments(input));
+ args = args.concat(Cpp.collectSystemIncludePathsArguments(input));
// Silent output generation flag.
args.push("--silent");
@@ -679,11 +712,8 @@ function compilerFlags(project, product, input, outputs, explicitlyDependsOn) {
args.push("-l", outputs.lst[0].filePath);
// Misc flags.
- args = args.concat(ModUtils.moduleProperty(input, "platformFlags"),
- ModUtils.moduleProperty(input, "flags"),
- ModUtils.moduleProperty(input, "platformFlags", tag),
- ModUtils.moduleProperty(input, "flags", tag),
- ModUtils.moduleProperty(input, "driverFlags", tag));
+ args = args.concat(Cpp.collectMiscCompilerArguments(input, tag),
+ Cpp.collectMiscDriverArguments(product));
return args;
}
@@ -703,21 +733,12 @@ function assemblerFlags(project, product, input, outputs, explicitlyDependsOn) {
// The `--preinclude` flag is only supported for a certain
// set of assemblers, not for all.
- if (supportIAssembler(architecture)) {
- var prefixHeaders = input.cpp.prefixHeaders;
- for (var i in prefixHeaders)
- args.push("--preinclude", prefixHeaders[i]);
- }
+ if (supportIAssembler(architecture))
+ args = args.concat(Cpp.collectPreincludePathsArguments(input));
// Includes.
- var allIncludePaths = [];
- var systemIncludePaths = input.cpp.systemIncludePaths;
- if (systemIncludePaths)
- allIncludePaths = allIncludePaths.uniqueConcat(systemIncludePaths);
- var distributionIncludePaths = input.cpp.distributionIncludePaths;
- if (distributionIncludePaths)
- allIncludePaths = allIncludePaths.uniqueConcat(distributionIncludePaths);
- args = args.concat(allIncludePaths.map(function(include) { return "-I" + include }));
+ args = args.concat(Cpp.collectIncludePathsArguments(input));
+ args = args.concat(Cpp.collectSystemIncludePathsArguments(input));
// Debug information flags.
if (input.cpp.debugInformation)
@@ -749,8 +770,7 @@ function assemblerFlags(project, product, input, outputs, explicitlyDependsOn) {
args.push("-l", outputs.lst[0].filePath);
// Misc flags.
- args = args.concat(ModUtils.moduleProperty(input, "platformFlags", tag),
- ModUtils.moduleProperty(input, "flags", tag));
+ args = args.concat(Cpp.collectMiscAssemblerArguments(input, tag));
return args;
}
@@ -758,63 +778,41 @@ function linkerFlags(project, product, inputs, outputs) {
var args = [];
// Inputs.
- if (inputs.obj)
- args = args.concat(inputs.obj.map(function(obj) { return obj.filePath }));
+ args = args.concat(Cpp.collectLinkerObjectPaths(inputs));
// Output.
args.push("-o", outputs.application[0].filePath);
// Library paths.
- var allLibraryPaths = [];
- var libraryPaths = product.cpp.libraryPaths;
- if (libraryPaths)
- allLibraryPaths = allLibraryPaths.uniqueConcat(libraryPaths);
- var distributionLibraryPaths = product.cpp.distributionLibraryPaths;
- if (distributionLibraryPaths)
- allLibraryPaths = allLibraryPaths.uniqueConcat(distributionLibraryPaths);
+ args = args.concat(Cpp.collectLibraryPathsArguments(product));
// Library dependencies.
- var libraryDependencies = Cpp.collectLibraryDependencies(product);
- if (libraryDependencies)
- args = args.concat(libraryDependencies.map(function(dep) { return dep.filePath }));
+ args = args.concat(Cpp.collectLibraryDependenciesArguments(product));
// Linker scripts.
- var linkerScripts = inputs.linkerscript
- ? inputs.linkerscript.map(function(a) { return a.filePath; }) : [];
+ args = args.concat(Cpp.collectLinkerScriptPathsArguments(product, inputs));
- // Architecture specific flags.
- var architecture = product.qbs.architecture;
- if (supportILinker(architecture)) {
- args = args.concat(allLibraryPaths.map(function(path) { return '-L' + path }));
- // Silent output generation flag.
- args.push("--silent");
- // Map file generation flag.
- if (product.cpp.generateLinkerMapFile)
- args.push("--map", outputs.mem_map[0].filePath);
- // Entry point flag.
- if (product.cpp.entryPoint)
- args.push("--entry", product.cpp.entryPoint);
- // Linker scripts flags.
- linkerScripts.forEach(function(script) { args.push("--config", script); });
- } else if (supportXLinker(architecture)) {
- args = args.concat(allLibraryPaths.map(function(path) { return '-I' + path }));
- // Silent output generation flag.
- args.push("-S");
- // Debug information flag.
+ // Silent output generation flag.
+ args.push(linkerSilentFlag(product.qbs));
+
+ // Map file generation flag.
+ if (product.cpp.generateLinkerMapFile)
+ args.push(linkerMapFileFlag(product.qbs), outputs.mem_map[0].filePath);
+
+ // Entry point flag.
+ if (product.cpp.entryPoint)
+ args.push(linkerEntryPointFlag(product.qbs), product.cpp.entryPoint);
+
+ // Debug information flag.
+ if (supportXLinker(product.qbs.architecture)) {
if (product.cpp.debugInformation)
args.push("-rt");
- // Map file generation flag.
- if (product.cpp.generateLinkerMapFile)
- args.push("-l", outputs.mem_map[0].filePath);
- // Entry point flag.
- if (product.cpp.entryPoint)
- args.push("-s", product.cpp.entryPoint);
- // Linker scripts flags.
- linkerScripts.forEach(function(script) { args.push("-f", script); });
}
// Misc flags.
- args = args.concat(ModUtils.moduleProperty(product, "driverLinkerFlags"));
+ args = args.concat(Cpp.collectMiscEscapableLinkerArguments(product),
+ Cpp.collectMiscLinkerArguments(product),
+ Cpp.collectMiscDriverArguments(product));
return args;
}
@@ -822,8 +820,7 @@ function archiverFlags(project, product, inputs, outputs) {
var args = [];
// Inputs.
- if (inputs.obj)
- args = args.concat(inputs.obj.map(function(obj) { return obj.filePath }));
+ args = args.concat(Cpp.collectLinkerObjectPaths(inputs));
// Output.
var architecture = product.qbs.architecture;
diff --git a/share/qbs/modules/cpp/iar.qbs b/share/qbs/modules/cpp/iar.qbs
index 787ffa2cf..8209c3e57 100644
--- a/share/qbs/modules/cpp/iar.qbs
+++ b/share/qbs/modules/cpp/iar.qbs
@@ -95,6 +95,14 @@ CppModule {
enableExceptions: false
enableRtti: false
+ defineFlag: "-D"
+ includeFlag: "-I"
+ systemIncludeFlag: "-I"
+ preincludeFlag: "--preinclude"
+ libraryDependencyFlag: ""
+ libraryPathFlag: IAR.libraryPathFlag(qbs)
+ linkerScriptFlag: IAR.linkerScriptFlag(qbs)
+
Rule {
id: assembler
inputs: ["asm"]
diff --git a/share/qbs/modules/cpp/keil.js b/share/qbs/modules/cpp/keil.js
index 8b0902d6f..54d97944f 100644
--- a/share/qbs/modules/cpp/keil.js
+++ b/share/qbs/modules/cpp/keil.js
@@ -532,25 +532,6 @@ function compilerFlags(project, product, input, outputs, explicitlyDependsOn) {
var tag = ModUtils.fileTagForTargetLanguage(input.fileTags.concat(outputs.obj[0].fileTags));
var args = [];
- var allDefines = [];
- var platformDefines = input.cpp.platformDefines;
- if (platformDefines)
- allDefines = allDefines.uniqueConcat(platformDefines);
- var defines = input.cpp.defines;
- if (defines)
- allDefines = allDefines.uniqueConcat(defines);
-
- var allIncludePaths = [];
- var includePaths = input.cpp.includePaths;
- if (includePaths)
- allIncludePaths = allIncludePaths.uniqueConcat(includePaths);
- var systemIncludePaths = input.cpp.systemIncludePaths;
- if (systemIncludePaths)
- allIncludePaths = allIncludePaths.uniqueConcat(systemIncludePaths);
- var distributionIncludePaths = input.cpp.distributionIncludePaths;
- if (distributionIncludePaths)
- allIncludePaths = allIncludePaths.uniqueConcat(distributionIncludePaths);
-
var architecture = input.qbs.architecture;
if (isMcsArchitecture(architecture) || isC166Architecture(architecture)) {
// Input.
@@ -560,10 +541,13 @@ function compilerFlags(project, product, input, outputs, explicitlyDependsOn) {
args.push("OBJECT (" + outputs.obj[0].filePath + ")");
// Defines.
- if (allDefines.length > 0)
- args = args.concat("DEFINE (" + allDefines.join(",") + ")");
+ var defines = Cpp.collectDefines(input);
+ if (defines.length > 0)
+ args = args.concat("DEFINE (" + defines.join(",") + ")");
// Includes.
+ var allIncludePaths = [].concat(Cpp.collectIncludePaths(input),
+ Cpp.collectSystemIncludePaths(input));
if (allIncludePaths.length > 0)
args = args.concat("INCDIR (" + allIncludePaths.join(";") + ")");
@@ -604,17 +588,19 @@ function compilerFlags(project, product, input, outputs, explicitlyDependsOn) {
} else if (isArmArchitecture(architecture)) {
// Input.
args.push("-c", input.filePath);
+
// Output.
args.push("-o", outputs.obj[0].filePath);
+ // Preinclude headers.
+ args = args.concat(Cpp.collectPreincludePathsArguments(input, true));
+
// Defines.
- args = args.concat(allDefines.map(function(define) { return '-D' + define }));
- // Includes.
- args = args.concat(allIncludePaths.map(function(include) { return '-I' + include }));
+ args = args.concat(Cpp.collectDefinesArguments(input));
- var prefixHeaders = input.cpp.prefixHeaders;
- for (var i in prefixHeaders)
- args.push(input.cpp.preincludeFlag, prefixHeaders[i]);
+ // Includes.
+ args = args.concat(Cpp.collectIncludePathsArguments(input));
+ args = args.concat(Cpp.collectSystemIncludePathsArguments(input));
var compilerPath = input.cpp.compilerPath;
if (isArmCCCompiler(compilerPath)) {
@@ -753,11 +739,8 @@ function compilerFlags(project, product, input, outputs, explicitlyDependsOn) {
}
// Misc flags.
- args = args.concat(ModUtils.moduleProperty(input, "platformFlags"),
- ModUtils.moduleProperty(input, "flags"),
- ModUtils.moduleProperty(input, "platformFlags", tag),
- ModUtils.moduleProperty(input, "flags", tag),
- ModUtils.moduleProperty(input, "driverFlags", tag));
+ args = args.concat(Cpp.collectMiscCompilerArguments(input, tag),
+ Cpp.collectMiscDriverArguments(input));
return args;
}
@@ -766,25 +749,6 @@ function assemblerFlags(project, product, input, outputs, explicitlyDependsOn) {
var tag = ModUtils.fileTagForTargetLanguage(input.fileTags.concat(outputs.obj[0].fileTags));
var args = [];
- var allDefines = [];
- var platformDefines = input.cpp.platformDefines;
- if (platformDefines)
- allDefines = allDefines.uniqueConcat(platformDefines);
- var defines = input.cpp.defines;
- if (defines)
- allDefines = allDefines.uniqueConcat(defines);
-
- var allIncludePaths = [];
- var includePaths = input.cpp.includePaths;
- if (includePaths)
- allIncludePaths = allIncludePaths.uniqueConcat(includePaths);
- var systemIncludePaths = input.cpp.systemIncludePaths;
- if (systemIncludePaths)
- allIncludePaths = allIncludePaths.uniqueConcat(systemIncludePaths);
- var distributionIncludePaths = input.cpp.distributionIncludePaths;
- if (distributionIncludePaths)
- allIncludePaths = allIncludePaths.uniqueConcat(distributionIncludePaths);
-
var architecture = input.qbs.architecture;
if (isMcsArchitecture(architecture) || isC166Architecture(architecture)) {
// Input.
@@ -793,13 +757,11 @@ function assemblerFlags(project, product, input, outputs, explicitlyDependsOn) {
// Output.
args.push("OBJECT (" + outputs.obj[0].filePath + ")");
- // Defines.
- if (allDefines.length > 0)
- args = args.concat("DEFINE (" + allDefines.join(",") + ")");
-
// Includes.
+ var allIncludePaths = [].concat(Cpp.collectIncludePaths(input),
+ Cpp.collectSystemIncludePaths(input));
if (allIncludePaths.length > 0)
- args = args.concat("INCDIR (" + adjusted.join(";") + ")");
+ args = args.concat("INCDIR (" + allIncludePaths.join(";") + ")");
// Debug information flags.
if (input.cpp.debugInformation)
@@ -820,20 +782,9 @@ function assemblerFlags(project, product, input, outputs, explicitlyDependsOn) {
// Output.
args.push("-o", outputs.obj[0].filePath);
- // Defines.
- allDefines.forEach(function(define) {
- var parts = define.split("=");
- args.push("--pd");
- if (parts[1] === undefined)
- args.push(parts[0] + " SETA " + 1);
- else if (parts[1].contains("\""))
- args.push(parts[0] + " SETS " + parts[1]);
- else
- args.push(parts[0] + " SETA " + parts[1]);
- });
-
// Includes.
- args = args.concat(allIncludePaths.map(function(include) { return '-I' + include }));
+ args = args.concat(Cpp.collectIncludePathsArguments(input));
+ args = args.concat(Cpp.collectSystemIncludePathsArguments(input));
// Debug information flags.
if (input.cpp.debugInformation) {
@@ -856,8 +807,7 @@ function assemblerFlags(project, product, input, outputs, explicitlyDependsOn) {
}
// Misc flags.
- args = args.concat(ModUtils.moduleProperty(input, "platformFlags", tag),
- ModUtils.moduleProperty(input, "flags", tag));
+ args = args.concat(Cpp.collectMiscAssemblerArguments(input, tag));
return args;
}
@@ -871,39 +821,39 @@ function disassemblerFlags(project, product, input, outputs, explicitlyDependsOn
function linkerFlags(project, product, inputs, outputs) {
var args = [];
- // Library paths.
- var libraryPaths = product.cpp.libraryPaths;
+ var libraryPaths = Cpp.collectLibraryPaths(product);
var architecture = product.qbs.architecture;
if (isMcsArchitecture(architecture) || isC166Architecture(architecture)) {
+ // Semi-intelligent handling the library paths.
+ // We need to add the full path prefix to the library file if this
+ // file is not absolute or not relative. Reason is that the C51, C251,
+ // and C166 linkers does not support the library paths.
+ function collectLibraryObjectPaths(product) {
+ var libraryObjects = Cpp.collectLibraryDependencies(product);
+ return libraryObjects.map(function(dep) {
+ var filePath = dep.filePath;
+ if (FileInfo.isAbsolutePath(filePath))
+ return filePath;
+ for (var i = 0; i < libraryPaths.length; ++i) {
+ var fullPath = FileInfo.joinPaths(libraryPaths[i], filePath);
+ if (File.exists(fullPath))
+ return fullPath;
+ }
+ return filePath;
+ });
+ }
+
// Note: The C51, C251, or C166 linker does not distinguish an object files and
// a libraries, it interpret all this stuff as an input objects,
// so, we need to pass it together in one string.
- var allObjectPaths = [];
-
- // Inputs.
- if (inputs.obj)
- inputs.obj.map(function(obj) { allObjectPaths.push(obj.filePath) });
-
- // Library dependencies.
- var libraryObjects = Cpp.collectLibraryDependencies(product);
- allObjectPaths = allObjectPaths.concat(libraryObjects.map(function(lib) {
- // Semi-intelligent handling the library paths.
- // We need to add the full path prefix to the library file if this
- // file is not absolute or not relative. Reason is that the C51, C251,
- // and C166 linkers does not support the library paths.
- var filePath = lib.filePath;
- if (FileInfo.isAbsolutePath(filePath))
- return filePath;
- for (var i = 0; i < libraryPaths.length; ++i) {
- var fullPath = FileInfo.joinPaths(libraryPaths[i], filePath);
- if (File.exists(fullPath))
- return fullPath;
- }
- return filePath;
- }));
+ function collectAllObjectPathsArguments(product, inputs) {
+ return [].concat(Cpp.collectLinkerObjectPaths(inputs),
+ collectLibraryObjectPaths(product));
+ }
// Add all input objects as arguments (application and library object files).
+ var allObjectPaths = collectAllObjectPathsArguments(product, inputs);
if (allObjectPaths.length > 0)
args = args.concat(allObjectPaths.join(","));
@@ -917,23 +867,20 @@ function linkerFlags(project, product, inputs, outputs) {
args.push("PRINT(" + outputs.mem_map[0].filePath + ")");
} else if (isArmArchitecture(architecture)) {
// Inputs.
- if (inputs.obj)
- args = args.concat(inputs.obj.map(function(obj) { return obj.filePath }));
+ args = args.concat(Cpp.collectLinkerObjectPaths(inputs));
// Output.
args.push("--output", outputs.application[0].filePath);
- if (libraryPaths)
- args.push("--userlibpath=" + libraryPaths.join(","));
+ // Library paths.
+ if (libraryPaths.length > 0)
+ args.push(product.cpp.libraryPathFlag + libraryPaths.join(","));
// Library dependencies.
- var libraryDependencies = Cpp.collectLibraryDependencies(product);
- args = args.concat(libraryDependencies.map(function(dep) { return dep.filePath; }));
+ args = args.concat(Cpp.collectLibraryDependenciesArguments(product));
- // Debug information flag.
- var debugInformation = product.cpp.debugInformation;
- if (debugInformation !== undefined)
- args.push(debugInformation ? "--debug" : "--no_debug");
+ // Linker scripts.
+ args = args.concat(Cpp.collectLinkerScriptPathsArguments(product, inputs));
// Map file generation flag.
if (product.cpp.generateLinkerMapFile)
@@ -943,37 +890,33 @@ function linkerFlags(project, product, inputs, outputs) {
if (product.cpp.entryPoint)
args.push("--entry", product.cpp.entryPoint);
- // Linker scripts flags.
- var linkerScripts = inputs.linkerscript
- ? inputs.linkerscript.map(function(a) { return a.filePath; }) : [];
- linkerScripts.forEach(function(script) { args.push("--scatter", script); });
+ // Debug information flag.
+ var debugInformation = product.cpp.debugInformation;
+ if (debugInformation !== undefined)
+ args.push(debugInformation ? "--debug" : "--no_debug");
}
// Misc flags.
- args = args.concat(ModUtils.moduleProperty(product, "driverLinkerFlags"));
+ args = args.concat(Cpp.collectMiscEscapableLinkerArguments(product),
+ Cpp.collectMiscLinkerArguments(product),
+ Cpp.collectMiscDriverArguments(product));
return args;
}
function archiverFlags(project, product, inputs, outputs) {
var args = [];
+ // Inputs.
+ var objectPaths = Cpp.collectLinkerObjectPaths(inputs);
+
var architecture = product.qbs.architecture;
if (isMcsArchitecture(architecture) || isC166Architecture(architecture)) {
// Library creation command.
args.push("TRANSFER");
- var allObjectPaths = [];
- function addObjectPath(obj) {
- allObjectPaths.push(obj.filePath);
- }
-
// Inputs.
- if (inputs.obj)
- inputs.obj.map(function(obj) { addObjectPath(obj) });
-
- // Add all input objects as arguments.
- if (allObjectPaths.length > 0)
- args = args.concat(allObjectPaths.join(","));
+ if (objectPaths.length > 0)
+ args = args.concat(objectPaths.join(","));
// Output.
args.push("TO", outputs.staticlibrary[0].filePath);
@@ -985,8 +928,7 @@ function archiverFlags(project, product, inputs, outputs) {
args.push("--create", outputs.staticlibrary[0].filePath);
// Inputs.
- if (inputs.obj)
- args = args.concat(inputs.obj.map(function(obj) { return obj.filePath }));
+ args = args.concat(objectPaths);
// Debug information flag.
if (product.cpp.debugInformation)
diff --git a/share/qbs/modules/cpp/keil.qbs b/share/qbs/modules/cpp/keil.qbs
index ba883c515..eeab4e9a0 100644
--- a/share/qbs/modules/cpp/keil.qbs
+++ b/share/qbs/modules/cpp/keil.qbs
@@ -97,7 +97,13 @@ CppModule {
enableExceptions: false
enableRtti: false
- property string preincludeFlag: KEIL.preincludeFlag(compilerPath)
+ defineFlag: "-D"
+ includeFlag: "-I"
+ systemIncludeFlag: "-I"
+ preincludeFlag: KEIL.preincludeFlag(compilerPath)
+ libraryDependencyFlag: ""
+ libraryPathFlag: "--userlibpath="
+ linkerScriptFlag: "--scatter"
Rule {
id: assembler
diff --git a/share/qbs/modules/cpp/msvc.js b/share/qbs/modules/cpp/msvc.js
index 9f3d20282..d912a7f8c 100644
--- a/share/qbs/modules/cpp/msvc.js
+++ b/share/qbs/modules/cpp/msvc.js
@@ -188,9 +188,7 @@ function prepareCompiler(project, product, inputs, outputs, input, output, expli
args.push(rtl);
}
- var driverFlags = product.cpp.driverFlags;
- if (driverFlags)
- args = args.concat(driverFlags);
+ args = args.concat(Cpp.collectMiscDriverArguments(product));
// warnings:
var warningLevel = input.cpp.warningLevel;
@@ -200,37 +198,26 @@ function prepareCompiler(project, product, inputs, outputs, input, output, expli
args.push('/Wall')
if (input.cpp.treatWarningsAsErrors)
args.push('/WX')
- var includePaths = input.cpp.includePaths;
- if (includePaths) {
- args = args.concat([].uniqueConcat(includePaths).map(function(path) {
- return '/I' + FileInfo.toWindowsSeparators(path);
- }));
- }
- var allSystemIncludePaths = [];
- var systemIncludePaths = input.cpp.systemIncludePaths;
- if (systemIncludePaths)
- allSystemIncludePaths = allSystemIncludePaths.uniqueConcat(systemIncludePaths);
- var distributionIncludePaths = input.cpp.distributionIncludePaths;
- if (distributionIncludePaths)
- allSystemIncludePaths = allSystemIncludePaths.uniqueConcat(distributionIncludePaths);
- var includeFlag = "/I";
+ var includePaths = Cpp.collectIncludePaths(input);
+ args = args.concat([].uniqueConcat(includePaths).map(function(path) {
+ return input.cpp.includeFlag + FileInfo.toWindowsSeparators(path);
+ }));
+
+ var includeFlag = input.cpp.includeFlag;
if (supportsExternalIncludesOption(input)) {
args.push("/experimental:external");
- includeFlag = "/external:I"
+ includeFlag = input.cpp.systemIncludeFlag;
}
- allSystemIncludePaths.forEach(function(path) {
- args.push(includeFlag, FileInfo.toWindowsSeparators(path)); });
+ var systemIncludePaths = Cpp.collectSystemIncludePaths(input);
+ args = args.concat([].uniqueConcat(systemIncludePaths).map(function(path) {
+ return includeFlag + FileInfo.toWindowsSeparators(path);
+ }));
- var allDefines = [];
- var platformDefines = input.cpp.platformDefines;
- if (platformDefines)
- allDefines = allDefines.uniqueConcat(platformDefines);
- var defines = input.cpp.defines;
- if (defines)
- allDefines = allDefines.uniqueConcat(defines);
- for (i in allDefines)
- args.push('/D' + allDefines[i].replace(/%/g, "%%"));
+ var defines = Cpp.collectDefines(input);
+ args = args.concat([].uniqueConcat(defines).map(function(define) {
+ return input.cpp.defineFlag + define.replace(/%/g, "%%");
+ }));
var minimumWindowsVersion = product.cpp.minimumWindowsVersion;
if (minimumWindowsVersion) {
@@ -238,7 +225,7 @@ function prepareCompiler(project, product, inputs, outputs, input, output, expli
if (hexVersion) {
var versionDefs = [ 'WINVER', '_WIN32_WINNT', '_WIN32_WINDOWS' ];
for (i in versionDefs) {
- args.push('/D' + versionDefs[i] + '=' + hexVersion);
+ args.push(input.cpp.defineFlag + versionDefs[i] + '=' + hexVersion);
}
}
}
@@ -254,9 +241,10 @@ function prepareCompiler(project, product, inputs, outputs, input, output, expli
args.push('/Fo' + FileInfo.toWindowsSeparators(objOutput.filePath))
args.push(FileInfo.toWindowsSeparators(input.filePath))
- var prefixHeaders = product.cpp.prefixHeaders;
- for (i in prefixHeaders)
- args.push("/FI" + FileInfo.toWindowsSeparators(prefixHeaders[i]));
+ var preincludePaths = Cpp.collectPreincludePaths(input);
+ args = args.concat([].uniqueConcat(preincludePaths).map(function(path) {
+ return input.cpp.preincludeFlag + FileInfo.toWindowsSeparators(path);
+ }));
// Language
if (tag === "cpp") {
@@ -301,10 +289,7 @@ function prepareCompiler(project, product, inputs, outputs, input, output, expli
}
}
- args = args.concat(ModUtils.moduleProperty(input, 'platformFlags'),
- ModUtils.moduleProperty(input, 'flags'),
- ModUtils.moduleProperty(input, 'platformFlags', tag),
- ModUtils.moduleProperty(input, 'flags', tag));
+ args = args.concat(Cpp.collectMiscCompilerArguments(input, tag));
var compilerPath = product.cpp.compilerPath;
var wrapperArgs = product.cpp.compilerWrapper;
@@ -435,19 +420,14 @@ function prepareLinker(project, product, inputs, outputs, input, output) {
if (useCompilerDriver) {
args.push('/nologo');
- var driverFlags = product.cpp.driverFlags;
- if (driverFlags)
- args = args.concat(driverFlags);
- var driverLinkerFlags = product.cpp.driverLinkerFlags;
- if (driverLinkerFlags)
- args = args.concat(driverLinkerFlags);
+ args = args.concat(Cpp.collectMiscDriverArguments(product),
+ Cpp.collectMiscLinkerArguments(product));
}
- var allInputs = inputs.obj || [];
- for (i in allInputs) {
- var fileName = FileInfo.toWindowsSeparators(allInputs[i].filePath)
- args.push(fileName)
- }
+ var allInputs = Cpp.collectLinkerObjectPaths(inputs);
+ args = args.concat([].uniqueConcat(allInputs).map(function(path) {
+ return FileInfo.toWindowsSeparators(path);
+ }));
var linkerArgs = ['/nologo']
if (linkDLL) {
@@ -581,12 +561,12 @@ function prepareLinker(project, product, inputs, outputs, input, output) {
args.push('/Fe' + linkerOutputNativeFilePath);
else
linkerArgs.push('/OUT:' + linkerOutputNativeFilePath);
- var libraryPaths = product.cpp.libraryPaths;
- if (libraryPaths)
- libraryPaths = [].uniqueConcat(libraryPaths);
- for (i in libraryPaths) {
- linkerArgs.push('/LIBPATH:' + FileInfo.toWindowsSeparators(libraryPaths[i]))
- }
+
+ var libraryPaths = Cpp.collectLibraryPaths(product);
+ linkerArgs = linkerArgs.concat([].uniqueConcat(libraryPaths).map(function(path) {
+ return product.cpp.libraryPathFlag + FileInfo.toWindowsSeparators(path);
+ }));
+
handleDiscardProperty(product, linkerArgs);
var linkerFlags = product.cpp.platformLinkerFlags.concat(product.cpp.linkerFlags);
linkerArgs = linkerArgs.concat(linkerFlags);
diff --git a/share/qbs/modules/cpp/sdcc.js b/share/qbs/modules/cpp/sdcc.js
index 804ae534e..c78cae23a 100644
--- a/share/qbs/modules/cpp/sdcc.js
+++ b/share/qbs/modules/cpp/sdcc.js
@@ -239,9 +239,6 @@ function extraApplicationLinkerOutputArtifacts(product) {
}
function compilerFlags(project, product, input, outputs, explicitlyDependsOn) {
- // Determine which C-language we"re compiling.
- var tag = ModUtils.fileTagForTargetLanguage(input.fileTags.concat(outputs.obj[0].fileTags));
-
var args = [];
var escapablePreprocessorFlags = [];
@@ -252,37 +249,19 @@ function compilerFlags(project, product, input, outputs, explicitlyDependsOn) {
args.push("-c");
args.push("-o", outputs.obj[0].filePath);
- var prefixHeaders = input.cpp.prefixHeaders;
- for (var i in prefixHeaders)
- escapablePreprocessorFlags.push("-include " + prefixHeaders[i]);
+ // Prefix headers.
+ escapablePreprocessorFlags = escapablePreprocessorFlags.concat(
+ Cpp.collectPreincludePathsArguments(input));
// Defines.
- var allDefines = [];
- var platformDefines = input.cpp.platformDefines;
- if (platformDefines)
- allDefines = allDefines.uniqueConcat(platformDefines);
- var defines = input.cpp.defines;
- if (defines)
- allDefines = allDefines.uniqueConcat(defines);
- args = args.concat(allDefines.map(function(define) { return "-D" + define }));
+ args = args.concat(Cpp.collectDefinesArguments(input));
// Includes.
- var includePaths = input.cpp.includePaths;
- if (includePaths) {
- args = args.concat([].uniqueConcat(includePaths).map(function(path) {
- return "-I" + path; }));
- }
-
- var allSystemIncludePaths = [];
- var systemIncludePaths = input.cpp.systemIncludePaths;
- if (systemIncludePaths)
- allSystemIncludePaths = allSystemIncludePaths.uniqueConcat(systemIncludePaths);
- var distributionIncludePaths = input.cpp.distributionIncludePaths;
- if (distributionIncludePaths)
- allSystemIncludePaths = allSystemIncludePaths.uniqueConcat(distributionIncludePaths);
+ args = args.concat(Cpp.collectIncludePathsArguments(input));
escapablePreprocessorFlags = escapablePreprocessorFlags.concat(
- allSystemIncludePaths.map(function(include) { return "-isystem " + include }));
+ Cpp.collectSystemIncludePathsArguments(input));
+ // Target MCU flag.
var targetFlag = targetArchitectureFlag(input.cpp.architecture);
if (targetFlag)
args.push(targetFlag);
@@ -315,6 +294,9 @@ function compilerFlags(project, product, input, outputs, explicitlyDependsOn) {
if (input.cpp.treatWarningsAsErrors)
args.push("--Werror");
+ // Determine which C-language we"re compiling.
+ var tag = ModUtils.fileTagForTargetLanguage(input.fileTags.concat(outputs.obj[0].fileTags));
+
// C language version flags.
if (tag === "c") {
var knownValues = ["c11", "c99", "c89"];
@@ -333,46 +315,28 @@ function compilerFlags(project, product, input, outputs, explicitlyDependsOn) {
}
}
- // Misc flags.
- escapablePreprocessorFlags = escapablePreprocessorFlags.uniqueConcat(input.cpp.cppFlags);
var escapedPreprocessorFlags = escapePreprocessorFlags(escapablePreprocessorFlags);
if (escapedPreprocessorFlags)
Array.prototype.push.apply(args, escapedPreprocessorFlags);
- args = args.concat(ModUtils.moduleProperty(input, "platformFlags"),
- ModUtils.moduleProperty(input, "flags"),
- ModUtils.moduleProperty(input, "platformFlags", tag),
- ModUtils.moduleProperty(input, "flags", tag),
- ModUtils.moduleProperty(input, "driverFlags", tag));
-
+ // Misc flags.
+ args = args.concat(Cpp.collectMiscCompilerArguments(input, tag),
+ Cpp.collectMiscDriverArguments(input));
return args;
}
function assemblerFlags(project, product, input, outputs, explicitlyDependsOn) {
- // Determine which C-language we"re compiling
- var tag = ModUtils.fileTagForTargetLanguage(input.fileTags.concat(outputs.obj[0].fileTags));
-
var args = [];
// Includes.
- var includePaths = input.cpp.includePaths;
- if (includePaths) {
- args = args.concat([].uniqueConcat(includePaths).map(function(path) {
- return "-I" + path; }));
- }
+ args = args.concat(Cpp.collectIncludePathsArguments(input));
+ args = args.concat(Cpp.collectSystemIncludePathsArguments(input, input.cpp.includeFlag));
- var allSystemIncludePaths = [];
- var systemIncludePaths = input.cpp.systemIncludePaths;
- if (systemIncludePaths)
- allSystemIncludePaths = allSystemIncludePaths.uniqueConcat(systemIncludePaths);
- var distributionIncludePaths = input.cpp.distributionIncludePaths;
- if (distributionIncludePaths)
- allSystemIncludePaths = allSystemIncludePaths.uniqueConcat(distributionIncludePaths);
- args = args.concat(allSystemIncludePaths.map(function(include) { return "-I" + include }));
+ // Determine which C-language we"re compiling.
+ var tag = ModUtils.fileTagForTargetLanguage(input.fileTags.concat(outputs.obj[0].fileTags));
// Misc flags.
- args = args.concat(ModUtils.moduleProperty(input, "platformFlags", tag),
- ModUtils.moduleProperty(input, "flags", tag));
+ args = args.concat(Cpp.collectMiscCompilerArguments(input, tag));
args.push("-ol");
args.push(outputs.obj[0].filePath);
@@ -388,82 +352,53 @@ function linkerFlags(project, product, inputs, outputs) {
if (targetFlag)
args.push(targetFlag);
- var allLibraryPaths = [];
- var libraryPaths = product.cpp.libraryPaths;
- if (libraryPaths)
- allLibraryPaths = allLibraryPaths.uniqueConcat(libraryPaths);
- var distributionLibraryPaths = product.cpp.distributionLibraryPaths;
- if (distributionLibraryPaths)
- allLibraryPaths = allLibraryPaths.uniqueConcat(distributionLibraryPaths);
-
- var libraryDependencies = Cpp.collectLibraryDependencies(product);
-
var escapableLinkerFlags = [];
// Map file generation flag.
if (product.cpp.generateLinkerMapFile)
escapableLinkerFlags.push("-m");
- if (product.cpp.platformLinkerFlags)
- Array.prototype.push.apply(escapableLinkerFlags, product.cpp.platformLinkerFlags);
- if (product.cpp.linkerFlags)
- Array.prototype.push.apply(escapableLinkerFlags, product.cpp.linkerFlags);
+ escapableLinkerFlags = escapableLinkerFlags.concat(Cpp.collectMiscEscapableLinkerArguments(product));
var useCompilerDriver = useCompilerDriverLinker(product);
- if (useCompilerDriver) {
- // Output.
- args.push("-o", outputs.application[0].filePath);
-
- // Inputs.
- if (inputs.obj)
- args = args.concat(inputs.obj.map(function(obj) { return obj.filePath }));
-
- // Library paths.
- args = args.concat(allLibraryPaths.map(function(path) { return "-L" + path }));
-
- // Linker scripts.
- var scripts = inputs.linkerscript
- ? inputs.linkerscript.map(function(scr) { return "-f" + scr.filePath; }) : [];
- if (scripts)
- Array.prototype.push.apply(escapableLinkerFlags, scripts);
- } else {
- // Output.
- args.push(outputs.application[0].filePath);
-
- // Inputs.
- if (inputs.obj)
- args = args.concat(inputs.obj.map(function(obj) { return obj.filePath }));
-
- // Library paths.
- args = args.concat(allLibraryPaths.map(function(path) { return "-k" + path }));
-
- // Linker scripts.
- // Note: We need to split the '-f' and the file path to separate
- // lines; otherwise the linking fails.
- inputs.linkerscript.forEach(function(scr) {
- escapableLinkerFlags.push("-f", scr.filePath);
- });
- }
+
+ // Output.
+ if (useCompilerDriver)
+ args.push("-o");
+ args.push(outputs.application[0].filePath);
+
+ // Inputs.
+ args = args.concat(Cpp.collectLinkerObjectPaths(inputs));
+
+ // Library paths.
+ var libraryPathFlag = useCompilerDriver ? "-L" : "-k";
+ args = args.concat(Cpp.collectLibraryPathsArguments(product, libraryPathFlag));
+
+ // Linker scripts.
+ // Note: We need to split the '-f' flag and the file path to separate
+ // lines when we don't use the compiler driver mode.
+ escapableLinkerFlags = escapableLinkerFlags.concat(
+ Cpp.collectLinkerScriptPathsArguments(product, inputs, !useCompilerDriver));
// Library dependencies.
- if (libraryDependencies)
- args = args.concat(libraryDependencies.map(function(dep) { return "-l" + dep.filePath }));
+ args = args.concat(Cpp.collectLibraryDependenciesArguments(product));
- // Misc flags.
var escapedLinkerFlags = escapeLinkerFlags(product, escapableLinkerFlags);
if (escapedLinkerFlags)
Array.prototype.push.apply(args, escapedLinkerFlags);
- var driverLinkerFlags = useCompilerDriver ? product.cpp.driverLinkerFlags : undefined;
- if (driverLinkerFlags)
- Array.prototype.push.apply(args, driverLinkerFlags);
+
+ // Misc flags.
+ if (useCompilerDriver) {
+ args = args.concat(Cpp.collectMiscLinkerArguments(product),
+ Cpp.collectMiscDriverArguments(product));
+ }
return args;
}
function archiverFlags(project, product, inputs, outputs) {
var args = ["-rc"];
args.push(outputs.staticlibrary[0].filePath);
- if (inputs.obj)
- args = args.concat(inputs.obj.map(function(obj) { return obj.filePath }));
+ args = args.concat(Cpp.collectLinkerObjectPaths(inputs));
return args;
}
diff --git a/share/qbs/modules/cpp/sdcc.qbs b/share/qbs/modules/cpp/sdcc.qbs
index 2013fae4c..45c039596 100644
--- a/share/qbs/modules/cpp/sdcc.qbs
+++ b/share/qbs/modules/cpp/sdcc.qbs
@@ -96,6 +96,14 @@ CppModule {
enableExceptions: false
enableRtti: false
+ defineFlag: "-D"
+ includeFlag: "-I"
+ systemIncludeFlag: "-isystem"
+ preincludeFlag: "-include"
+ libraryDependencyFlag: "-l"
+ libraryPathFlag: "-L"
+ linkerScriptFlag: "-f"
+
Rule {
id: assembler
inputs: ["asm"]
diff --git a/share/qbs/modules/cpp/windows-msvc-base.qbs b/share/qbs/modules/cpp/windows-msvc-base.qbs
index 10093f144..1dce682ed 100644
--- a/share/qbs/modules/cpp/windows-msvc-base.qbs
+++ b/share/qbs/modules/cpp/windows-msvc-base.qbs
@@ -114,6 +114,12 @@ CppModule {
property string windowsSdkVersion
+ defineFlag: "/D"
+ includeFlag: "/I"
+ systemIncludeFlag: "/external:I"
+ preincludeFlag: "/FI"
+ libraryPathFlag: "/LIBPATH:"
+
Rule {
condition: useCPrecompiledHeader
inputs: ["c_pch_src"]