From d14bef846b0b3ab6513837c0ab20b3d143c17b00 Mon Sep 17 00:00:00 2001 From: Denis Shienkov Date: Sun, 20 Jan 2019 22:32:35 +0300 Subject: bare-metal: Link with library dependencies on IAR for ARM This patch adds the possibility to link the application with an external or dependent libraries. IAR supports linking only with the static libraries for the bare-metal devices. Now it is possible to use the cpp.staticLibraries and cpp.libraryPaths properties, also to use the product's library dependencies via Depends { name: "mylib" }. Change-Id: I5129473dc0353970d060a8c714b2f4b51d1ab4cc Reviewed-by: Richard Weickelt Reviewed-by: Christian Kandeler --- share/qbs/modules/cpp/iar.js | 68 +++++++++++++++++++++++++++++++++++++++++++ share/qbs/modules/cpp/iar.qbs | 2 ++ 2 files changed, 70 insertions(+) (limited to 'share') diff --git a/share/qbs/modules/cpp/iar.js b/share/qbs/modules/cpp/iar.js index ae852c1b6..c2c9e569e 100644 --- a/share/qbs/modules/cpp/iar.js +++ b/share/qbs/modules/cpp/iar.js @@ -71,6 +71,61 @@ function dumpMacros(compilerFilePath, qbs, nullDevice) { return map; } +function collectLibraryDependencies(product) { + var seen = {}; + var result = []; + + function addFilePath(filePath) { + result.push({ filePath: filePath }); + } + + function addArtifactFilePaths(dep, artifacts) { + if (!artifacts) + return; + var artifactFilePaths = artifacts.map(function(a) { return a.filePath; }); + artifactFilePaths.forEach(addFilePath); + } + + function addExternalStaticLibs(obj) { + if (!obj.cpp) + return; + function ensureArray(a) { + return Array.isArray(a) ? a : []; + } + function sanitizedModuleListProperty(obj, moduleName, propertyName) { + return ensureArray(ModUtils.sanitizedModuleProperty(obj, moduleName, propertyName)); + } + var externalLibs = [].concat( + sanitizedModuleListProperty(obj, "cpp", "staticLibraries")); + var staticLibrarySuffix = obj.moduleProperty("cpp", "staticLibrarySuffix"); + externalLibs.forEach(function(staticLibraryName) { + if (!staticLibraryName.endsWith(staticLibrarySuffix)) + staticLibraryName += staticLibrarySuffix; + addFilePath(staticLibraryName); + }); + } + + function traverse(dep) { + if (seen.hasOwnProperty(dep.name)) + return; + seen[dep.name] = true; + + if (dep.parameters.cpp && dep.parameters.cpp.link === false) + return; + + var staticLibraryArtifacts = dep.artifacts["staticlibrary"]; + if (staticLibraryArtifacts) { + dep.dependencies.forEach(traverse); + addArtifactFilePaths(dep, staticLibraryArtifacts); + addExternalStaticLibs(dep); + } + } + + product.dependencies.forEach(traverse); + addExternalStaticLibs(product); + return result; +} + function compilerFlags(project, product, input, output, explicitlyDependsOn) { // Determine which C-language we"re compiling. var tag = ModUtils.fileTagForTargetLanguage(input.fileTags.concat(output.fileTags)); @@ -197,6 +252,19 @@ function linkerFlags(project, product, input, outputs) { if (product.cpp.generateMapFile) args.push("--map", outputs.map_file[0].filePath); + 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(allLibraryPaths.map(function(path) { return '-L' + path })); + + var libraryDependencies = collectLibraryDependencies(product); + if (libraryDependencies) + args = args.concat(libraryDependencies.map(function(dep) { return dep.filePath })); + var linkerScripts = inputs.linkerscript ? inputs.linkerscript.map(function(a) { return a.filePath; }) : []; for (i in linkerScripts) diff --git a/share/qbs/modules/cpp/iar.qbs b/share/qbs/modules/cpp/iar.qbs index 69a0a0377..b91bd6022 100644 --- a/share/qbs/modules/cpp/iar.qbs +++ b/share/qbs/modules/cpp/iar.qbs @@ -149,6 +149,7 @@ CppModule { id: applicationLinker multiplex: true inputs: ["obj", "linkerscript"] + inputsFromDependencies: ["staticlibrary"] outputFileTags: { var tags = ["application"]; @@ -182,6 +183,7 @@ CppModule { id: staticLibraryLinker multiplex: true inputs: ["obj"] + inputsFromDependencies: ["staticlibrary"] Artifact { fileTags: ["staticlibrary"] -- cgit v1.2.3