diff options
author | Christian Kandeler <christian.kandeler@qt.io> | 2017-05-15 13:54:16 +0200 |
---|---|---|
committer | Christian Kandeler <christian.kandeler@qt.io> | 2017-05-22 09:10:58 +0000 |
commit | 7ac55bda5519ad2ef3f220f4f0f778dd9592abc5 (patch) | |
tree | a78e13e7b702fbd4e4b631bbb9542e3fb5a986af /share/qbs/modules/cpp/gcc.js | |
parent | 1dd00091f99e62d8c10677de98e753fe332565a9 (diff) |
Introduce dependency parameter cpp.linkWholeArchive
Maps to --whole-archive, -force_load and /WHOLEARCHIVE on the toolchain
level.
[ChangeLog][Parameters] When pulling in static library products, the new
Depends parameter cpp.linkWholeArchive can now be specified to force all
the library's objects into the target binary.
Task-number: QBS-701
Change-Id: Ic6482092f39f9ecb1ffb8e37d3031a94dc830be8
Reviewed-by: Joerg Bornemann <joerg.bornemann@qt.io>
Diffstat (limited to 'share/qbs/modules/cpp/gcc.js')
-rw-r--r-- | share/qbs/modules/cpp/gcc.js | 52 |
1 files changed, 41 insertions, 11 deletions
diff --git a/share/qbs/modules/cpp/gcc.js b/share/qbs/modules/cpp/gcc.js index d95edddba..916935ac6 100644 --- a/share/qbs/modules/cpp/gcc.js +++ b/share/qbs/modules/cpp/gcc.js @@ -83,12 +83,16 @@ function collectLibraryDependencies(product) { objectByFilePath[obj.filePath] = obj; } - function addPublicFilePath(filePath) { + function addPublicFilePath(filePath, dep) { var existing = objectByFilePath[filePath]; - if (existing) + var wholeArchive = dep.parameters.cpp && dep.parameters.cpp.linkWholeArchive; + if (existing) { existing.direct = true; - else - addObject({ direct: true, filePath: filePath }, Array.prototype.unshift); + existing.wholeArchive = wholeArchive; + } else { + addObject({ direct: true, filePath: filePath, wholeArchive: wholeArchive }, + Array.prototype.unshift); + } } function addPrivateFilePath(filePath) { @@ -102,7 +106,8 @@ function collectLibraryDependencies(product) { if (!artifacts) return; var artifactFilePaths = artifacts.map(function(a) { return a.filePath; }); - artifactFilePaths.forEach(addFunction); + for (var i = 0; i < artifactFilePaths.length; ++i) + addFunction(artifactFilePaths[i], dep); } function addExternalLibs(obj) { @@ -158,7 +163,8 @@ function collectLibraryDependencies(product) { objects.forEach( function (obj) { if (obj.direct) { - result.libraries.push(obj.filePath); + result.libraries.push({ filePath: obj.filePath, + wholeArchive: obj.wholeArchive }); } else { var dirPath = FileInfo.path(obj.filePath); if (!seenRPathLinkDirs.hasOwnProperty(dirPath)) { @@ -367,11 +373,35 @@ function linkerFlags(project, product, inputs, output) { args = args.concat(['-weak_framework', weakFrameworks[i]]); } - args = args.concat(libraryDependencies.libraries.map(function(lib) { - return FileInfo.isAbsolutePath(lib) || lib.startsWith('@') - ? lib - : '-l' + lib; - })); + var wholeArchiveActive = false; + for (i = 0; i < libraryDependencies.libraries.length; ++i) { + var dep = libraryDependencies.libraries[i]; + var lib = dep.filePath; + if (dep.wholeArchive && !wholeArchiveActive) { + var wholeArchiveFlag; + if (isDarwin) { + wholeArchiveFlag = "-force_load"; + } else { + wholeArchiveFlag = "--whole-archive"; + wholeArchiveActive = true; + } + Array.prototype.push.apply(args, + escapeLinkerFlags(product, inputs, [wholeArchiveFlag])); + } + if (!dep.wholeArchive && wholeArchiveActive) { + Array.prototype.push.apply(args, + escapeLinkerFlags(product, inputs, ["--no-whole-archive"])); + wholeArchiveActive = false; + } + if (FileInfo.isAbsolutePath(lib) || lib.startsWith('@')) + args.push(lib); + else + args.push('-l' + lib); + } + if (wholeArchiveActive) { + Array.prototype.push.apply(args, + escapeLinkerFlags(product, inputs, ["--no-whole-archive"])); + } if (product.cpp.useRPathLink) { args = args.concat(escapeLinkerFlags( |