diff options
author | Jake Petroules <jake.petroules@petroules.com> | 2013-03-13 16:04:25 -0400 |
---|---|---|
committer | Joerg Bornemann <joerg.bornemann@digia.com> | 2013-03-20 18:32:05 +0100 |
commit | 84f5d13adb3ab6dc9510a3e512799bff13d6d01d (patch) | |
tree | 0c18ab88ad2d0b035e75738730d47695ca7d6f73 /share/qbs/modules/cpp | |
parent | 91b271353f75e17addf3aa70bc7a1a55f360da32 (diff) |
Add support for setting the minimum operating system target version.
Task-number: QBS-226
Change-Id: I85c6e24ecfe6b90d33df17589f151e4082b53d58
Reviewed-by: Joerg Bornemann <joerg.bornemann@digia.com>
Diffstat (limited to 'share/qbs/modules/cpp')
-rw-r--r-- | share/qbs/modules/cpp/CppModule.qbs | 43 | ||||
-rw-r--r-- | share/qbs/modules/cpp/GenericGCC.qbs | 33 | ||||
-rw-r--r-- | share/qbs/modules/cpp/gcc.js | 36 | ||||
-rw-r--r-- | share/qbs/modules/cpp/msvc.js | 30 | ||||
-rw-r--r-- | share/qbs/modules/cpp/windows-msvc.qbs | 1 | ||||
-rw-r--r-- | share/qbs/modules/cpp/windows.js | 22 |
6 files changed, 148 insertions, 17 deletions
diff --git a/share/qbs/modules/cpp/CppModule.qbs b/share/qbs/modules/cpp/CppModule.qbs index 33cefca67..b29e997f8 100644 --- a/share/qbs/modules/cpp/CppModule.qbs +++ b/share/qbs/modules/cpp/CppModule.qbs @@ -19,6 +19,49 @@ Module { description: "preprocessor macros that are defined when using this particular compiler" } + property string minimumWindowsVersion + PropertyOptions { + name: "minimumWindowsVersion" + description: "a version number in the format [major].[minor] indicating the earliest \ + version of Windows that the product should run on. defines WINVER, \ + _WIN32_WINNT, and _WIN32_WINDOWS, and applies a version number to the \ + linker flags /SUBSYSTEM and /OSVERSION (or -Wl,-subsystem and -Wl,-osversion). \ + if undefined, compiler defaults will be used." + } + + property string minimumMacVersion + PropertyOptions { + name: "minimumMacVersion" + description: "a version number in the format [major].[minor] indicating the earliest \ + version of OS X that the product should run on. passes -mmacosx-version-min=<version> \ + to the compiler. if undefined, compiler defaults will be used." + } + + property string minimumIosVersion + PropertyOptions { + name: "minimumIosVersion" + description: "a version number in the format [major].[minor] indicating the earliest \ + version of iOS that the product should run on. passes -miphoneos-version-min=<version> \ + to the compiler. if undefined, compiler defaults will be used." + } + + property string minimumAndroidVersion + PropertyOptions { + name: "minimumAndroidVersion" + description: "a version number in the format [major].[minor] indicating the earliest \ + version of Android that the product should run on. this value is converted into an SDK \ + version which is then written to AndroidManifest.xml." + } + + property string maximumAndroidVersion + PropertyOptions { + name: "maximumAndroidVersion" + description: "a version number in the format [major].[minor] indicating the latest \ + version of Android that the product should run on. this value is converted into an SDK \ + version which is then written to AndroidManifest.xml. if undefined, no upper limit will \ + be set." + } + property pathList includePaths property pathList systemIncludePaths property pathList libraryPaths diff --git a/share/qbs/modules/cpp/GenericGCC.qbs b/share/qbs/modules/cpp/GenericGCC.qbs index 43f4abe24..050ac83ff 100644 --- a/share/qbs/modules/cpp/GenericGCC.qbs +++ b/share/qbs/modules/cpp/GenericGCC.qbs @@ -1,5 +1,6 @@ import qbs 1.0 import qbs.fileinfo as FileInfo +import 'windows.js' as Windows import 'gcc.js' as Gcc import '../utils.js' as ModUtils @@ -101,7 +102,8 @@ CppModule { args.push('-o'); args.push(output.fileName); - args = args.concat(Gcc.libs(libraryPaths, frameworkPaths, systemFrameworkPaths, rpaths, dynamicLibraries, staticLibrariesI, frameworksI, weakFrameworksI)); + args = args.concat(Gcc.libraryLinkerFlags(libraryPaths, frameworkPaths, systemFrameworkPaths, rpaths, dynamicLibraries, staticLibrariesI, frameworksI, weakFrameworksI)); + 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); @@ -188,12 +190,20 @@ CppModule { args = args.concat(platformLinkerFlags); for (i in linkerFlags) args.push(linkerFlags[i]) - if (product.consoleApplication !== undefined - && product.moduleProperty("qbs", "toolchain") === "mingw") { - if (product.consoleApplication) - args.push("-Wl,-subsystem,console"); - else - args.push("-Wl,-subsystem,windows"); + if (product.moduleProperty("qbs", "toolchain") === "mingw") { + var subsystemSwitch = product.consoleApplication ? "-Wl,-subsystem,console" : "-Wl,-subsystem,windows"; + + var minimumWindowsVersion = ModUtils.moduleProperty(product, "minimumWindowsVersion"); + if (minimumWindowsVersion) { + var subsystemVersion = Windows.getWindowsVersionInFormat(minimumWindowsVersion, 'subsystem'); + if (subsystemVersion) { + args.push(subsystemSwitch + ',' + subsystemVersion); + args.push("-Wl,-osversion," + subsystemVersion); + } else { + print('WARNING: Unknown Windows version "' + minimumWindowsVersion + '"'); + args.push(subsystemSwitch); + } + } } args.push('-o'); args.push(output.fileName); @@ -238,7 +248,8 @@ CppModule { var weakFrameworksI = weakFrameworks; - args = args.concat(Gcc.libs(libraryPaths, frameworkPaths, systemFrameworkPaths, rpaths, dynamicLibrariesI, staticLibrariesI, frameworksI, weakFrameworksI)); + args = args.concat(Gcc.libraryLinkerFlags(libraryPaths, frameworkPaths, systemFrameworkPaths, rpaths, dynamicLibrariesI, staticLibrariesI, frameworksI, weakFrameworksI)); + 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); @@ -327,7 +338,8 @@ CppModule { break; } } - args = args.concat(Gcc.additionalFlags(product, includePaths, frameworkPaths, systemIncludePaths, systemFrameworkPaths, input.fileName, output)) + args = args.concat(Gcc.additionalCompilerFlags(product, includePaths, frameworkPaths, systemIncludePaths, systemFrameworkPaths, input.fileName, output)); + args = args.concat(Gcc.additionalCompilerAndLinkerFlags(product)); var cmd = new Command(ModUtils.moduleProperty(product, "compilerPath"), args); cmd.description = 'compiling ' + FileInfo.fileName(input.fileName); cmd.highlight = "compiler"; @@ -353,8 +365,9 @@ CppModule { var cxxFlags = ModUtils.moduleProperty(product, "cxxFlags") if (cxxFlags) args = args.concat(cxxFlags); - args = args.concat(Gcc.additionalFlags(product, includePaths, frameworkPaths, systemIncludePaths, + args = args.concat(Gcc.additionalCompilerFlags(product, includePaths, frameworkPaths, systemIncludePaths, systemFrameworkPaths, ModUtils.moduleProperty(product, "precompiledHeader"), output)); + args = args.concat(Gcc.additionalCompilerAndLinkerFlags(product)); var cmd = new Command(ModUtils.moduleProperty(product, "compilerPath"), args); cmd.description = 'precompiling ' + FileInfo.fileName(input.fileName); return cmd; diff --git a/share/qbs/modules/cpp/gcc.js b/share/qbs/modules/cpp/gcc.js index ec7831d94..e4b4e793c 100644 --- a/share/qbs/modules/cpp/gcc.js +++ b/share/qbs/modules/cpp/gcc.js @@ -1,4 +1,4 @@ -function libs(libraryPaths, frameworkPaths, systemFrameworkPaths, rpaths, dynamicLibraries, staticLibraries, frameworks, weakFrameworks) +function libraryLinkerFlags(libraryPaths, frameworkPaths, systemFrameworkPaths, rpaths, dynamicLibraries, staticLibraries, frameworks, weakFrameworks) { var i; var args = []; @@ -32,6 +32,7 @@ function libs(libraryPaths, frameworkPaths, systemFrameworkPaths, rpaths, dynami return args; } +// for compiler AND linker function configFlags(config) { var args = []; @@ -69,7 +70,7 @@ 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 additionalFlags(product, includePaths, frameworkPaths, systemIncludePaths, systemFrameworkPaths, fileName, output) +function additionalCompilerFlags(product, includePaths, frameworkPaths, systemIncludePaths, systemFrameworkPaths, fileName, output) { var args = [] if (product.type.indexOf('staticlibrary') >= 0 || product.type.indexOf('dynamiclibrary') >= 0) { @@ -103,9 +104,40 @@ function additionalFlags(product, includePaths, frameworkPaths, systemIncludePat args.push('-isystem' + systemIncludePaths[i]); for (i in systemFrameworkPaths) args.push('-iframework' + systemFrameworkPaths[i]); + + var minimumWindowsVersion = ModUtils.moduleProperty(product, "minimumWindowsVersion"); + if (minimumWindowsVersion && product.moduleProperty("qbs", "targetOS") === "windows") { + var hexVersion = Windows.getWindowsVersionInFormat(minimumWindowsVersion, 'hex'); + if (hexVersion) { + var versionDefs = [ 'WINVER', '_WIN32_WINNT', '_WIN32_WINDOWS' ]; + for (i in versionDefs) + args.push('-D' + versionDefs[i] + '=' + hexVersion); + } else { + print('WARNING: Unknown Windows version "' + minimumWindowsVersion + '"'); + } + } + args.push('-c'); args.push(fileName); args.push('-o'); args.push(output.fileName); return args } + +function additionalCompilerAndLinkerFlags(product) { + var args = [] + + var minimumMacVersion = ModUtils.moduleProperty(product, "minimumMacVersion"); + if (minimumMacVersion && product.moduleProperty("qbs", "targetOS") === "mac") + args.push('-mmacosx-version-min=' + minimumMacVersion); + + var minimumiOSVersion = ModUtils.moduleProperty(product, "minimumIosVersion"); + if (minimumiOSVersion && product.moduleProperty("qbs", "targetOS") === "ios") { + if (product.moduleProperty("qbs", "architecture") === "x86") + args.push('-mios-simulator-version-min=' + minimumiOSVersion); + else + args.push('-miphoneos-version-min=' + minimumiOSVersion); + } + + return args +} diff --git a/share/qbs/modules/cpp/msvc.js b/share/qbs/modules/cpp/msvc.js index 288badb0a..257705b32 100644 --- a/share/qbs/modules/cpp/msvc.js +++ b/share/qbs/modules/cpp/msvc.js @@ -42,6 +42,19 @@ function prepareCompiler(product, input, outputs, platformDefines, defines, incl for (i in defines) args.push('/D' + defines[i]) + var minimumWindowsVersion = ModUtils.moduleProperty(product, "minimumWindowsVersion"); + if (minimumWindowsVersion) { + var hexVersion = Windows.getWindowsVersionInFormat(minimumWindowsVersion, 'hex'); + if (hexVersion) { + var versionDefs = [ 'WINVER', '_WIN32_WINNT', '_WIN32_WINDOWS' ]; + for (i in versionDefs) { + args.push('/D' + versionDefs[i] + '=' + hexVersion); + } + } else { + print('WARNING: Unknown Windows version "' + minimumWindowsVersion + '"'); + } + } + var objOutput = outputs.obj ? outputs.obj[0] : undefined var pchOutput = outputs["c++_pch"] ? outputs["c++_pch"][0] : undefined @@ -108,11 +121,18 @@ function prepareLinker(product, inputs, outputs, libraryPaths, dynamicLibraries, else args.push('/INCREMENTAL:NO') - if (product.consoleApplication !== undefined) { - if (product.consoleApplication) - args.push('/SUBSYSTEM:CONSOLE'); - else - args.push('/SUBSYSTEM:WINDOWS'); + var subsystemSwitch = product.consoleApplication ? '/SUBSYSTEM:CONSOLE' : '/SUBSYSTEM:WINDOWS'; + + var minimumWindowsVersion = ModUtils.moduleProperty(product, "minimumWindowsVersion"); + if (minimumWindowsVersion) { + var subsystemVersion = Windows.getWindowsVersionInFormat(minimumWindowsVersion, 'subsystem'); + if (subsystemVersion) { + args.push(subsystemSwitch + ',' + subsystemVersion); + args.push('/OSVERSION:' + subsystemVersion); + } else { + print('WARNING: Unknown Windows version "' + minimumWindowsVersion + '"'); + args.push(subsystemSwitch); + } } var linkerOutputNativeFilePath; diff --git a/share/qbs/modules/cpp/windows-msvc.qbs b/share/qbs/modules/cpp/windows-msvc.qbs index f0cf44270..63fdb2b04 100644 --- a/share/qbs/modules/cpp/windows-msvc.qbs +++ b/share/qbs/modules/cpp/windows-msvc.qbs @@ -1,6 +1,7 @@ import qbs 1.0 import qbs.fileinfo as FileInfo import '../utils.js' as ModUtils +import 'windows.js' as Windows import 'msvc.js' as MSVC CppModule { diff --git a/share/qbs/modules/cpp/windows.js b/share/qbs/modules/cpp/windows.js new file mode 100644 index 000000000..677a450ce --- /dev/null +++ b/share/qbs/modules/cpp/windows.js @@ -0,0 +1,22 @@ +function getWindowsVersionInFormat(systemVersion, format) { + // Add new Windows versions to this list when they are released + var realVersions = [ '6.2', '6.1', '6.0', '5.2', '5.1', '5.0', '4.0' ]; + for (i in realVersions) { + // Make sure the user specified a valid Windows version we have listed here + if (systemVersion === realVersions[i]) { + var major = parseInt(systemVersion.split('.')[0]); + var minor = parseInt(systemVersion.split('.')[1]); + + if (format === 'hex') { + return '0x' + major + (minor < 10 ? '0' : '') + minor; + } else if (format === 'subsystem') { + // http://msdn.microsoft.com/en-us/library/fcc1zstk.aspx + return major + '.' + (minor < 10 ? '0' : '') + minor; + } else { + throw ("Unrecognized Windows version format " + format + ". Must be in {hex, subsystem}."); + } + } + } + + return undefined +} |