diff options
author | Christian Kandeler <christian.kandeler@qt.io> | 2017-08-01 15:08:51 +0200 |
---|---|---|
committer | Christian Kandeler <christian.kandeler@qt.io> | 2017-08-28 08:40:16 +0000 |
commit | 40787b4d077eea1211f43d9f247c560957bd6887 (patch) | |
tree | 5e44c225aa4eddbb3c22ca0481524f6c875c3a5d /share/qbs/modules/cpp | |
parent | d36064bc2e486d81e8403e45ddf91311aa066fdb (diff) | |
download | qbs-40787b4d077eea1211f43d9f247c560957bd6887.tar.gz |
Introduce the cpufeatures module
Provides an abstraction for the respective compiler flags. The initial
set of properties is the superset of what Qt can configure and what MSVC
supports.
Change-Id: I1be90361f2f104a55d2a784a69625396680b0713
Reviewed-by: Joerg Bornemann <joerg.bornemann@qt.io>
Diffstat (limited to 'share/qbs/modules/cpp')
-rw-r--r-- | share/qbs/modules/cpp/CppModule.qbs | 3 | ||||
-rw-r--r-- | share/qbs/modules/cpp/gcc.js | 41 | ||||
-rw-r--r-- | share/qbs/modules/cpp/msvc.js | 25 |
3 files changed, 69 insertions, 0 deletions
diff --git a/share/qbs/modules/cpp/CppModule.qbs b/share/qbs/modules/cpp/CppModule.qbs index f5adc27fc..c340519ac 100644 --- a/share/qbs/modules/cpp/CppModule.qbs +++ b/share/qbs/modules/cpp/CppModule.qbs @@ -35,6 +35,9 @@ import qbs.WindowsUtils Module { condition: false + + Depends { name: "cpufeatures" } + version: compilerVersion property string compilerVersion: [compilerVersionMajor, compilerVersionMinor, compilerVersionPatch].join(".") diff --git a/share/qbs/modules/cpp/gcc.js b/share/qbs/modules/cpp/gcc.js index a0acc638a..873aea531 100644 --- a/share/qbs/modules/cpp/gcc.js +++ b/share/qbs/modules/cpp/gcc.js @@ -560,6 +560,46 @@ function qnxLangArgs(config, tag) { } } +function handleCpuFeatures(input, flags) { + function potentiallyAddFlagForFeature(propName, flagName) { + var propValue = input.cpufeatures[propName]; + if (propValue === true) + flags.push("-m" + flagName); + else if (propValue === false) + flags.push("-mno-" + flagName); + } + + if (!input.qbs.architecture) + return; + if (input.qbs.architecture.startsWith("x86")) { + potentiallyAddFlagForFeature("x86_avx", "avx"); + potentiallyAddFlagForFeature("x86_avx2", "avx2"); + potentiallyAddFlagForFeature("x86_avx512bw", "avx512bw"); + potentiallyAddFlagForFeature("x86_avx512cd", "avx512cd"); + potentiallyAddFlagForFeature("x86_avx512dq", "avx512dq"); + potentiallyAddFlagForFeature("x86_avx512er", "avx512er"); + potentiallyAddFlagForFeature("x86_avx512f", "avx512f"); + potentiallyAddFlagForFeature("x86_avx512ifma", "avx512ifma"); + potentiallyAddFlagForFeature("x86_avx512pf", "avx512pf"); + potentiallyAddFlagForFeature("x86_avx512vbmi", "avx512vbmi"); + potentiallyAddFlagForFeature("x86_avx512vl", "avx512vl"); + potentiallyAddFlagForFeature("x86_f16c", "f16c"); + potentiallyAddFlagForFeature("x86_sse2", "sse2"); + potentiallyAddFlagForFeature("x86_sse3", "sse3"); + potentiallyAddFlagForFeature("x86_sse4_1", "sse4.1"); + potentiallyAddFlagForFeature("x86_sse4_2", "sse4.2"); + potentiallyAddFlagForFeature("x86_ssse3", "ssse3"); + } else if (input.qbs.architecture.startsWith("arm")) { + if (input.cpufeatures.arm_neon === true) + flags.push("-mfpu=neon"); + if (input.cpufeatures.arm_vfpv4 === true) + flags.push("-mfpu=vfpv4"); + } else if (input.qbs.architecture.startsWith("mips")) { + potentiallyAddFlagForFeature("mips_dsp", "dsp"); + potentiallyAddFlagForFeature("mips_dspr2", "dspr2"); + } +} + function compilerFlags(project, product, input, output, explicitlyDependsOn) { var i; @@ -581,6 +621,7 @@ function compilerFlags(project, product, input, output, explicitlyDependsOn) { var args = additionalCompilerAndLinkerFlags(product); Array.prototype.push.apply(args, product.cpp.sysrootFlags); + handleCpuFeatures(input, args); if (input.cpp.debugInformation) args.push('-g'); diff --git a/share/qbs/modules/cpp/msvc.js b/share/qbs/modules/cpp/msvc.js index 484d6475f..4d12ee427 100644 --- a/share/qbs/modules/cpp/msvc.js +++ b/share/qbs/modules/cpp/msvc.js @@ -34,11 +34,36 @@ var ModUtils = require("qbs.ModUtils"); var Utilities = require("qbs.Utilities"); var WindowsUtils = require("qbs.WindowsUtils"); +function handleCpuFeatures(input, flags) { + if (!input.qbs.architecture) + return; + if (input.qbs.architecture.startsWith("x86")) { + if (input.qbs.architecture === "x86") { + var sse2 = input.cpufeatures.x86_sse2; + if (sse2 === true) + flags.push("/arch:SSE2"); + if (sse2 === false) + flags.push("/arch:IA32"); + } + if (input.cpufeatures.x86_avx === true) + flags.push("/arch:AVX"); + if (input.cpufeatures.x86_avx2 === true) + flags.push("/arch:AVX2"); + } else if (input.qbs.architecture.startsWith("arm")) { + if (input.cpufeatures.arm_vfpv4 === true) + flags.push("/arch:VFPv4"); + if (input.cpp.machineType === "armv7ve") + flags.push("/arch:ARMv7VE"); + } +} + function prepareCompiler(project, product, inputs, outputs, input, output, explicitlyDependsOn) { var i; var debugInformation = input.cpp.debugInformation; var args = ['/nologo', '/c'] + handleCpuFeatures(input, args); + // Determine which C-language we're compiling var tag = ModUtils.fileTagForTargetLanguage(input.fileTags.concat(Object.keys(outputs))); if (!["c", "cpp"].contains(tag)) |