2 ==============================================================================
4 These instructions are for people using Apple's Mac OS X (pronounced
7 From the developer's point of view, OS X is a sort of hybrid Mac and
8 Unix system, and you have the option of using either traditional
9 command line tools or Apple's IDE Xcode.
11 To build SDL using the command line, use the standard configure and make
18 You can also build SDL as a Universal library (a single binary for both
19 32-bit and 64-bit Intel architectures), on Mac OS X 10.7 and newer, by using
20 the gcc-fat.sh script in build-scripts:
24 CC=$PWD/../build-scripts/gcc-fat.sh CXX=$PWD/../build-scripts/g++-fat.sh ../configure
28 This script builds SDL with 10.5 ABI compatibility on i386 and 10.6
29 ABI compatibility on x86_64 architectures. For best compatibility you
30 should compile your application the same way.
32 Please note that building SDL requires at least Xcode 4.6 and the 10.7 SDK
33 (even if you target back to 10.5 systems). PowerPC support for Mac OS X has
34 been officially dropped as of SDL 2.0.2.
36 To use the library once it's built, you essential have two possibilities:
37 use the traditional autoconf/automake/make method, or use Xcode.
39 ==============================================================================
40 Caveats for using SDL with Mac OS X
41 ==============================================================================
43 Some things you have to be aware of when using SDL on Mac OS X:
45 - If you register your own NSApplicationDelegate (using [NSApp setDelegate:]),
46 SDL will not register its own. This means that SDL will not terminate using
47 SDL_Quit if it receives a termination request, it will terminate like a
48 normal app, and it will not send a SDL_DROPFILE when you request to open a
49 file with the app. To solve these issues, put the following code in your
50 NSApplicationDelegate implementation:
53 - (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication *)sender
55 if (SDL_GetEventState(SDL_QUIT) == SDL_ENABLE) {
57 event.type = SDL_QUIT;
58 SDL_PushEvent(&event);
61 return NSTerminateCancel;
64 - (BOOL)application:(NSApplication *)theApplication openFile:(NSString *)filename
66 if (SDL_GetEventState(SDL_DROPFILE) == SDL_ENABLE) {
68 event.type = SDL_DROPFILE;
69 event.drop.file = SDL_strdup([filename UTF8String]);
70 return (SDL_PushEvent(&event) > 0);
76 ==============================================================================
77 Using the Simple DirectMedia Layer with a traditional Makefile
78 ==============================================================================
80 An existing autoconf/automake build system for your SDL app has good chances
81 to work almost unchanged on OS X. However, to produce a "real" Mac OS X binary
82 that you can distribute to users, you need to put the generated binary into a
83 so called "bundle", which basically is a fancy folder with a name like
86 To get this build automatically, add something like the following rule to
89 bundle_contents = APP_NAME.app/Contents
90 APP_NAME_bundle: EXE_NAME
91 mkdir -p $(bundle_contents)/MacOS
92 mkdir -p $(bundle_contents)/Resources
93 echo "APPL????" > $(bundle_contents)/PkgInfo
94 $(INSTALL_PROGRAM) $< $(bundle_contents)/MacOS/
96 You should replace EXE_NAME with the name of the executable. APP_NAME is what
97 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 package
100 name as specified in your configure.in file.
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.
105 If you want the created bundles to be installed, you may want to add this
106 rule to your Makefile.am:
108 install-exec-hook: APP_NAME_bundle
109 rm -rf $(DESTDIR)$(prefix)/Applications/APP_NAME.app
110 mkdir -p $(DESTDIR)$(prefix)/Applications/
111 cp -r $< /$(DESTDIR)$(prefix)Applications/
113 This rule takes the Bundle created by the rule from step 3 and installs them
114 into "$(DESTDIR)$(prefix)/Applications/".
116 Again, if you want to install multiple applications, you will have to augment
117 the make rule accordingly.
120 But beware! That is only part of the story! With the above, you end up with
121 a bare bone .app bundle, which is double clickable from the Finder. But
122 there are some more things you should do before shipping your product...
124 1) The bundle right now probably is dynamically linked against SDL. That
125 means that when you copy it to another computer, *it will not run*,
126 unless you also install SDL on that other computer. A good solution
127 for this dilemma is to static link against SDL. On OS X, you can
128 achieve that by linking against the libraries listed by
130 sdl-config --static-libs
132 instead of those listed by
136 Depending on how exactly SDL is integrated into your build systems, the
137 way to achieve that varies, so I won't describe it here in detail
139 2) Add an 'Info.plist' to your application. That is a special XML file which
140 contains some meta-information about your application (like some copyright
141 information, the version of your app, the name of an optional icon file,
142 and other things). Part of that information is displayed by the Finder
143 when you click on the .app, or if you look at the "Get Info" window.
144 More information about Info.plist files can be found on Apple's homepage.
147 As a final remark, let me add that I use some of the techniques (and some
148 variations of them) in Exult and ScummVM; both are available in source on
149 the net, so feel free to take a peek at them for inspiration!
152 ==============================================================================
153 Using the Simple DirectMedia Layer with Xcode
154 ==============================================================================
156 These instructions are for using Apple's Xcode IDE to build SDL applications.
160 The first thing to do is to unpack the Xcode.tar.gz archive in the
161 top level SDL directory (where the Xcode.tar.gz archive resides).
162 Because Stuffit Expander will unpack the archive into a subdirectory,
163 you should unpack the archive manually from the command line:
165 cd [path_to_SDL_source]
168 This will create a new folder called Xcode, which you can browse
169 normally from the Finder.
171 - Building the Framework
173 The SDL Library is packaged as a framework bundle, an organized
174 relocatable folder hierarchy of executable code, interface headers,
175 and additional resources. For practical purposes, you can think of a
176 framework as a more user and system-friendly shared library, whose library
177 file behaves more or less like a standard UNIX shared library.
179 To build the framework, simply open the framework project and build it.
180 By default, the framework bundle "SDL.framework" is installed in
181 /Library/Frameworks. Therefore, the testers and project stationary expect
182 it to be located there. However, it will function the same in any of the
186 /Local/Library/Frameworks
187 /System/Library/Frameworks
190 There are two "Build Styles" (See the "Targets" tab) for SDL.
191 "Deployment" should be used if you aren't tweaking the SDL library.
192 "Development" should be used to debug SDL apps or the library itself.
194 - Building the Testers
195 Open the SDLTest project and build away!
197 - Using the Project Stationary
198 Copy the stationary to the indicated folders to access it from
199 the "New Project" and "Add target" menus. What could be easier?
201 - Setting up a new project by hand
202 Some of you won't want to use the Stationary so I'll give some tips:
203 * Create a new "Cocoa Application"
204 * Add src/main/macosx/SDLMain.m , .h and .nib to your project
205 * Remove "main.c" from your project
206 * Remove "MainMenu.nib" 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 * Set the "Main Nib File" under "Application Settings" to "SDLMain.nib"
214 - Building from command line
215 Use pbxbuild in the same directory as your .pbproj file
218 You can send command line args to your app by either invoking it from
219 the command line (in *.app/Contents/MacOS) or by entering them in the
220 "Executables" panel of the target settings.
222 - Implementation Notes
223 Some things that may be of interest about how it all works...
225 As defined in the SDL_main.m file, the working directory of your SDL app
226 is by default set to its parent. You may wish to change this to better
228 * You have a Cocoa App!
229 Your SDL app is essentially a Cocoa application. When your app
230 starts up and the libraries finish loading, a Cocoa procedure is called,
231 which sets up the working directory and calls your main() method.
232 You are free to modify your Cocoa app with generally no consequence
233 to SDL. You cannot, however, easily change the SDL window itself.
234 Functionality may be added in the future to help this.
237 Known bugs are listed in the file "BUGS.txt".