summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--share/qbs/modules/cpp/GenericGCC.qbs87
-rw-r--r--share/qbs/modules/cpp/gcc.js91
2 files changed, 73 insertions, 105 deletions
diff --git a/share/qbs/modules/cpp/GenericGCC.qbs b/share/qbs/modules/cpp/GenericGCC.qbs
index da43c782e..7f5d095b8 100644
--- a/share/qbs/modules/cpp/GenericGCC.qbs
+++ b/share/qbs/modules/cpp/GenericGCC.qbs
@@ -54,14 +54,6 @@ CppModule {
}
prepare: {
- var libraryPaths = ModUtils.moduleProperties(product, 'libraryPaths');
- var dynamicLibraries = ModUtils.moduleProperties(product, 'dynamicLibraries');
- var staticLibraries = ModUtils.moduleProperties(product, 'staticLibraries');
- var frameworkPaths = ModUtils.moduleProperties(product, 'frameworkPaths');
- var systemFrameworkPaths = ModUtils.moduleProperties(product, 'systemFrameworkPaths');
- var frameworks = ModUtils.modulePropertiesFromArtifacts(product, inputs.dynamiclibrary, 'cpp', 'frameworks');
- var weakFrameworks = ModUtils.modulePropertiesFromArtifacts(product, inputs.dynamiclibrary, 'cpp', 'weakFrameworks');
- var rpaths = ModUtils.moduleProperties(product, 'rpaths');
var platformLinkerFlags = ModUtils.moduleProperties(product, 'platformLinkerFlags');
var linkerFlags = ModUtils.moduleProperties(product, 'linkerFlags');
var commands = [];
@@ -95,30 +87,11 @@ CppModule {
else
args.push('--sysroot=' + sysroot);
}
- var staticLibrariesI = [];
- for (i in inputs.staticlibrary) {
- staticLibrariesI.push(inputs.staticlibrary[i].fileName);
- }
- staticLibrariesI = staticLibrariesI.concat(staticLibraries);
-
- var frameworksI = frameworks;
- for (i in inputs.framework) {
- fileName = inputs.framework[i].fileName;
- frameworkPaths.push(FileInfo.path(fileName));
- fileName = Gcc.removePrefixAndSuffix(FileInfo.fileName(fileName),
- ModUtils.moduleProperty(product, "dynamicLibraryPrefix"),
- ModUtils.moduleProperty(product, "dynamicLibrarySuffix"));
- frameworksI.push(fileName);
- }
-
- var weakFrameworksI = weakFrameworks;
args.push('-o');
args.push(output.fileName);
- args = args.concat(Gcc.libraryLinkerFlags(libraryPaths, frameworkPaths, systemFrameworkPaths, rpaths, dynamicLibraries, staticLibrariesI, frameworksI, weakFrameworksI));
+ args = args.concat(Gcc.libraryLinkerFlags(product, inputs));
args = args.concat(Gcc.additionalCompilerAndLinkerFlags(product));
- for (i in inputs.dynamiclibrary)
- args.push(inputs.dynamiclibrary[i].fileName);
var cmd = new Command(ModUtils.moduleProperty(product, "compilerPath"), args);
cmd.description = 'linking ' + FileInfo.fileName(output.fileName);
cmd.highlight = 'linker';
@@ -204,14 +177,6 @@ CppModule {
}
prepare: {
- var libraryPaths = ModUtils.moduleProperties(product, 'libraryPaths');
- var dynamicLibraries = ModUtils.modulePropertiesFromArtifacts(product, inputs.dynamiclibrary, 'cpp', 'dynamicLibraries');
- var staticLibraries = ModUtils.modulePropertiesFromArtifacts(product, inputs.staticlibrary, 'cpp', 'staticLibraries');
- var frameworkPaths = ModUtils.moduleProperties(product, 'frameworkPaths');
- var systemFrameworkPaths = ModUtils.moduleProperties(product, 'systemFrameworkPaths');
- var frameworks = ModUtils.modulePropertiesFromArtifacts(product, inputs.dynamiclibrary, 'cpp', 'frameworks');
- var weakFrameworks = ModUtils.modulePropertiesFromArtifacts(product, inputs.dynamiclibrary, 'cpp', 'weakFrameworks');
- var rpaths = ModUtils.moduleProperties(product, 'rpaths');
var platformLinkerFlags = ModUtils.moduleProperties(product, 'platformLinkerFlags');
var linkerFlags = ModUtils.moduleProperties(product, 'linkerFlags');
var args = Gcc.configFlags(product);
@@ -254,29 +219,6 @@ CppModule {
args.push('-o');
args.push(output.fileName);
- var staticLibrariesI = [];
- for (i in inputs.staticlibrary) {
- staticLibrariesI.push(inputs.staticlibrary[i].fileName);
- }
- staticLibrariesI = staticLibrariesI.concat(staticLibraries);
-
- var dynamicLibrariesI = [];
- var dllPrefix = ModUtils.moduleProperty(product, "dynamicLibraryPrefix")
- var dllSuffix = ModUtils.moduleProperty(product, "dynamicLibrarySuffix")
- for (i in dynamicLibraries) {
- if (dynamicLibraries[i].match("^" + dllPrefix + ".*\\" + dllSuffix + "$") !== null) {
- // shared object filename found
- var libDir = FileInfo.path(dynamicLibraries[i])
- var libName = FileInfo.fileName(dynamicLibraries[i])
- libName = Gcc.removePrefixAndSuffix(libName, dllPrefix, dllSuffix);
- libraryPaths.push(libDir)
- dynamicLibrariesI.push(libName)
- } else {
- // shared object libname found
- dynamicLibrariesI.push(dynamicLibraries[i])
- }
- }
-
if (product.moduleProperty("qbs", "targetOS").contains('linux')) {
var transitiveSOs = ModUtils.modulePropertiesFromArtifacts(product, inputs.dynamiclibrary, 'cpp', 'transitiveSOs')
for (i in transitiveSOs) {
@@ -284,20 +226,8 @@ CppModule {
}
}
- var frameworksI = frameworks;
- for (i in inputs.frameworkbundle) {
- fileName = inputs.frameworkbundle[i].fileName;
- frameworkPaths.push(FileInfo.path(fileName));
- fileName = Gcc.removePrefixAndSuffix(FileInfo.fileName(fileName), "", ".framework");
- frameworksI.push(fileName);
- }
-
- var weakFrameworksI = weakFrameworks;
-
- args = args.concat(Gcc.libraryLinkerFlags(libraryPaths, frameworkPaths, systemFrameworkPaths, rpaths, dynamicLibrariesI, staticLibrariesI, frameworksI, weakFrameworksI));
+ args = args.concat(Gcc.libraryLinkerFlags(product, inputs));
args = args.concat(Gcc.additionalCompilerAndLinkerFlags(product));
- for (i in inputs.dynamiclibrary)
- args.push(inputs.dynamiclibrary[i].fileName);
var cmd = new Command(ModUtils.moduleProperty(product, "compilerPath"), args);
cmd.description = 'linking ' + FileInfo.fileName(output.fileName);
cmd.highlight = 'linker'
@@ -318,10 +248,6 @@ CppModule {
}
prepare: {
- var includePaths = ModUtils.moduleProperties(input, 'includePaths');
- var frameworkPaths = ModUtils.moduleProperties(product, 'frameworkPaths');
- var systemIncludePaths = ModUtils.moduleProperties(input, 'systemIncludePaths');
- var systemFrameworkPaths = ModUtils.moduleProperties(input, 'systemFrameworkPaths');
var cFlags = ModUtils.moduleProperties(input, 'cFlags');
var cxxFlags = ModUtils.moduleProperties(input, 'cxxFlags');
var objcFlags = ModUtils.moduleProperties(input, 'objcFlags');
@@ -387,7 +313,7 @@ CppModule {
}
}
args = args.concat(ModUtils.moduleProperties(input, 'commonCompilerFlags'));
- args = args.concat(Gcc.additionalCompilerFlags(product, includePaths, frameworkPaths, systemIncludePaths, systemFrameworkPaths, input.fileName, output));
+ args = args.concat(Gcc.additionalCompilerFlags(product, input, output));
args = args.concat(Gcc.additionalCompilerAndLinkerFlags(product));
var cmd = new Command(ModUtils.moduleProperty(product, "compilerPath"), args);
cmd.description = 'compiling ' + FileInfo.fileName(input.fileName);
@@ -406,17 +332,12 @@ CppModule {
}
prepare: {
var args = Gcc.configFlags(product);
- var includePaths = ModUtils.moduleProperties(input, 'includePaths');
- var frameworkPaths = ModUtils.moduleProperties(product, 'frameworkPaths');
- var systemIncludePaths = ModUtils.moduleProperties(input, 'systemIncludePaths');
- var systemFrameworkPaths = ModUtils.moduleProperties(input, 'systemFrameworkPaths');
args.push('-x');
args.push('c++-header');
var cxxFlags = ModUtils.moduleProperty(product, "cxxFlags")
if (cxxFlags)
args = args.concat(cxxFlags);
- args = args.concat(Gcc.additionalCompilerFlags(product, includePaths, frameworkPaths, systemIncludePaths,
- systemFrameworkPaths, ModUtils.moduleProperty(product, "precompiledHeader"), output));
+ args = args.concat(Gcc.additionalCompilerFlags(product, input, output));
args = args.concat(Gcc.additionalCompilerAndLinkerFlags(product));
var cmd = new Command(ModUtils.moduleProperty(product, "compilerPath"), args);
cmd.description = 'precompiling ' + FileInfo.fileName(input.fileName);
diff --git a/share/qbs/modules/cpp/gcc.js b/share/qbs/modules/cpp/gcc.js
index 04c25808a..9771f3b82 100644
--- a/share/qbs/modules/cpp/gcc.js
+++ b/share/qbs/modules/cpp/gcc.js
@@ -1,37 +1,79 @@
-function libraryLinkerFlags(libraryPaths, frameworkPaths, systemFrameworkPaths, rpaths, dynamicLibraries, staticLibraries, frameworks, weakFrameworks)
+function libraryLinkerFlags(product, inputs)
{
- var i;
- var args = [];
+ var libraryPaths = ModUtils.moduleProperties(product, 'libraryPaths');
+ var dynamicLibraries = ModUtils.modulePropertiesFromArtifacts(product, inputs.dynamiclibrary, 'cpp', 'dynamicLibraries');
+ var staticLibraries = ModUtils.modulePropertiesFromArtifacts(product, inputs.staticlibrary, 'cpp', 'staticLibraries');
+ var frameworkPaths = ModUtils.moduleProperties(product, 'frameworkPaths');
+ var systemFrameworkPaths = ModUtils.moduleProperties(product, 'systemFrameworkPaths');
+ var frameworks = ModUtils.modulePropertiesFromArtifacts(product, inputs.dynamiclibrary, 'cpp', 'frameworks');
+ var weakFrameworks = ModUtils.modulePropertiesFromArtifacts(product, inputs.dynamiclibrary, 'cpp', 'weakFrameworks');
+ var rpaths = ModUtils.moduleProperties(product, 'rpaths');
+ var args = [], i, prefix, suffix;
+
if (rpaths && rpaths.length)
args.push('-Wl,-rpath,' + rpaths.join(",-rpath,"));
- for (i in libraryPaths) {
- args.push('-L' + libraryPaths[i]);
- }
+
+ // Add filenames of internal library dependencies to the lists
+ for (i in inputs.staticlibrary)
+ staticLibraries.unshift(inputs.staticlibrary[i].fileName);
+ for (i in inputs.dynamiclibrary)
+ dynamicLibraries.unshift(inputs.dynamiclibrary[i].fileName);
+ for (i in inputs.frameworkbundle)
+ frameworks.unshift(inputs.frameworkbundle[i].fileName);
+
+ // Flags for library search paths
+ if (libraryPaths)
+ args = args.concat(libraryPaths.map(function(path) { return '-L' + path }));
+ if (frameworkPaths)
+ args = args.concat(frameworkPaths.map(function(path) { return '-F' + path }));
+ if (systemFrameworkPaths)
+ args = args.concat(systemFrameworkPaths.map(function(path) { return '-iframework' + path }));
+
+ prefix = ModUtils.moduleProperty(product, "staticLibraryPrefix");
+ suffix = ModUtils.moduleProperty(product, "staticLibrarySuffix");
for (i in staticLibraries) {
- if (staticLibraries[i].match(/\.(a|lib)$/i)) {
+ if (isLibraryFileName(product, FileInfo.fileName(staticLibraries[i]), prefix, suffix, false))
args.push(staticLibraries[i]);
- } else {
+ else
args.push('-l' + staticLibraries[i]);
- }
}
+
+ prefix = ModUtils.moduleProperty(product, "dynamicLibraryPrefix");
+ suffix = ModUtils.moduleProperty(product, "dynamicLibrarySuffix");
for (i in dynamicLibraries) {
- if (FileInfo.isAbsolutePath(dynamicLibraries[i])) {
+ if (isLibraryFileName(product, FileInfo.fileName(dynamicLibraries[i]), prefix, suffix, true))
args.push(dynamicLibraries[i]);
- } else {
+ else
args.push('-l' + dynamicLibraries[i]);
- }
}
- if (frameworkPaths)
- args = args.concat(frameworkPaths.map(function(path) { return '-F' + path }));
- if (systemFrameworkPaths)
- args = args.concat(systemFrameworkPaths.map(function(path) { return '-iframework' + path }));
- for (i in frameworks)
- args = args.concat(['-framework', frameworks[i]]);
- for (i in weakFrameworks)
- args = args.concat(['-weak_framework', weakFrameworks[i]]);
+
+ suffix = ".framework";
+ for (i in frameworks) {
+ if (frameworks[i].slice(-suffix.length) === suffix)
+ args.push(frameworks[i] + "/" + FileInfo.fileName(frameworks[i]).slice(0, -suffix.length));
+ else
+ args = args.concat(['-framework', frameworks[i]]);
+ }
+
+ for (i in weakFrameworks) {
+ if (weakFrameworks[i].slice(-suffix.length) === suffix)
+ args.push(weakFrameworks[i] + "/" + FileInfo.fileName(weakFrameworks[i]).slice(0, -suffix.length));
+ else
+ args = args.concat(['-weak_framework', weakFrameworks[i]]);
+ }
+
return args;
}
+// Returns whether the string looks like a library filename
+function isLibraryFileName(product, fileName, prefix, suffix, isShared)
+{
+ var os = product.moduleProperty("qbs", "targetOS");
+ if (os.contains("unix") && !os.contains("darwin") && isShared)
+ suffix += "(\\.[0-9]+){0,3}";
+ return fileName.match("^" + prefix + ".+?\\" + suffix + "$");
+}
+
// for compiler AND linker
function configFlags(config) {
var args = [];
@@ -70,8 +112,13 @@ function removePrefixAndSuffix(str, prefix, suffix)
// ### what we actually need here is something like product.usedFileTags
// that contains all fileTags that have been used when applying the rules.
-function additionalCompilerFlags(product, includePaths, frameworkPaths, systemIncludePaths, systemFrameworkPaths, fileName, output)
+function additionalCompilerFlags(product, input, output)
{
+ var includePaths = ModUtils.moduleProperties(input, 'includePaths');
+ var frameworkPaths = ModUtils.moduleProperties(product, 'frameworkPaths');
+ var systemIncludePaths = ModUtils.moduleProperties(input, 'systemIncludePaths');
+ var systemFrameworkPaths = ModUtils.moduleProperties(input, 'systemFrameworkPaths');
+
var EffectiveTypeEnum = { UNKNOWN: 0, LIB: 1, APP: 2 };
var effectiveType = EffectiveTypeEnum.UNKNOWN;
var libTypes = {staticlibrary : 1, dynamiclibrary : 1, frameworkbundle : 1};
@@ -138,7 +185,7 @@ function additionalCompilerFlags(product, includePaths, frameworkPaths, systemIn
}
args.push('-c');
- args.push(fileName);
+ args.push(input.fileName);
args.push('-o');
args.push(output.fileName);
return args