aboutsummaryrefslogtreecommitdiffstats
path: root/share
diff options
context:
space:
mode:
authorJake Petroules <jake.petroules@qt.io>2017-03-21 12:25:52 -0700
committerJake Petroules <jake.petroules@qt.io>2017-03-22 20:07:57 +0000
commit6ca71e5b61c5b1e4ec4c931665a2f3f34709cc23 (patch)
tree0f94d290ac2d0b6354cea7062ff10e813c370c2e /share
parent53457970d7555307cb79f1c85fc0e3dccad45a03 (diff)
Introduce cpp.target[Assembler,Driver,Linker]Flags
These are internal properties that deduplicates architecture/vendor/system/abi related flags between the compiler invocation and compiler probe, and reduces tight coupling between gcc.js, GccProbe, and the individual cpp toolchain modules. Change-Id: I7ea57ea1dd4c5eb42fc8983e4c9c45aa01284521 Reviewed-by: Joerg Bornemann <joerg.bornemann@qt.io>
Diffstat (limited to 'share')
-rw-r--r--share/qbs/imports/qbs/Probes/GccProbe.qbs23
-rw-r--r--share/qbs/modules/cpp/CppModule.qbs4
-rw-r--r--share/qbs/modules/cpp/DarwinGCC.qbs19
-rw-r--r--share/qbs/modules/cpp/GenericGCC.qbs36
-rw-r--r--share/qbs/modules/cpp/gcc.js60
5 files changed, 66 insertions, 76 deletions
diff --git a/share/qbs/imports/qbs/Probes/GccProbe.qbs b/share/qbs/imports/qbs/Probes/GccProbe.qbs
index 45e174441..77fac9e04 100644
--- a/share/qbs/imports/qbs/Probes/GccProbe.qbs
+++ b/share/qbs/imports/qbs/Probes/GccProbe.qbs
@@ -35,12 +35,9 @@ import "../../../modules/cpp/gcc.js" as Gcc
PathProbe {
// Inputs
property string compilerFilePath
- property string preferredArchitecture
- property string preferredMachineType
property stringList flags: []
property var environment
- property bool _haveArchFlag: qbs.targetOS.contains("darwin")
property string _nullDevice: qbs.nullDevice
property stringList _toolchain: qbs.toolchain
property string _pathListSeparator: qbs.pathListSeparator
@@ -57,22 +54,8 @@ PathProbe {
property stringList frameworkPaths
configure: {
- var args = flags;
- if (_haveArchFlag) {
- if (preferredArchitecture)
- args.push("-arch", preferredArchitecture);
- } else {
- if (preferredArchitecture === "i386")
- args.push("-m32");
- else if (preferredArchitecture === "x86_64")
- args.push("-m64");
-
- if (preferredMachineType)
- args.push("-march=" + preferredMachineType);
- }
-
- var macros = Gcc.dumpMacros(environment, compilerFilePath, args, _nullDevice);
- var defaultPaths = Gcc.dumpDefaultPaths(environment, compilerFilePath, args, _nullDevice,
+ var macros = Gcc.dumpMacros(environment, compilerFilePath, flags, _nullDevice);
+ var defaultPaths = Gcc.dumpDefaultPaths(environment, compilerFilePath, flags, _nullDevice,
_pathListSeparator, _targetOS, _sysroot);
found = !!macros && !!defaultPaths;
@@ -82,7 +65,7 @@ PathProbe {
// We have to dump the compiler's macros; -dumpmachine is not suitable because it is not
// always complete (for example, the subarch is not included for arm architectures).
- architecture = ModUtils.guessArchitecture(macros) || preferredArchitecture;
+ architecture = ModUtils.guessArchitecture(macros);
if (_toolchain.contains("clang")) {
versionMajor = parseInt(macros["__clang_major__"], 10);
diff --git a/share/qbs/modules/cpp/CppModule.qbs b/share/qbs/modules/cpp/CppModule.qbs
index ec3c388f3..3575683a8 100644
--- a/share/qbs/modules/cpp/CppModule.qbs
+++ b/share/qbs/modules/cpp/CppModule.qbs
@@ -318,6 +318,10 @@ Module {
property bool combineObjcSources: false
property bool combineObjcxxSources: false
+ property stringList targetAssemblerFlags
+ property stringList targetDriverFlags
+ property stringList targetLinkerFlags
+
// TODO: The following four rules could use a convenience base item if rule properties
// were available in Artifact items and prepare scripts.
Rule {
diff --git a/share/qbs/modules/cpp/DarwinGCC.qbs b/share/qbs/modules/cpp/DarwinGCC.qbs
index 46781e2c6..d183511b0 100644
--- a/share/qbs/modules/cpp/DarwinGCC.qbs
+++ b/share/qbs/modules/cpp/DarwinGCC.qbs
@@ -119,7 +119,26 @@ UnixGCC {
return dict;
}
+ targetLinkerFlags: darwinArchFlags.concat(minimumDarwinVersionLinkerFlags)
+ targetAssemblerFlags: targetDriverFlags
+ targetDriverFlags: {
+ var args = [];
+ if (!hasTargetOption)
+ args = args.concat(darwinArchFlags).concat(minimumDarwinVersionCompilerFlags);
+ return args.concat(base); // concat base flags to get -march
+ }
+
// private properties
+ readonly property stringList darwinArchFlags: targetArch ? ["-arch", targetArch] : []
+
+ readonly property stringList minimumDarwinVersionCompilerFlags:
+ (minimumDarwinVersionCompilerFlag && minimumDarwinVersion)
+ ? [minimumDarwinVersionCompilerFlag + "=" + minimumDarwinVersion] : []
+
+ readonly property stringList minimumDarwinVersionLinkerFlags:
+ (minimumDarwinVersionLinkerFlag && minimumDarwinVersion)
+ ? [minimumDarwinVersionLinkerFlag, minimumDarwinVersion] : []
+
readonly property var buildEnv: {
var env = {
"ARCHS_STANDARD": targetArch, // TODO: this will be affected by multi-arch support
diff --git a/share/qbs/modules/cpp/GenericGCC.qbs b/share/qbs/modules/cpp/GenericGCC.qbs
index 2bee8f14f..169886a5c 100644
--- a/share/qbs/modules/cpp/GenericGCC.qbs
+++ b/share/qbs/modules/cpp/GenericGCC.qbs
@@ -52,9 +52,39 @@ CppModule {
Probes.GccProbe {
id: gccProbe
compilerFilePath: compilerPath
- preferredArchitecture: targetArch
- preferredMachineType: machineType
environment: buildEnv
+ flags: targetDriverFlags
+ }
+
+ targetAssemblerFlags: {
+ switch (targetArch) {
+ case "i386":
+ return ["--32"];
+ case "x86_64":
+ return ["--64"];
+ default:
+ return [];
+ }
+ }
+
+ targetDriverFlags: {
+ var args = [];
+ if (hasTargetOption) {
+ if (target)
+ args.push("-target", target);
+ } else {
+ switch (targetArch) {
+ case "i386":
+ args.push("-m32");
+ break;
+ case "x86_64":
+ args.push("-m64");
+ break;
+ }
+ if (machineType)
+ args.push("-march=" + machineType);
+ }
+ return args;
}
Probe {
@@ -82,6 +112,8 @@ CppModule {
compilerFrameworkPaths: gccProbe.frameworkPaths
compilerLibraryPaths: gccProbe.libraryPaths
+ property bool hasTargetOption: qbs.toolchain.contains("clang")
+ && Utilities.versionCompare(compilerVersion, "3.1") >= 0
property string target: [targetArch, targetVendor, targetSystem, targetAbi].join("-")
property string targetArch: Utilities.canonicalTargetArchitecture(
qbs.architecture, targetVendor, targetSystem, targetAbi)
diff --git a/share/qbs/modules/cpp/gcc.js b/share/qbs/modules/cpp/gcc.js
index 409b6eebe..178541cde 100644
--- a/share/qbs/modules/cpp/gcc.js
+++ b/share/qbs/modules/cpp/gcc.js
@@ -242,12 +242,9 @@ function linkerFlags(project, product, inputs, output) {
["--as-needed"]));
}
- var minimumDarwinVersion = product.cpp.minimumDarwinVersion;
- if (minimumDarwinVersion) {
- var flag = product.cpp.minimumDarwinVersionLinkerFlag;
- if (flag)
- args = args.concat(escapeLinkerFlags(product, inputs, [flag, minimumDarwinVersion]));
- }
+ var targetLinkerFlags = product.cpp.targetLinkerFlags;
+ if (targetLinkerFlags)
+ args = args.concat(escapeLinkerFlags(product, inputs, targetLinkerFlags));
var sysroot = product.cpp.sysroot;
if (sysroot) {
@@ -391,40 +388,12 @@ function linkerFlags(project, product, inputs, output) {
// for compiler AND linker
function configFlags(config, isDriver) {
- if (isDriver === undefined)
- isDriver = true;
-
var args = [];
- if (isDriver) {
+ if (isDriver !== false) {
args = args.concat(config.cpp.platformDriverFlags);
args = args.concat(config.cpp.driverFlags);
- }
-
- if (haveTargetOption(config) && isDriver) {
- args.push("-target", config.cpp.target);
- } else {
- var arch = config.cpp.targetArch;
- if (config.qbs.targetOS.contains("darwin"))
- args.push("-arch", arch);
-
- if (isDriver) {
- if (arch === 'x86_64')
- args.push('-m64');
- else if (arch === 'i386')
- args.push('-m32');
-
- var march = config.cpp.machineType;
- if (march)
- args.push("-march=" + march);
-
- var minimumDarwinVersion = config.cpp.minimumDarwinVersion;
- if (minimumDarwinVersion) {
- var flag = config.cpp.minimumDarwinVersionCompilerFlag;
- if (flag)
- args.push(flag + "=" + minimumDarwinVersion);
- }
- }
+ args = args.concat(config.cpp.targetDriverFlags);
}
var frameworkPaths = config.cpp.frameworkPaths;
@@ -676,16 +645,6 @@ function compilerFlags(project, product, input, output) {
return args;
}
-function haveTargetOption(product) {
- var toolchain = product.qbs.toolchain;
- var major = product.cpp.compilerVersionMajor;
- var minor = product.cpp.compilerVersionMinor;
-
- // Apple Clang 3.1 (shipped with Xcode 4.3) just happened to also correspond to LLVM 3.1,
- // so no special version check is needed for Apple
- return toolchain.contains("clang") && (major > 3 || (major === 3 && minor >= 1));
-}
-
function additionalCompilerAndLinkerFlags(product) {
var args = []
@@ -720,14 +679,7 @@ function prepareAssembler(project, product, inputs, outputs, input, output) {
var systemIncludePaths = input.cpp.systemIncludePaths;
var distributionIncludePaths = input.cpp.distributionIncludePaths;
- var args = [];
- var arch = product.cpp.targetArch;
- if (product.qbs.targetOS.contains("darwin"))
- args.push("-arch", arch);
- else if (arch === 'x86_64')
- args.push('--64');
- else if (arch === 'i386')
- args.push('--32');
+ var args = product.cpp.targetAssemblerFlags;
if (input.cpp.debugInformation)
args.push('-g');