diff options
| author | 3gg <3gg@shellblade.net> | 2025-12-27 12:03:39 -0800 |
|---|---|---|
| committer | 3gg <3gg@shellblade.net> | 2025-12-27 12:03:39 -0800 |
| commit | 5a079a2d114f96d4847d1ee305d5b7c16eeec50e (patch) | |
| tree | 8926ab44f168acf787d8e19608857b3af0f82758 /contrib/SDL-3.2.8/docs/README-macos.md | |
Initial commit
Diffstat (limited to 'contrib/SDL-3.2.8/docs/README-macos.md')
| -rw-r--r-- | contrib/SDL-3.2.8/docs/README-macos.md | 251 |
1 files changed, 251 insertions, 0 deletions
diff --git a/contrib/SDL-3.2.8/docs/README-macos.md b/contrib/SDL-3.2.8/docs/README-macos.md new file mode 100644 index 0000000..fb0639b --- /dev/null +++ b/contrib/SDL-3.2.8/docs/README-macos.md | |||
| @@ -0,0 +1,251 @@ | |||
| 1 | # macOS | ||
| 2 | |||
| 3 | These instructions are for people using Apple's macOS. | ||
| 4 | |||
| 5 | From the developer's point of view, macOS is a sort of hybrid Mac and | ||
| 6 | Unix system, and you have the option of using either traditional | ||
| 7 | command line tools or Apple's IDE Xcode. | ||
| 8 | |||
| 9 | # Command Line Build | ||
| 10 | |||
| 11 | To build SDL using the command line, use the CMake build script: | ||
| 12 | |||
| 13 | ```bash | ||
| 14 | mkdir build | ||
| 15 | cd build | ||
| 16 | cmake .. -DCMAKE_OSX_DEPLOYMENT_TARGET=10.13 | ||
| 17 | cmake --build . | ||
| 18 | sudo cmake --install . | ||
| 19 | ``` | ||
| 20 | |||
| 21 | |||
| 22 | You can also build SDL as a Universal library (a single binary for both | ||
| 23 | 64-bit Intel and ARM architectures): | ||
| 24 | |||
| 25 | ```bash | ||
| 26 | mkdir build | ||
| 27 | cd build | ||
| 28 | cmake .. "-DCMAKE_OSX_ARCHITECTURES=arm64;x86_64" -DCMAKE_OSX_DEPLOYMENT_TARGET=10.13 | ||
| 29 | cmake --build . | ||
| 30 | sudo cmake --install . | ||
| 31 | ``` | ||
| 32 | |||
| 33 | Please note that building SDL requires at least Xcode 12.2 and the macOS 11.0 SDK. | ||
| 34 | |||
| 35 | To use the library once it's built, you essential have two possibilities: | ||
| 36 | use the traditional autoconf/automake/make method, or use Xcode. | ||
| 37 | |||
| 38 | |||
| 39 | # Caveats for using SDL with macOS | ||
| 40 | |||
| 41 | If you register your own NSApplicationDelegate (using [NSApp setDelegate:]), | ||
| 42 | SDL will not register its own. This means that SDL will not terminate using | ||
| 43 | SDL_Quit if it receives a termination request, it will terminate like a | ||
| 44 | normal app, and it will not send a SDL_EVENT_DROP_FILE when you request to open a | ||
| 45 | file with the app. To solve these issues, put the following code in your | ||
| 46 | NSApplicationDelegate implementation: | ||
| 47 | |||
| 48 | |||
| 49 | ```objc | ||
| 50 | - (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication *)sender | ||
| 51 | { | ||
| 52 | if (SDL_GetEventState(SDL_EVENT_QUIT) == SDL_ENABLE) { | ||
| 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_GetEventState(SDL_EVENT_DROP_FILE) == SDL_ENABLE) { | ||
| 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 | |||
| 78 | An existing build system for your SDL app has good chances to work almost | ||
| 79 | unchanged on macOS, as long as you link with the SDL framework. However, | ||
| 80 | to produce a "real" Mac binary that you can distribute to users, you need | ||
| 81 | to put the generated binary into a so called "bundle", which is basically | ||
| 82 | a fancy folder with a name like "MyCoolGame.app". | ||
| 83 | |||
| 84 | To get this build automatically, add something like the following rule to | ||
| 85 | your Makefile.am: | ||
| 86 | |||
| 87 | ```make | ||
| 88 | bundle_contents = APP_NAME.app/Contents | ||
| 89 | APP_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 | |||
| 96 | You should replace `EXE_NAME` with the name of the executable. `APP_NAME` is | ||
| 97 | what will be visible to the user in the Finder. Usually it will be the same | ||
| 98 | as `EXE_NAME` but capitalized. E.g. if `EXE_NAME` is "testgame" then `APP_NAME` | ||
| 99 | usually is "TestGame". You might also want to use `@PACKAGE@` to use the | ||
| 100 | package name as specified in your configure.ac file. | ||
| 101 | |||
| 102 | If your project builds more than one application, you will have to do a bit | ||
| 103 | more. For each of your target applications, you need a separate rule. | ||
| 104 | |||
| 105 | If you want the created bundles to be installed, you may want to add this | ||
| 106 | rule to your Makefile.am: | ||
| 107 | |||
| 108 | ```make | ||
| 109 | install-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 | |||
| 115 | This rule takes the Bundle created by the rule from step 3 and installs them | ||
| 116 | into "$(DESTDIR)$(prefix)/Applications/". | ||
| 117 | |||
| 118 | Again, if you want to install multiple applications, you will have to augment | ||
| 119 | the make rule accordingly. | ||
| 120 | |||
| 121 | But beware! That is only part of the story! With the above, you end up with | ||
| 122 | a barebones .app bundle, which is double-clickable from the Finder. But | ||
| 123 | there are some more things you should do before shipping your product... | ||
| 124 | |||
| 125 | 1. 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 | |||
| 128 | 2. 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 | |||
| 136 | As a final remark, let me add that I use some of the techniques (and some | ||
| 137 | variations of them) in [Exult](https://github.com/exult/exult) and | ||
| 138 | [ScummVM](https://github.com/scummvm/scummvm); both are available in source on | ||
| 139 | the net, so feel free to take a peek at them for inspiration! | ||
| 140 | |||
| 141 | |||
| 142 | # Using the Simple DirectMedia Layer with Xcode | ||
| 143 | |||
| 144 | These instructions are for using Apple's Xcode IDE to build SDL applications. | ||
| 145 | |||
| 146 | ## First steps | ||
| 147 | |||
| 148 | The first thing to do is to unpack the Xcode.tar.gz archive in the | ||
| 149 | top level SDL directory (where the Xcode.tar.gz archive resides). | ||
| 150 | Because Stuffit Expander will unpack the archive into a subdirectory, | ||
| 151 | you should unpack the archive manually from the command line: | ||
| 152 | |||
| 153 | ```bash | ||
| 154 | cd [path_to_SDL_source] | ||
| 155 | tar zxf Xcode.tar.gz | ||
| 156 | ``` | ||
| 157 | |||
| 158 | This will create a new folder called Xcode, which you can browse | ||
| 159 | normally from the Finder. | ||
| 160 | |||
| 161 | ## Building the Framework | ||
| 162 | |||
| 163 | The SDL Library is packaged as a framework bundle, an organized | ||
| 164 | relocatable folder hierarchy of executable code, interface headers, | ||
| 165 | and additional resources. For practical purposes, you can think of a | ||
| 166 | framework as a more user and system-friendly shared library, whose library | ||
| 167 | file behaves more or less like a standard UNIX shared library. | ||
| 168 | |||
| 169 | To build the framework, simply open the framework project and build it. | ||
| 170 | By default, the framework bundle "SDL.framework" is installed in | ||
| 171 | /Library/Frameworks. Therefore, the testers and project stationary expect | ||
| 172 | it to be located there. However, it will function the same in any of the | ||
| 173 | following locations: | ||
| 174 | |||
| 175 | * ~/Library/Frameworks | ||
| 176 | * /Local/Library/Frameworks | ||
| 177 | * /System/Library/Frameworks | ||
| 178 | |||
| 179 | ## Build Options | ||
| 180 | |||
| 181 | There 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 | |||
| 187 | Open the SDLTest project and build away! | ||
| 188 | |||
| 189 | ## Using the Project Stationary | ||
| 190 | |||
| 191 | Copy the stationary to the indicated folders to access it from | ||
| 192 | the "New Project" and "Add target" menus. What could be easier? | ||
| 193 | |||
| 194 | ## Setting up a new project by hand | ||
| 195 | |||
| 196 | Some 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 | |||
| 215 | Use `xcode-build` in the same directory as your .pbxproj file | ||
| 216 | |||
| 217 | ## Running your app | ||
| 218 | |||
| 219 | You can send command line args to your app by either invoking it from | ||
| 220 | the command line (in *.app/Contents/MacOS) or by entering them in the | ||
| 221 | Executables" panel of the target settings. | ||
| 222 | |||
| 223 | # Implementation Notes | ||
| 224 | |||
| 225 | Some things that may be of interest about how it all works... | ||
| 226 | |||
| 227 | ## Working directory | ||
| 228 | |||
| 229 | In SDL 1.2, the working directory of your SDL app is by default set to its | ||
| 230 | parent, but this is no longer the case in SDL 2.0 and later. SDL2 does not | ||
| 231 | change the working directory, which means it'll be whatever the command line | ||
| 232 | prompt that launched the program was using, or if launched by double-clicking | ||
| 233 | in the Finder, it will be "/", the _root of the filesystem_. Plan accordingly! | ||
| 234 | You can use SDL_GetBasePath() to find where the program is running from and | ||
| 235 | chdir() there directly. | ||
| 236 | |||
| 237 | |||
| 238 | ## You have a Cocoa App! | ||
| 239 | |||
| 240 | Your SDL app is essentially a Cocoa application. When your app | ||
| 241 | starts up and the libraries finish loading, a Cocoa procedure is called, | ||
| 242 | which sets up the working directory and calls your main() method. | ||
| 243 | You are free to modify your Cocoa app with generally no consequence | ||
| 244 | to SDL. You cannot, however, easily change the SDL window itself. | ||
| 245 | Functionality may be added in the future to help this. | ||
| 246 | |||
| 247 | # Bug reports | ||
| 248 | |||
| 249 | Bugs are tracked at [the GitHub issue tracker](https://github.com/libsdl-org/SDL/issues/). | ||
| 250 | Please feel free to report bugs there! | ||
| 251 | |||
