Skip to content

Commit 24547f5

Browse files
committed
Add guide for how to use embedAndSign to bundle frameworks in Xcode
1 parent 747de22 commit 24547f5

File tree

2 files changed

+65
-1
lines changed

2 files changed

+65
-1
lines changed
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
---
2+
title: Embedding Frameworks in Xcode for App Distribution
3+
---
4+
5+
In order to build a distributeable mac app it is typical to embed the resources your app depends on, including libraries and frameworks, inside the .app folder structure itself. Additionally you must sign all bundled executables for the app to be accepted for notarization.
6+
7+
The snippet below shows an example of the Xcode specific settings you need to set so that you can generate a *.xcodeproj* and have it build an app ready for distribution without needing to manually adjust settings in the Xcode UI.
8+
9+
Before attempting to setup your premake generated project make sure you are able to set all the required settings manually from the UI at least once, and export your app successfully for distribution. Doing this will allow Xcode to handle any one time setup or certificate generation for you, and provide you with a point of comparison if your generated project has issues.
10+
11+
Some things to note:
12+
* *Info.plist* and *.entitlements* files need to be specified twice. Once in the `files` section where paths are relative to the premake script, and once under `xcodebuildsettings` where the path is relative to the generated *.xcodeproj*.
13+
* Adding a third party framework such as *SDL2.framework* requires four steps. `links` to link the framework, `frameworkdirs` to tell Xcode where to find it while building, `sysincludedirs` points to the framework headers, and `embedAndSign` to correctly embed the framework.
14+
* `@executable_path/../Frameworks` must be added to `"LD_RUNPATH_SEARCH_PATHS"` to tell the built executable where to search for frameworks inside the .app bundle.
15+
16+
```lua
17+
-- mac specific settings
18+
filter "action:xcode4"
19+
files {
20+
"source/mac/Info.plist", -- add your own your .plist and .entitlements so you can customise them
21+
"source/mac/app.entitlements",
22+
}
23+
24+
links {
25+
"third_party/sdl2/macos/SDL2.framework", -- relative path to third party frameworks
26+
"CoreFoundation.framework", -- no path needed for system frameworks
27+
"OpenGL.framework",
28+
}
29+
30+
sysincludedirs {
31+
"third_party/sdl2/macos/SDL2.framework/Headers", -- need to explicitly add path to framework headers
32+
}
33+
34+
frameworkdirs {
35+
"third_party/sdl2/macos/", -- path to search for third party frameworks
36+
}
37+
38+
embedAndSign {
39+
"SDL2.framework" -- bundle the framework into the built .app and sign with your certificate
40+
}
41+
42+
xcodebuildsettings {
43+
["MACOSX_DEPLOYMENT_TARGET"] = "10.11",
44+
["PRODUCT_BUNDLE_IDENTIFIER"] = 'com.yourdomain.yourapp',
45+
["CODE_SIGN_STYLE"] = "Automatic",
46+
["DEVELOPMENT_TEAM"] = '1234ABCD56', -- your dev team id
47+
["INFOPLIST_FILE"] = "../../source/mac/Info.plist", -- path is relative to the generated project file
48+
["CODE_SIGN_ENTITLEMENTS"] = ("../../source/mac/app.entitlements"), -- ^
49+
["ENABLE_HARDENED_RUNTIME"] = "YES", -- hardened runtime is required for notarization
50+
["CODE_SIGN_IDENTITY"] = "Apple Development", -- sets 'Signing Certificate' to 'Development'. Defaults to 'Sign to Run Locally'. not doing this will crash your app if you upgrade the project when prompted by Xcode
51+
["LD_RUNPATH_SEARCH_PATHS"] = "$(inherited) @executable_path/../Frameworks", -- tell the executable where to find the frameworks. Path is relative to executable location inside .app bundle
52+
}
53+
```
54+
55+
### See Also
56+
57+
* [embed](embed.md)
58+
* [embedAndSign](embedandsign.md)
59+
60+
### External Resources
61+
62+
* [All About Notarization at WWDC2019](https://developer.apple.com/videos/play/wwdc2019/703)
63+
* [Notarizing macOS software before distribution](https://developer.apple.com/documentation/security/notarizing_macos_software_before_distribution)

website/sidebars.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ module.exports = {
4747
type: 'category',
4848
label: 'Guides',
4949
items: [
50-
'Sharing-Configuration-Settings'
50+
'Sharing-Configuration-Settings',
51+
'Embedding-Frameworks-in-Xcode'
5152
]
5253
},
5354
{

0 commit comments

Comments
 (0)