From 3c4eccbdbaab777294ebde71166eabcb96d7ba39 Mon Sep 17 00:00:00 2001 From: Denis Shienkov Date: Fri, 14 Dec 2018 15:16:54 +0300 Subject: bare-metal: Add IAR EWARM toolchain support on Windows This commit adds a basic support of the IAR Embedded Workbench toolchain for the ARM processors on Windows host. To use it with Qt Creator, it is enough to add there a desired Kit with a custom IAR C/C++ compiler, and then set the following in the Kit's Qbs profile settings: * Key: qbs.toolchainType * Value: iar To specify the target CPU/FPU you need to set the cpp.driverFlags property, like this: cpp.driverFlags: [ "--cpu", "Cortex-M4", "--fpu", "VFPv4_sp" ] Then these flags will be automatically passed to both compiler and assembler. To specify the linker flags you need to set the cpp.driverLinkerFlags property instead of cpp.linkerFlags property, like this: cpp.driverLinkerFlags: ["--vfe"] To add the linker script files you need to set the 'linkerscript' tag, e.g. in the following way: Group { name: "Linker scripts" fileTags: ["linkerscript"] files: ["stm32f407xx_flash.icf"] } Other properties can be used as usual, according to the EWARM compiler documentation. Tested with EWARM v8.20.2, v6.50.3 on Windows using: * STM NUCLEO-F767ZI * STM 32F4DISCOVERY target boards. Change-Id: I3c42eb94051352cb3b7eb5b0768a1dc8bdacabce Reviewed-by: Richard Weickelt Reviewed-by: Christian Kandeler --- doc/config/macros.qdocconf | 1 + doc/reference/modules/cpp-module.qdoc | 11 ++ share/qbs/imports/qbs/Probes/IarProbe.qbs | 65 ++++++++ share/qbs/modules/cpp/iar.js | 264 ++++++++++++++++++++++++++++++ share/qbs/modules/cpp/iar.qbs | 195 ++++++++++++++++++++++ 5 files changed, 536 insertions(+) create mode 100644 share/qbs/imports/qbs/Probes/IarProbe.qbs create mode 100644 share/qbs/modules/cpp/iar.js create mode 100644 share/qbs/modules/cpp/iar.qbs diff --git a/doc/config/macros.qdocconf b/doc/config/macros.qdocconf index ade8c3a88..a8abe25e5 100644 --- a/doc/config/macros.qdocconf +++ b/doc/config/macros.qdocconf @@ -6,6 +6,7 @@ macro.nodefaultvalue = "Default: Undefined" macro.appleproperty = "This property is specific to Apple platforms." macro.unixproperty = "This property is specific to Unix platforms." macro.windowsproperty = "This property is specific to Windows." +macro.baremetalproperty = "This property is specific to bare-metal platforms." macro.funsince.HTML = "

This function was introduced in version \1.

