summaryrefslogtreecommitdiff
path: root/src/contrib/SDL-3.2.20/docs/README-macos.md
diff options
context:
space:
mode:
Diffstat (limited to 'src/contrib/SDL-3.2.20/docs/README-macos.md')
-rw-r--r--src/contrib/SDL-3.2.20/docs/README-macos.md251
1 files changed, 251 insertions, 0 deletions
diff --git a/src/contrib/SDL-3.2.20/docs/README-macos.md b/src/contrib/SDL-3.2.20/docs/README-macos.md
new file mode 100644
index 0000000..e5c75c1
--- /dev/null
+++ b/src/contrib/SDL-3.2.20/docs/README-macos.md
@@ -0,0 +1,251 @@
1# macOS
2
3These instructions are for people using Apple's macOS.
4
5From the developer's point of view, macOS is a sort of hybrid Mac and
6Unix system, and you have the option of using either traditional
7command line tools or Apple's IDE Xcode.
8
9# Command Line Build
10
11To build SDL using the command line, use the CMake build script:
12
13```bash
14mkdir build
15cd build
16cmake .. -DCMAKE_OSX_DEPLOYMENT_TARGET=10.13
17cmake --build .
18sudo cmake --install .
19```
20
21
22You can also build SDL as a Universal library (a single binary for both
2364-bit Intel and ARM architectures):
24
25```bash
26mkdir build
27cd build
28cmake .. "-DCMAKE_OSX_ARCHITECTURES=arm64;x86_64" -DCMAKE_OSX_DEPLOYMENT_TARGET=10.13
29cmake --build .
30sudo cmake --install .
31```
32
33Please note that building SDL requires at least Xcode 12.2 and the macOS 11.0 SDK.
34
35To use the library once it's built, you essential have two possibilities:
36use the traditional autoconf/automake/make method, or use Xcode.
37
38
39# Caveats for using SDL with macOS
40
41If you register your own NSApplicationDelegate (using [NSApp setDelegate:]),
42SDL will not register its own. This means that SDL will not terminate using
43SDL_Quit if it receives a termination request, it will terminate like a
44normal app, and it will not send a SDL_EVENT_DROP_FILE when you request to open a
45file with the app. To solve these issues, put the following code in your
46NSApplicationDelegate implementation:
47
48
49```objc
50- (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication *)sender
51{
52 if (SDL_EventEnabled(SDL_EVENT_QUIT)) {
53 SDL_Event event;
54 SDL_zero(event);
55 event.type = SDL_EVENT_QUIT;
56 SDL_PushEvent(&event);
57 }
58
59 return NSTerminateCancel;
60}
61
62- (BOOL)application:(NSApplication *)theApplication openFile:(NSString *)filename
63{
64 if (SDL_EventEnabled(SDL_EVENT_DROP_FILE)) {
65 SDL_Event event;
66 SDL_zero(event);
67 event.type = SDL_EVENT_DROP_FILE;
68 event.drop.file = SDL_strdup([filename UTF8String]);
69 return SDL_PushEvent(&event);
70 }
71
72 return NO;
73}
74```
75
76# Using the Simple DirectMedia Layer with a traditional Makefile
77
78An existing build system for your SDL app has good chances to work almost
79unchanged on macOS, as long as you link with the SDL framework. However,
80to produce a "real" Mac binary that you can distribute to users, you need
81to put the generated binary into a so called "bundle", which is basically
82a fancy folder with a name like "MyCoolGame.app".
83
84To get this build automatically, add something like the following rule to
85your Makefile.am:
86
87```make
88bundle_contents = APP_NAME.app/Contents
89APP_NAME_bundle: EXE_NAME
90 mkdir -p $(bundle_contents)/MacOS
91 mkdir -p $(bundle_contents)/Resources
92 echo "APPL????" > $(bundle_contents)/PkgInfo
93 $(INSTALL_PROGRAM) $< $(bundle_contents)/MacOS/
94```
95
96You should replace `EXE_NAME` with the name of the executable. `APP_NAME` is
97what will be visible to the user in the Finder. Usually it will be the same
98as `EXE_NAME` but capitalized. E.g. if `EXE_NAME` is "testgame" then `APP_NAME`
99usually is "TestGame". You might also want to use `@PACKAGE@` to use the
100package name as specified in your configure.ac file.
101
102If your project builds more than one application, you will have to do a bit
103more. For each of your target applications, you need a separate rule.
104
105If you want the created bundles to be installed, you may want to add this
106rule to your Makefile.am:
107
108```make
109install-exec-hook: APP_NAME_bundle
110 rm -rf $(DESTDIR)$(prefix)/Applications/APP_NAME.app
111 mkdir -p $(DESTDIR)$(prefix)/Applications/
112 cp -r $< /$(DESTDIR)$(prefix)Applications/
113```
114
115This rule takes the Bundle created by the rule from step 3 and installs them
116into "$(DESTDIR)$(prefix)/Applications/".
117
118Again, if you want to install multiple applications, you will have to augment
119the make rule accordingly.
120
121But beware! That is only part of the story! With the above, you end up with
122a barebones .app bundle, which is double-clickable from the Finder. But
123there are some more things you should do before shipping your product...
124
1251. You'll need to copy the SDL framework into the Contents/Frameworks
126 folder in your bundle, so it is included along with your application.
127
1282. Add an 'Info.plist' to your application. That is a special XML file which
129 contains some meta-information about your application (like some copyright
130 information, the version of your app, the name of an optional icon file,
131 and other things). Part of that information is displayed by the Finder
132 when you click on the .app, or if you look at the "Get Info" window.
133 More information about Info.plist files can be found on Apple's homepage.
134
135
136As a final remark, let me add that I use some of the techniques (and some
137variations of them) in [Exult](https://github.com/exult/exult) and
138[ScummVM](https://github.com/scummvm/scummvm); both are available in source on
139the net, so feel free to take a peek at them for inspiration!
140
141
142# Using the Simple DirectMedia Layer with Xcode
143
144These instructions are for using Apple's Xcode IDE to build SDL applications.
145
146## First steps
147
148The first thing to do is to unpack the Xcode.tar.gz archive in the
149top level SDL directory (where the Xcode.tar.gz archive resides).
150Because Stuffit Expander will unpack the archive into a subdirectory,
151you should unpack the archive manually from the command line:
152
153```bash
154cd [path_to_SDL_source]
155tar zxf Xcode.tar.gz
156```
157
158This will create a new folder called Xcode, which you can browse
159normally from the Finder.
160
161## Building the Framework
162
163The SDL Library is packaged as a framework bundle, an organized
164relocatable folder hierarchy of executable code, interface headers,
165and additional resources. For practical purposes, you can think of a
166framework as a more user and system-friendly shared library, whose library
167file behaves more or less like a standard UNIX shared library.
168
169To build the framework, simply open the framework project and build it.
170By default, the framework bundle "SDL.framework" is installed in
171/Library/Frameworks. Therefore, the testers and project stationary expect
172it to be located there. However, it will function the same in any of the
173following locations:
174
175* ~/Library/Frameworks
176* /Local/Library/Frameworks
177* /System/Library/Frameworks
178
179## Build Options
180
181There are two "Build Styles" (See the "Targets" tab) for SDL.
182"Deployment" should be used if you aren't tweaking the SDL library.
183"Development" should be used to debug SDL apps or the library itself.
184
185## Building the Testers
186
187Open the SDLTest project and build away!
188
189## Using the Project Stationary
190
191Copy the stationary to the indicated folders to access it from
192the "New Project" and "Add target" menus. What could be easier?
193
194## Setting up a new project by hand
195
196Some of you won't want to use the Stationary so I'll give some tips:
197
198(this is accurate as of Xcode 12.5.)
199
200* Click "File" -> "New" -> "Project...
201* Choose "macOS" and then "App" from the "Application" section.
202* Fill out the options in the next window. User interface is "XIB" and
203 Language is "Objective-C".
204* Remove "main.m" from your project
205* Remove "MainMenu.xib" from your project
206* Remove "AppDelegates.*" from your project
207* Add "\$(HOME)/Library/Frameworks/SDL.framework/Headers" to include path
208* Add "\$(HOME)/Library/Frameworks" to the frameworks search path
209* Add "-framework SDL -framework Foundation -framework AppKit" to "OTHER_LDFLAGS"
210* Add your files
211* Clean and build
212
213## Building from command line
214
215Use `xcode-build` in the same directory as your .pbxproj file
216
217## Running your app
218
219You can send command line args to your app by either invoking it from
220the command line (in *.app/Contents/MacOS) or by entering them in the
221Executables" panel of the target settings.
222
223# Implementation Notes
224
225Some things that may be of interest about how it all works...
226
227## Working directory
228
229In SDL 1.2, the working directory of your SDL app is by default set to its
230parent, but this is no longer the case in SDL 2.0 and later. SDL2 does not
231change the working directory, which means it'll be whatever the command line
232prompt that launched the program was using, or if launched by double-clicking
233in the Finder, it will be "/", the _root of the filesystem_. Plan accordingly!
234You can use SDL_GetBasePath() to find where the program is running from and
235chdir() there directly.
236
237
238## You have a Cocoa App!
239
240Your SDL app is essentially a Cocoa application. When your app
241starts up and the libraries finish loading, a Cocoa procedure is called,
242which sets up the working directory and calls your main() method.
243You are free to modify your Cocoa app with generally no consequence
244to SDL. You cannot, however, easily change the SDL window itself.
245Functionality may be added in the future to help this.
246
247# Bug reports
248
249Bugs are tracked at [the GitHub issue tracker](https://github.com/libsdl-org/SDL/issues/).
250Please feel free to report bugs there!
251