🛠️🐜 Antkeeper superbuild with dependencies included https://antkeeper.com
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

285 lines
9.6 KiB

  1. # Mac OS X (aka macOS).
  2. These instructions are for people using Apple's Mac OS X (pronounced
  3. "ten"), which in newer versions is just referred to as "macOS".
  4. From the developer's point of view, macOS is a sort of hybrid Mac and
  5. Unix system, and you have the option of using either traditional
  6. command line tools or Apple's IDE Xcode.
  7. # Command Line Build
  8. To build SDL using the command line, use the standard configure and make
  9. process:
  10. ```bash
  11. mkdir build
  12. cd build
  13. ../configure
  14. make
  15. sudo make install
  16. ```
  17. CMake is also known to work, although it continues to be a work in progress:
  18. ```bash
  19. mkdir build
  20. cd build
  21. cmake -DCMAKE_BUILD_TYPE=Release ..
  22. make
  23. sudo make install
  24. ```
  25. You can also build SDL as a Universal library (a single binary for both
  26. 64-bit Intel and ARM architectures), by using the build-scripts/clang-fat.sh
  27. script.
  28. ```bash
  29. mkdir build
  30. cd build
  31. CC=$PWD/../build-scripts/clang-fat.sh ../configure
  32. make
  33. sudo make install
  34. ```
  35. This script builds SDL with 10.9 ABI compatibility on 64-bit Intel and 11.0
  36. ABI compatibility on ARM64 architectures. For best compatibility you
  37. should compile your application the same way.
  38. Please note that building SDL requires at least Xcode 6 and the 10.9 SDK.
  39. PowerPC support for macOS has been officially dropped as of SDL 2.0.2.
  40. 32-bit Intel and macOS 10.8 runtime support has been officially dropped as
  41. of SDL 2.24.0.
  42. To use the library once it's built, you essential have two possibilities:
  43. use the traditional autoconf/automake/make method, or use Xcode.
  44. # Caveats for using SDL with 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:
  51. ```objc
  52. - (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication *)sender
  53. {
  54. if (SDL_GetEventState(SDL_QUIT) == SDL_ENABLE) {
  55. SDL_Event event;
  56. event.type = SDL_QUIT;
  57. SDL_PushEvent(&event);
  58. }
  59. return NSTerminateCancel;
  60. }
  61. - (BOOL)application:(NSApplication *)theApplication openFile:(NSString *)filename
  62. {
  63. if (SDL_GetEventState(SDL_DROPFILE) == SDL_ENABLE) {
  64. SDL_Event event;
  65. event.type = SDL_DROPFILE;
  66. event.drop.file = SDL_strdup([filename UTF8String]);
  67. return (SDL_PushEvent(&event) > 0);
  68. }
  69. return NO;
  70. }
  71. ```
  72. # Using the Simple DirectMedia Layer with a traditional Makefile
  73. An existing autoconf/automake build system for your SDL app has good chances
  74. to work almost unchanged on macOS. However, to produce a "real" Mac binary
  75. that you can distribute to users, you need to put the generated binary into a
  76. so called "bundle", which is basically a fancy folder with a name like
  77. "MyCoolGame.app".
  78. To get this build automatically, add something like the following rule to
  79. your Makefile.am:
  80. ```make
  81. bundle_contents = APP_NAME.app/Contents
  82. APP_NAME_bundle: EXE_NAME
  83. mkdir -p $(bundle_contents)/MacOS
  84. mkdir -p $(bundle_contents)/Resources
  85. echo "APPL????" > $(bundle_contents)/PkgInfo
  86. $(INSTALL_PROGRAM) $< $(bundle_contents)/MacOS/
  87. ```
  88. You should replace `EXE_NAME` with the name of the executable. `APP_NAME` is
  89. what will be visible to the user in the Finder. Usually it will be the same
  90. as `EXE_NAME` but capitalized. E.g. if `EXE_NAME` is "testgame" then `APP_NAME`
  91. usually is "TestGame". You might also want to use `@PACKAGE@` to use the
  92. package name as specified in your configure.ac file.
  93. If your project builds more than one application, you will have to do a bit
  94. more. For each of your target applications, you need a separate rule.
  95. If you want the created bundles to be installed, you may want to add this
  96. rule to your Makefile.am:
  97. ```make
  98. install-exec-hook: APP_NAME_bundle
  99. rm -rf $(DESTDIR)$(prefix)/Applications/APP_NAME.app
  100. mkdir -p $(DESTDIR)$(prefix)/Applications/
  101. cp -r $< /$(DESTDIR)$(prefix)Applications/
  102. ```
  103. This rule takes the Bundle created by the rule from step 3 and installs them
  104. into "$(DESTDIR)$(prefix)/Applications/".
  105. Again, if you want to install multiple applications, you will have to augment
  106. the make rule accordingly.
  107. But beware! That is only part of the story! With the above, you end up with
  108. a barebones .app bundle, which is double-clickable from the Finder. But
  109. there are some more things you should do before shipping your product...
  110. 1. The bundle right now probably is dynamically linked against SDL. That
  111. means that when you copy it to another computer, *it will not run*,
  112. unless you also install SDL on that other computer. A good solution
  113. for this dilemma is to static link against SDL. On OS X, you can
  114. achieve that by linking against the libraries listed by
  115. ```bash
  116. sdl-config --static-libs
  117. ```
  118. instead of those listed by
  119. ```bash
  120. sdl-config --libs
  121. ```
  122. Depending on how exactly SDL is integrated into your build systems, the
  123. way to achieve that varies, so I won't describe it here in detail
  124. 2. Add an 'Info.plist' to your application. That is a special XML file which
  125. contains some meta-information about your application (like some copyright
  126. information, the version of your app, the name of an optional icon file,
  127. and other things). Part of that information is displayed by the Finder
  128. when you click on the .app, or if you look at the "Get Info" window.
  129. More information about Info.plist files can be found on Apple's homepage.
  130. As a final remark, let me add that I use some of the techniques (and some
  131. variations of them) in [Exult](https://github.com/exult/exult) and
  132. [ScummVM](https://github.com/scummvm/scummvm); both are available in source on
  133. the net, so feel free to take a peek at them for inspiration!
  134. # Using the Simple DirectMedia Layer with Xcode
  135. These instructions are for using Apple's Xcode IDE to build SDL applications.
  136. ## First steps
  137. The first thing to do is to unpack the Xcode.tar.gz archive in the
  138. top level SDL directory (where the Xcode.tar.gz archive resides).
  139. Because Stuffit Expander will unpack the archive into a subdirectory,
  140. you should unpack the archive manually from the command line:
  141. ```bash
  142. cd [path_to_SDL_source]
  143. tar zxf Xcode.tar.gz
  144. ```
  145. This will create a new folder called Xcode, which you can browse
  146. normally from the Finder.
  147. ## Building the Framework
  148. The SDL Library is packaged as a framework bundle, an organized
  149. relocatable folder hierarchy of executable code, interface headers,
  150. and additional resources. For practical purposes, you can think of a
  151. framework as a more user and system-friendly shared library, whose library
  152. file behaves more or less like a standard UNIX shared library.
  153. To build the framework, simply open the framework project and build it.
  154. By default, the framework bundle "SDL.framework" is installed in
  155. /Library/Frameworks. Therefore, the testers and project stationary expect
  156. it to be located there. However, it will function the same in any of the
  157. following locations:
  158. * ~/Library/Frameworks
  159. * /Local/Library/Frameworks
  160. * /System/Library/Frameworks
  161. ## Build Options
  162. There are two "Build Styles" (See the "Targets" tab) for SDL.
  163. "Deployment" should be used if you aren't tweaking the SDL library.
  164. "Development" should be used to debug SDL apps or the library itself.
  165. ## Building the Testers
  166. Open the SDLTest project and build away!
  167. ## Using the Project Stationary
  168. Copy the stationary to the indicated folders to access it from
  169. the "New Project" and "Add target" menus. What could be easier?
  170. ## Setting up a new project by hand
  171. Some of you won't want to use the Stationary so I'll give some tips:
  172. (this is accurate as of Xcode 12.5.)
  173. * Click "File" -> "New" -> "Project...
  174. * Choose "macOS" and then "App" from the "Application" section.
  175. * Fill out the options in the next window. User interface is "XIB" and
  176. Language is "Objective-C".
  177. * Remove "main.m" from your project
  178. * Remove "MainMenu.xib" from your project
  179. * Remove "AppDelegates.*" from your project
  180. * Add "\$(HOME)/Library/Frameworks/SDL.framework/Headers" to include path
  181. * Add "\$(HOME)/Library/Frameworks" to the frameworks search path
  182. * Add "-framework SDL -framework Foundation -framework AppKit" to "OTHER_LDFLAGS"
  183. * Add your files
  184. * Clean and build
  185. ## Building from command line
  186. Use `xcode-build` in the same directory as your .pbxproj file
  187. ## Running your app
  188. You can send command line args to your app by either invoking it from
  189. the command line (in *.app/Contents/MacOS) or by entering them in the
  190. Executables" panel of the target settings.
  191. # Implementation Notes
  192. Some things that may be of interest about how it all works...
  193. ## Working directory
  194. In SDL 1.2, the working directory of your SDL app is by default set to its
  195. parent, but this is no longer the case in SDL 2.0. SDL2 does change the
  196. working directory, which means it'll be whatever the command line prompt
  197. that launched the program was using, or if launched by double-clicking in
  198. the finger, it will be "/", the _root of the filesystem_. Plan accordingly!
  199. You can use SDL_GetBasePath() to find where the program is running from and
  200. chdir() there directly.
  201. ## You have a Cocoa App!
  202. Your SDL app is essentially a Cocoa application. When your app
  203. starts up and the libraries finish loading, a Cocoa procedure is called,
  204. which sets up the working directory and calls your main() method.
  205. You are free to modify your Cocoa app with generally no consequence
  206. to SDL. You cannot, however, easily change the SDL window itself.
  207. Functionality may be added in the future to help this.
  208. # Bug reports
  209. Bugs are tracked at [the GitHub issue tracker](https://github.com/libsdl-org/SDL/issues/).
  210. Please feel free to report bugs there!