diff options
author | Fawzi Mohamed <fawzi.mohamed@digia.com> | 2013-03-19 22:02:56 +0100 |
---|---|---|
committer | Fawzi Mohamed <fawzi.mohamed@digia.com> | 2013-04-02 17:51:08 +0200 |
commit | 3059ab7aeb2695d32c1a03455e376265e3af4c1c (patch) | |
tree | 5296ef63dd65b3ff2386ac410a8324c01fa07673 /share | |
parent | 67365f0cc01233dab7ecffe17c128dd6e3e26a3d (diff) |
Add iOS module and move OS X/iOS common code to DarwinGCC
Change-Id: I2fea6a7eddd599c70336f351b6814bfe335edd79
Reviewed-by: Jake Petroules <jake.petroules@petroules.com>
Reviewed-by: Joerg Bornemann <joerg.bornemann@digia.com>
Diffstat (limited to 'share')
-rw-r--r-- | share/qbs/modules/cpp/DarwinGCC.qbs | 69 | ||||
-rw-r--r-- | share/qbs/modules/cpp/GenericGCC.qbs | 3 | ||||
-rw-r--r-- | share/qbs/modules/cpp/darwin-tools.js | 4 | ||||
-rw-r--r-- | share/qbs/modules/cpp/ios-gcc.qbs | 193 | ||||
-rw-r--r-- | share/qbs/modules/cpp/mac-gcc.qbs | 34 |
5 files changed, 271 insertions, 32 deletions
diff --git a/share/qbs/modules/cpp/DarwinGCC.qbs b/share/qbs/modules/cpp/DarwinGCC.qbs new file mode 100644 index 000000000..10dc2ae1d --- /dev/null +++ b/share/qbs/modules/cpp/DarwinGCC.qbs @@ -0,0 +1,69 @@ +import qbs 1.0 +import '../utils.js' as ModUtils +import 'darwin-tools.js' as Tools + +UnixGCC { + condition: false + + compilerDefines: ["__GNUC__", "__APPLE__"] + dynamicLibrarySuffix: ".dylib" + + property var defaultInfoPlist + property var infoPlist: defaultInfoPlist + property bool buildDsym: qbs.buildVariant === "release" + + Rule { + multiplex: true + inputs: ["qbs"] + + Artifact { + fileName: product.targetName + ".app/" + + (product.moduleProperty("qbs", "targetOS") === "mac" ? "Contents/" : "") + + "PkgInfo" + fileTags: ["pkginfo"] + } + + prepare: { + var cmd = new JavaScriptCommand(); + cmd.description = "generating PkgInfo"; + cmd.highlight = "codegen"; + var pkgType = 'APPL'; + var pkgSign = '????'; + var infoPlist = product.moduleProperty("cpp", "infoPList"); + if (infoPlist && infoPlist.hasOwnProperty('CFBundlePackageType')) + pkgType = infoPlist['CFBundlePackageType']; + if (infoPlist && infoPlist.hasOwnProperty('CFBundleSignature')) + pkgSign = infoPlist['CFBundleSignature']; + cmd.pkgInfo = pkgType + pkgSign; + cmd.sourceCode = function() { + var pkginfo = new TextFile(outputs.pkginfo[0].fileName, TextFile.WriteOnly); + pkginfo.write(pkgInfo); + pkginfo.close(); + } + return cmd; + } + } + + Rule { + inputs: ["application"] + + Artifact { + fileName: input.fileName + ".app.dSYM" + fileTags: ["dsym"] + } + + prepare: { + if (!product.moduleProperty("cpp", "buildDsym")) { + // to be removed when dynamic dependencies work + var cmd = new JavaScriptCommand(); + cmd.description = "skipping dsym generation"; + cmd.highlight = "codegen"; + return cmd; + } + var cmd = new Command("dsymutil", ["--out=" + outputs.dsym[0].fileName, input.fileName]); + cmd.description = "generating dsym"; + cmd.highlight = "codegen"; + return cmd; + } + } +} diff --git a/share/qbs/modules/cpp/GenericGCC.qbs b/share/qbs/modules/cpp/GenericGCC.qbs index 2b56d242f..2f2d101d0 100644 --- a/share/qbs/modules/cpp/GenericGCC.qbs +++ b/share/qbs/modules/cpp/GenericGCC.qbs @@ -169,7 +169,8 @@ CppModule { Artifact { fileName: product.destinationDirectory + "/" - + (product.type === "applicationbundle" ? product.targetName + ".app/Contents/MacOS/" : "") + + (product.type !== "applicationbundle" ? "" : product.targetName + ".app/" + + (product.moduleProperty("qbs", "targetOS") !== "mac" ? "" : "Contents/MacOS/")) + ModUtils.moduleProperty(product, "executablePrefix") + product.targetName + ModUtils.moduleProperty(product, "executableSuffix") fileTags: ["application"] diff --git a/share/qbs/modules/cpp/darwin-tools.js b/share/qbs/modules/cpp/darwin-tools.js new file mode 100644 index 000000000..fd7fe83b3 --- /dev/null +++ b/share/qbs/modules/cpp/darwin-tools.js @@ -0,0 +1,4 @@ +function rfc1034(inStr) +{ + return inStr.replace(/[^-A-Za-z0-9.]/g,'-'); +} diff --git a/share/qbs/modules/cpp/ios-gcc.qbs b/share/qbs/modules/cpp/ios-gcc.qbs new file mode 100644 index 000000000..bba09d469 --- /dev/null +++ b/share/qbs/modules/cpp/ios-gcc.qbs @@ -0,0 +1,193 @@ +import qbs 1.0 +import '../utils.js' as ModUtils +import 'darwin-tools.js' as Tools + +DarwinGCC { + condition: qbs.hostOS === 'mac' && qbs.targetOS === 'ios' && qbs.toolchain === 'gcc' + + property string signingIdentity + property string provisionFile + property bool buildIpa: qbs.architecture.match("^arm") === "arm" + + defaultInfoPlist: { + var baseName = String(product.targetName).substring(product.targetName.lastIndexOf('/') + 1); + var baseNameRfc1034 = Tools.rfc1034(baseName); + var defaultVal = { + CFBundleName: baseName, + CFBundleIdentifier: "org.example." + baseNameRfc1034, + CFBundleInfoDictionaryVersion : "6.0", + CFBundleVersion: "1.0", // version of the app + CFBundleShortVersionString: "1.0", // user visible version of the app + // this and the following MainStoryboard related keys are iOS 6 only, and are only to + // use "storyboards" for UI, which we most likely won't, so we can avoid using + // these keys (and stay compatible with previous iOS versions) + // "UIMainStoryboardFile" : "MainStoryboard_iPhone", + // "UIMainStoryboardFile~ipad" : "MainStoryboard_iPad", + CFBundleExecutable: baseName, + LSRequiresIPhoneOS: true, + UIRequiredDeviceCapabilities : [ + // architectures supported, to support iPhone 3G for example one has to add + // armv6 to the list and also compile for it (with Xcode 4.4.1 or earlier) + "armv7" + ], + CFBundleDisplayName: baseName, + CFBundlePackageType: "APPL", + CFBundleSignature: "????", // legacy creator code in macOS Classic, can be ignored + CFBundleDevelopmentRegion: "en", // default localization + UISupportedInterfaceOrientations: [ + "UIInterfaceOrientationPortrait", + "UIInterfaceOrientationLandscapeLeft", + "UIInterfaceOrientationLandscapeRight" + ], + "UISupportedInterfaceOrientations~ipad": [ + "UIInterfaceOrientationPortrait", + "UIInterfaceOrientationPortraitUpsideDown", + "UIInterfaceOrientationLandscapeLeft", + "UIInterfaceOrientationLandscapeRight" + ] + } + return defaultVal + } + + Rule { + multiplex: true + inputs: ["qbs"] + + Artifact { + fileName: product.targetName + ".app/Info.plist" + fileTags: ["infoplist"] + } + + prepare: { + var cmd = new JavaScriptCommand(); + cmd.description = "generating Info.plist"; + cmd.highlight = "codegen"; + cmd.infoPlist = ModUtils.moduleProperty(product, "infoPlist") || {}; + cmd.platformPath = product.moduleProperty("cpp","platformPath"); + cmd.sourceCode = function() { + var defaultValues = ModUtils.moduleProperty(product, "defaultInfoPlist"); + var key; + for (key in defaultValues) { + if (defaultValues.hasOwnProperty(key) && !(key in infoPlist)) + infoPlist[key] = defaultValues[key]; + } + + var process; + if (platformPath) { + process = new Process(); + process.start("plutil", ["-convert", "json", "-o", "-", + platformPath + "/Info.plist"]); + process.waitForFinished(); + platformInfo = JSON.parse(process.readAll()); + + var additionalProps = platformInfo["AdditionalInfo"]; + for (key in additionalProps) { + if (additionalProps.hasOwnProperty(key) && !(key in infoPlist)) // override infoPlist? + infoPlist[key] = defaultValues[key]; + } + key = "UIDeviceFamily"; + if (key in platformInfo && !(key in infoPlist)) + infoPlist[key] = platformInfo[key]; + } else { + print("Missing platformPath property"); + } + + process = new Process(); + process.start("sw_vers", ["-buildVersion"]); + process.waitForFinished(); + infoPlist["BuildMachineOSBuild"] = process.readAll().trim(); + + var infoplist = new TextFile(outputs.infoplist[0].fileName, TextFile.WriteOnly); + infoplist.write(JSON.stringify(infoPlist)); + infoplist.close(); + + process = new Process(); + process.start("plutil", ["-convert", "binary1", outputs.infoplist[0].fileName]); + process.waitForFinished(); + } + return cmd; + } + } + + Rule { + multiplex: true + inputs: ["qbs"] + + Artifact { + fileName: product.targetName + ".app/ResourceRules.plist" + fileTags: ["resourcerules"] + } + + prepare: { + var cmd = new JavaScriptCommand(); + cmd.description = "generating ResourceRules"; + cmd.highlight = "codegen"; + cmd.sysroot = product.moduleProperty("qbs","sysroot"); + cmd.sourceCode = function() { + File.copy(sysroot + "/ResourceRules.plist", outputs.resourcerules[0].fileName); + } + return cmd; + } + } + + Rule { + multiplex: true + inputs: ["application", "infoplist", "pkginfo", "resourcerules"] + + Artifact { + fileName: product.targetName + ".ipa" + fileTags: ["ipa"] + } + + prepare: { + if (!(product.moduleProperty("qbs","architecture").match("^arm"))) { + // to be removed when dynamic dependencies work + var cmd = new JavaScriptCommand(); + cmd.description = "skipping ipa for simulator on arch " + + product.moduleProperty("qbs", "architecture"); + cmd.highlight = "codegen"; + return cmd; + } + var signingIdentity = product.moduleProperty("cpp", "signingIdentity"); + if (!signingIdentity) + throw "The name of a valid Signing identity should be stored in cpp.signingIdentity to build package."; + var provisionFile = product.moduleProperty("cpp", "provisionFile"); + if (!provisionFile) + throw "The path to a provision file is required in key cpp.provisionFile to build package."; + args = ["-sdk", "iphoneos", "PackageApplication", "-v", + product.buildDirectory + "/" + product.targetName + ".app", + "-o", outputs.ipa[0].fileName, "--sign", signingIdentity, + "--embed", provisionFile] + var command = "/usr/bin/xcrun"; + var cmd = new Command(command, args) + cmd.description = "creating ipa"; + cmd.highlight = "codegen"; + cmd.workingDirectory = product.buildDirectory; + return cmd; + } + } + + Rule { + multiplex: true + inputs: { + var res = ["application", "infoplist", "pkginfo", "resourcerules"]; + // if (product.moduleProperty("cpp", "buildDsym")) // should work like that in the future + res.push("dsym"); + // if (ModUtils.moduleProperty(product, "buildIpa")) // ditto + res.push("ipa"); + return res; + } + + Artifact { + fileName: product.targetName + ".app" + fileTags: ["applicationbundle"] + } + + prepare: { + var cmd = new JavaScriptCommand(); + cmd.description = "creating app bundle"; + cmd.highlight = "codegen"; + return cmd; + } + } +} diff --git a/share/qbs/modules/cpp/mac-gcc.qbs b/share/qbs/modules/cpp/mac-gcc.qbs index 455298534..89f239047 100644 --- a/share/qbs/modules/cpp/mac-gcc.qbs +++ b/share/qbs/modules/cpp/mac-gcc.qbs @@ -1,15 +1,10 @@ import qbs 1.0 import '../utils.js' as ModUtils +import 'darwin-tools.js' as Tools -UnixGCC { +DarwinGCC { condition: qbs.hostOS === 'mac' && qbs.targetOS === 'mac' && qbs.toolchain === 'gcc' - compilerDefines: ["__GNUC__", "__APPLE__"] - dynamicLibrarySuffix: ".dylib" - - property string infoPlist - property string pkgInfo - Rule { multiplex: true inputs: ["qbs"] @@ -76,30 +71,7 @@ UnixGCC { Rule { multiplex: true - inputs: ["qbs"] - - Artifact { - fileName: product.targetName + ".app/Contents/PkgInfo" - fileTags: ["pkginfo"] - } - - prepare: { - var cmd = new JavaScriptCommand(); - cmd.description = "generating PkgInfo"; - cmd.highlight = "codegen"; - cmd.pkgInfo = ModUtils.moduleProperty(product, "pkgInfo") || "FOO"; - cmd.sourceCode = function() { - var pkginfo = new TextFile(outputs.pkginfo[0].fileName, TextFile.WriteOnly); - pkginfo.write(pkgInfo); - pkginfo.close(); - } - return cmd; - } - } - - Rule { - multiplex: true - inputs: ["application", "infoplist", "pkginfo"] + inputs: ["application", "infoplist", "pkginfo", "dsym"] Artifact { fileName: product.targetName + ".app" |