" macro.aacute.HTML = "á" diff --git a/doc/reference/modules/cpp-module.qdoc b/doc/reference/modules/cpp-module.qdoc index 940e837ae..f69f07239 100644 --- a/doc/reference/modules/cpp-module.qdoc +++ b/doc/reference/modules/cpp-module.qdoc @@ -1662,3 +1662,14 @@ \nodefaultvalue */ + +/*! + \qmlproperty bool cpp::generateMapFile + \since Qbs 1.13 + + \baremetalproperty + + Whether to auto-generate a linker map file. + + \defaultvalue \c{true} +*/ diff --git a/share/qbs/imports/qbs/Probes/IarProbe.qbs b/share/qbs/imports/qbs/Probes/IarProbe.qbs new file mode 100644 index 000000000..9d22f5d2a --- /dev/null +++ b/share/qbs/imports/qbs/Probes/IarProbe.qbs @@ -0,0 +1,65 @@ +/**************************************************************************** +** +** Copyright (C) 2019 Denis Shienkov +** Contact: http://www.qt.io/licensing +** +** This file is part of the Qt Build Suite. +** +** 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. +** +****************************************************************************/ + +import qbs.File +import "../../../modules/cpp/iar.js" as IAR + +PathProbe { + // Inputs + property string compilerFilePath; + + property string _nullDevice: qbs.nullDevice + + // Outputs + property string architecture; + property string endianness; + property int versionMajor; + property int versionMinor; + property int versionPatch; + + configure: { + if (!File.exists(compilerFilePath)) { + found = false; + return; + } + + var macros = IAR.dumpMacros(compilerFilePath, qbs, _nullDevice); + + architecture = IAR.guessArchitecture(macros); + endianness = IAR.guessEndianness(macros); + + var version = parseInt(macros["__VER__"], 10); + versionMajor = parseInt(version / 1000000); + versionMinor = parseInt(version / 1000) % 1000; + versionPatch = parseInt(version) % 1000; + + found = version && architecture && endianness; + } +} diff --git a/share/qbs/modules/cpp/iar.js b/share/qbs/modules/cpp/iar.js new file mode 100644 index 000000000..ae852c1b6 --- /dev/null +++ b/share/qbs/modules/cpp/iar.js @@ -0,0 +1,264 @@ +/**************************************************************************** +** +** Copyright (C) 2019 Denis Shienkov +** Contact: http://www.qt.io/licensing +** +** This file is part of the Qt Build Suite. +** +** 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 Cpp = require("cpp.js"); +var Environment = require("qbs.Environment"); +var File = require("qbs.File"); +var FileInfo = require("qbs.FileInfo"); +var ModUtils = require("qbs.ModUtils"); +var Process = require("qbs.Process"); +var TemporaryDir = require("qbs.TemporaryDir"); +var TextFile = require("qbs.TextFile"); +var Utilities = require("qbs.Utilities"); +var WindowsUtils = require("qbs.WindowsUtils"); + +function guessArchitecture(macros) +{ + if (macros["__ICCARM__"] === "1") + return "arm"; +} + +function guessEndianness(macros) +{ + if (macros["__LITTLE_ENDIAN__"] === "1") + return "little"; + return "big" +} + +function dumpMacros(compilerFilePath, qbs, nullDevice) { + var tempDir = new TemporaryDir(); + var inFilePath = FileInfo.fromNativeSeparators(tempDir.path() + "/empty-source.c"); + var inFile = new TextFile(inFilePath, TextFile.WriteOnly); + var outFilePath = FileInfo.fromNativeSeparators(tempDir.path() + "/iar-macros.predef"); + var p = new Process(); + + p.exec(compilerFilePath, + [ inFilePath, "--predef_macros", outFilePath ], + true); + var outFile = new TextFile(outFilePath, TextFile.ReadOnly); + var map = {}; + outFile.readAll().trim().split(/\r?\n/g).map(function (line) { + var parts = line.split(" ", 3); + map[parts[1]] = parts[2]; + }); + return map; +} + +function compilerFlags(project, product, input, output, explicitlyDependsOn) { + // Determine which C-language we"re compiling. + var tag = ModUtils.fileTagForTargetLanguage(input.fileTags.concat(output.fileTags)); + + var args = []; + args.push(input.filePath); + + switch (input.cpp.optimization) { + case "small": + args.push("-Ohs"); + break; + case "fast": + args.push("-Ohz"); + break; + case "none": + args.push("-On"); + break; + } + + if (input.cpp.debugInformation) + args.push("--debug"); + + var warnings = input.cpp.warningLevel; + if (warnings === "none") { + args.push("--no_warnings"); + } else if (warnings === "all") { + args.push("--warnings_affect_exit_code"); + args.push("--deprecated_feature_warnings=" + +"+attribute_syntax," + +"+preprocessor_extensions," + +"+segment_pragmas"); + if (tag === "cpp") + args.push("--warn_about_c_style_casts"); + } + if (input.cpp.treatWarningsAsErrors) { + args.push("--warnings_are_errors"); + } + + // Choose byte order. + var endianness = input.cpp.endianness; + if (endianness) + args.push("--endian=" + endianness); + + if (tag === "c") { + // Language version. + if (input.cpp.cLanguageVersion === "c89") + args.push("--c89"); + } else if (tag === "cpp") { + args.push("--c++"); + if (!input.cpp.enableExceptions) + args.push("--no_exceptions"); + if (!input.cpp.enableRtti) + args.push("--no_rtti"); + } + + 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 })); + + 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 compilerIncludePaths = input.cpp.compilerIncludePaths; + if (compilerIncludePaths) + allIncludePaths = allIncludePaths.uniqueConcat(compilerIncludePaths); + args = args.concat(allIncludePaths.map(function(include) { return "-I" + include })); + + args.push("-o", output.filePath); + + args.push("--silent"); // Silent operation. + + 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)); + return args; +} + +function assemblerFlags(project, product, input, output, explicitlyDependsOn) { + // Determine which C-language we"re compiling + var tag = ModUtils.fileTagForTargetLanguage(input.fileTags.concat(output.fileTags)); + + var args = []; + args.push(input.filePath); + + if (input.cpp.debugInformation) + args.push("-r"); + + var warnings = input.cpp.warningLevel; + if (warnings === "none") + args.push("-w-"); + else + args.push("-w+"); + + args.push("-o", output.filePath); + + args.push("-S"); // Silent operation. + + args = args.concat(ModUtils.moduleProperty(input, "platformFlags", tag), + ModUtils.moduleProperty(input, "flags", tag), + ModUtils.moduleProperty(input, "driverFlags", tag)); + return args; +} + +function linkerFlags(project, product, input, outputs) { + var i; + var args = []; + + if (inputs.obj) + args = args.concat(inputs.obj.map(function(obj) { return obj.filePath })); + + args.push("-o", outputs.application[0].filePath); + + if (product.cpp.generateMapFile) + args.push("--map", outputs.map_file[0].filePath); + + var linkerScripts = inputs.linkerscript + ? inputs.linkerscript.map(function(a) { return a.filePath; }) : []; + for (i in linkerScripts) + args.push("--config", linkerScripts[i]); + + if (product.cpp.entryPoint) + args.push("--entry", product.cpp.entryPoint); + + args.push("--silent"); // Silent operation. + + args = args.concat(ModUtils.moduleProperty(product, "driverLinkerFlags")); + return args; +} + +function archiverFlags(project, product, input, outputs) { + var args = []; + + if (inputs.obj) + args = args.concat(inputs.obj.map(function(obj) { return obj.filePath })); + + args.push("--create"); + args.push("-o", outputs.staticlibrary[0].filePath); + + return args; +} + +function prepareCompiler(project, product, inputs, outputs, input, output, explicitlyDependsOn) { + var args = compilerFlags(project, product, input, output, explicitlyDependsOn); + var compilerPath = input.cpp.compilerPath; + var cmd = new Command(compilerPath, args) + cmd.description = "compiling " + input.fileName; + cmd.highlight = "compiler"; + return [cmd]; +} + +function prepareAssembler(project, product, inputs, outputs, input, output, explicitlyDependsOn) { + var args = assemblerFlags(project, product, input, output, explicitlyDependsOn); + var assemblerPath = input.cpp.assemblerPath; + var cmd = new Command(assemblerPath, args) + cmd.description = "assembling " + input.fileName; + cmd.highlight = "compiler"; + return [cmd]; +} + +function prepareLinker(project, product, inputs, outputs, input, output) { + var primaryOutput = outputs.application[0]; + var args = linkerFlags(project, product, input, outputs); + var linkerPath = product.cpp.linkerPath; + var cmd = new Command(linkerPath, args) + cmd.description = "linking " + primaryOutput.fileName; + cmd.highlight = "linker"; + return [cmd]; +} + +function prepareArchiver(project, product, inputs, outputs, input, output) { + var args = archiverFlags(project, product, input, outputs); + var archiverPath = product.cpp.archiverPath; + var cmd = new Command(archiverPath, args) + cmd.description = "linking " + output.fileName; + cmd.highlight = "linker"; + cmd.stdoutFilterFunction = function(output) { + return ""; + }; + return [cmd]; +} diff --git a/share/qbs/modules/cpp/iar.qbs b/share/qbs/modules/cpp/iar.qbs new file mode 100644 index 000000000..69a0a0377 --- /dev/null +++ b/share/qbs/modules/cpp/iar.qbs @@ -0,0 +1,195 @@ +/**************************************************************************** +** +** Copyright (C) 2019 Denis Shienkov +** Contact: http://www.qt.io/licensing +** +** This file is part of the Qt Build Suite. +** +** 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. +** +****************************************************************************/ + +import qbs 1.0 +import qbs.File +import qbs.FileInfo +import qbs.ModUtils +import qbs.PathTools +import qbs.Probes +import qbs.Utilities +import "iar.js" as IAR + +CppModule { + condition: qbs.toolchain && qbs.toolchain.contains("iar") + + Probes.BinaryProbe { + id: compilerPathProbe + condition: !toolchainInstallPath && !_skipAllChecks + names: ["iccarm"] + } + + Probes.IarProbe { + id: iarProbe + condition: !_skipAllChecks + compilerFilePath: compilerPath + } + + qbs.architecture: iarProbe.found ? iarProbe.architecture : original + + compilerVersionMajor: iarProbe.versionMajor + compilerVersionMinor: iarProbe.versionMinor + compilerVersionPatch: iarProbe.versionPatch + endianness: iarProbe.endianness + + compilerDefinesByLanguage: [] + + property string toolchainInstallPath: compilerPathProbe.found + ? compilerPathProbe.path : undefined + + property string compilerExtension: qbs.hostOS.contains("windows") ? ".exe" : "" + + property bool generateMapFile: true + PropertyOptions { + name: "generateMapFile" + description: "produce a linker list file (enabled by default)" + } + + /* Work-around for QtCreator which expects these properties to exist. */ + property string cCompilerName: compilerName + property string cxxCompilerName: compilerName + + compilerName: { + switch (qbs.architecture) { + case "arm": + return "iccarm" + compilerExtension; + } + } + compilerPath: FileInfo.joinPaths(toolchainInstallPath, compilerName) + + assemblerName: { + switch (qbs.architecture) { + case "arm": + return "iasmarm" + compilerExtension; + } + } + assemblerPath: FileInfo.joinPaths(toolchainInstallPath, assemblerName) + + linkerName: { + switch (qbs.architecture) { + case "arm": + return "ilinkarm" + compilerExtension; + } + } + linkerPath: FileInfo.joinPaths(toolchainInstallPath, linkerName) + + property string archiverName: { + switch (qbs.architecture) { + case "arm": + return "iarchive" + compilerExtension; + } + } + property string archiverPath: FileInfo.joinPaths(toolchainInstallPath, archiverName) + + runtimeLibrary: "static" + staticLibrarySuffix: ".a" + executableSuffix: ".out" + imageFormat: "elf" + enableExceptions: false + enableRtti: false + + Rule { + id: assembler + inputs: ["asm"] + + Artifact { + fileTags: ["obj"] + filePath: Utilities.getHash(input.baseDir) + "/" + input.fileName + ".o" + } + + prepare: IAR.prepareAssembler.apply(IAR, arguments); + } + + FileTagger { + patterns: "*.s" + fileTags: ["asm"] + } + + Rule { + id: compiler + inputs: ["cpp", "c"] + auxiliaryInputs: ["hpp"] + + Artifact { + fileTags: ["obj"] + filePath: Utilities.getHash(input.baseDir) + "/" + input.fileName + ".o" + } + + prepare: IAR.prepareCompiler.apply(IAR, arguments); + } + + Rule { + id: applicationLinker + multiplex: true + inputs: ["obj", "linkerscript"] + + outputFileTags: { + var tags = ["application"]; + if (product.moduleProperty("cpp", "generateMapFile")) + tags.push("map_file"); + return tags; + } + outputArtifacts: { + var app = { + fileTags: ["application"], + filePath: FileInfo.joinPaths( + product.destinationDirectory, + PathTools.applicationFilePath(product)) + }; + var artifacts = [app]; + if (product.cpp.generateMapFile) { + artifacts.push({ + fileTags: ["map_file"], + filePath: FileInfo.joinPaths( + product.destinationDirectory, + product.targetName + ".map") + }); + } + return artifacts; + } + + prepare:IAR.prepareLinker.apply(IAR, arguments); + } + + Rule { + id: staticLibraryLinker + multiplex: true + inputs: ["obj"] + + Artifact { + fileTags: ["staticlibrary"] + filePath: FileInfo.joinPaths( + product.destinationDirectory, + PathTools.staticLibraryFilePath(product)) + } + + prepare: IAR.prepareArchiver.apply(IAR, arguments); + } +} -- cgit v1.2.3