1
0

README.txt 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330
  1. Author: Ben Henning <b.henning@digipen.edu>
  2. The goal of this project is to provide a lightweight and portable meta-build
  3. system for generating build systems for various platforms and architectures, all
  4. for the SDL2 library and subsequently dependent executables.
  5. Following is a table of contents for the entire README file.
  6. [0] OVERVIEW
  7. [1] GENERATING PROJECTS AND COMMAND-LINE OPTIONS
  8. [2] STRUCTURE
  9. [3] SUPPORT ON WINDOWS AND VISUAL STUDIO
  10. [4] SUPPORT ON MAC OS X AND XCODE
  11. [5] SUPPORT FOR IOS
  12. [6] SUPPORT FOR LINUX
  13. [7] SUPPORT FOR MINGW
  14. [8] SUPPORT FOR CYGWIN
  15. [9] EXTENDING THE SYSTEM TO NEW PROJECTS OR PLATFORMS (code samples)
  16. [0] OVERVIEW
  17. The system is capable of generating projects for many different platforms and
  18. architectures. How to generically generate projects is described in the next
  19. section. Subsequent sections thereafter describe more specific ways to generate
  20. projects and dependencies projects have.
  21. All of the projects inherently have things in common, such as depending on the
  22. same source tree for header and source files. All projects generated will also
  23. have both debug and release configurations available to be built. More
  24. information on how to build either will be provided below.
  25. To view a list of progress on the project, view the changelog.
  26. [1] GENERATING PROJECTS AND COMMAND-LINE OPTIONS
  27. To receive help with various premake actions and command-line options, or to
  28. view the options available for the current premake environment, run the
  29. following command:
  30. ./premake4 --file=./path/to/premake4.lua help
  31. To construct the project files, run this local command from any command line:
  32. .\premake4 --file=.\path\to\premake4.lua --to=.\resultDirectory [opts] [vs2008/vs2010/vs2012]
  33. OR
  34. ./premake4 --file=./path/to/premake4.lua --to=./resultDirectory [opts] [xcode3/xcode4/gmake]
  35. opts may be one of:
  36. --mingw
  37. --cygwin
  38. --ios
  39. opts may also include any of the following:
  40. --alsa : Force the ALSA dependency on for Linux targets.
  41. --dbus : Force the D-Bus dependency on for Linux targets.
  42. --directx : Force the DirectX dependency on for Windows, MinGW, and Cygwin targets.
  43. --dlopen : Force the DLOpen dependency on for Linux targets.
  44. --esd : Force the ESD dependency on for Linux targets.
  45. --nas : Force the NAS dependency on for Linux targets.
  46. --opengl : Force the OpenGL dependency on for any target.
  47. --oss : Force the OSS dependency on for Linux targets.
  48. --pulseaudio : Force the PulseAudio dependency on for Linux targets.
  49. --x11 : Force the X11 dependency on for Linux targets.
  50. All projects have debug and release configurations that may be built. For IDE
  51. projects such as Visual Studio and Xcode, there are configurations in the former
  52. and schemas in the latter to handle this.
  53. For make files, the following command line may be used:
  54. make config=debug
  55. or:
  56. make config=release
  57. The make files also have a level of verbosity that will print all compiler and
  58. linking commands to the command line. This can be enabled with the following
  59. command:
  60. make verbose=1
  61. [2] STRUCTURE
  62. The structure of the meta-build system is split into three parts:
  63. 1. The core system which runs all of the other scripts, generates the premake
  64. Lua file that is used to generate the actual build system, and sets up
  65. premake to generate it. (premake4.lua)
  66. 2. The utility files for performing various convenience operations, ranging
  67. from string operations and a file wrapper to custom project definitions and
  68. complex dependency checking using CMake-esque functions. There is also a
  69. file containing custom dependency functions for checked support.
  70. (everything in the util folder)
  71. 3. The project definition files, which define each and every project related
  72. to SDL2. This includes the SDL2 library itself, along with all of its
  73. current tests and iOS Demos. These files also related to dependency handling
  74. and help build dependency trees for the various projects.
  75. (everything in the projects folder)
  76. The premake4.lua file is lightly documented and commented to explain how it
  77. interfaces with the other utility files and project files. It is not extensively
  78. documented because the actual generation process is not considered to be
  79. pertinent to the overall usage of the meta-build system.
  80. The utility files have thorough documentation, since they are the foundation for
  81. the entire project definition and dependency handling systems.
  82. The project definition files are lightly documented, since they are expected to
  83. be self-explanatory. Look through each and every project definition file
  84. (especially SDL2.lua, testgl2.lua, testshape.lua, testsprite2.lua, and
  85. testnative.lua) to gain experience and familiarity with most of the project
  86. definition system.
  87. The dependency system is very straightforward. As explained in both
  88. sdl_projects.lua and sdl_dependency_checkers.lua, a function for checking the
  89. actual dependency support is registered by its name and then referenced to in
  90. the project definitions (such as for SDL2.lua). These definitions are allowed to
  91. do anything necessary to determine whether the appropriate support exists in the
  92. current build environment or not. The possibilities for checking can be seen
  93. specifically in the function for checking DirectX support and any of the Linux
  94. dependency functions using the sdl_check_compile.lua functions.
  95. As far as building the projects is concerned, the project definitions are
  96. allowed to set configuration key-value pairs which will be translated and placed
  97. inside a generated SDL config header file, similar to the one generated by both
  98. autotools and CMake.
  99. [3] SUPPORT ON WINDOWS AND VISUAL STUDIO
  100. Check the Windows README for more information on SDL2 support on Windows and
  101. Visual Studio. Current support exists for Visual Studio 2008, 2010, and 2012.
  102. [4] SUPPORT ON MAC OS X AND XCODE
  103. Check the Mac OS X README for more information on SDL2 support on Mac OS X using
  104. Xcode. Current support should exist for Mac OS X 10.6, 10.7, and 10.8 (as
  105. tested, but more may be supported). Supported Xcode versions are 3 and 4. It
  106. supports building for both i686 and x86_64 architectures, as well as support for
  107. universal 32-bit binaries, universal 64-bit binaries, and universal combined
  108. binaries.
  109. [5] SUPPORT FOR IOS
  110. EXPERIMENTAL SUPPORT
  111. Check the iOS README for more information on SDL2 support on iOS using Xcode.
  112. Current support has been tested on the iOS 6 emulators for iPhone and iPad,
  113. using both Xcode 3 and Xcode 4. The iOS project will reference all the Demos
  114. the manual project does.
  115. [6] SUPPORT FOR LINUX
  116. EXPERIMENTAL SUPPORT
  117. Check the Linux README for more information on SDL2 support on Linux. Currently,
  118. only a subset of the Linux dependencies are supported, and they are supported
  119. partially. Linux also builds to a static library instead of a shared library.
  120. The tests run well and as expected.
  121. [7] SUPPORT FOR MINGW
  122. Check the MinGW README for more information on SDL2 support on MinGW. Currently,
  123. all of the tests that work using the Visual Studio projects also seem to work
  124. with MinGW, minus DirectX support. DirectX is not inherently supported, but can
  125. be forcibly turned on if the user knows what they are doing.
  126. [8] SUPPORT FOR CYGWIN
  127. BROKEN SUPPORT
  128. Check the Cygwin README for more information on the progress of supporting SDL2
  129. on Cygwin.
  130. [9] EXTENDING THE SYSTEM TO NEW PROJECTS OR PLATFORMS
  131. In order to create a new project, simply create a Lua file and place it within
  132. the projects directory. The meta-build system will automatically include it.
  133. It must contain a SDL_project definition. Projects *must* have source files as
  134. well, otherwise they will be ignored by the meta-build system. There are a
  135. plethora of examples demonstrating how to defined projects, link them to various
  136. dependencies, and to create dependencies.
  137. Here is an example that creates a new project named foo, it's a ConsoleApp
  138. (which is the default for SDL projects, look at http://industriousone.com/kind
  139. for more information). Its language is C and its source directory is "../test"
  140. (this path is relative to the location of premake4.lua). It's project location
  141. is "tests", which means it will be placed in the ./tests/ folder of whichever
  142. destination directory is set while generating the project (for example,
  143. ./VisualC/tests). It is including all the files starting with "foo." from the
  144. "../test" folder.
  145. SDL_project "foo"
  146. SDL_kind "ConsoleApp"
  147. SDL_language "C"
  148. SDL_sourcedir "../test"
  149. SDL_projectLocation "tests"
  150. SDL_files { "/testrendercopyex.*" }
  151. Now, we can extend this project slightly:
  152. SDL_project "foo"
  153. SDL_kind "ConsoleApp"
  154. SDL_notos "ios|cygwin"
  155. SDL_language "C"
  156. SDL_sourcedir "../test"
  157. SDL_projectLocation "tests"
  158. SDL_projectDependencies { "SDL2main", "SDL2test", "SDL2" }
  159. SDL_files { "/foo.*" }
  160. SDL_copy { "icon.bmp", "sample.bmp" }
  161. We now specified that this application will not work on iOS or Cygwin targets,
  162. so it will be discluded when generating projects for those platforms. We have
  163. also specified that this project depends on 'SDL2main', 'SDL2test', and 'SDL2',
  164. which are other projects that are already defined. We can set the dependency
  165. to any projects the SDL2 meta-build system is aware of. We also have an
  166. interesting SDL_copy directive, which will automatically copy the files
  167. "icon.bmp" and "sample.bmp" from "<sdl_root>/test" to the directory of foo's
  168. executable when it's built.
  169. Let's take a look at another example:
  170. SDL_project "testgl2"
  171. SDL_kind "ConsoleApp"
  172. SDL_notos "ios|cygwin"
  173. SDL_language "C"
  174. SDL_sourcedir "../test"
  175. SDL_projectLocation "tests"
  176. SDL_projectDependencies { "SDL2main", "SDL2test", "SDL2" }
  177. SDL_defines { "HAVE_OPENGL" }
  178. SDL_dependency "OpenGL"
  179. -- opengl is platform independent
  180. SDL_depfunc "OpenGL"
  181. SDL_files { "/testgl2.*" }
  182. This is a copy of the testgl2.lua file. Most of this is already familiar, but
  183. there are a few new things to point out. We can set preprocessor definitions by
  184. using the 'SDL_defines' directive. We can also create a dependency for the
  185. project on some varied criteria. For example, testgl2 is obviously dependent on
  186. the presence of the OpenGL library. So, the only way it will include the
  187. "testgl2.*" (testgl2.c/testgl2.h) files is if the dependency function "OpenGL"
  188. returns information regarding the whereabouts of the OpenGL library on the
  189. current system. This function is registered in sdl_dependency_checkers.lua:
  190. function openGLDep()
  191. print("Checking OpenGL dependencies...")
  192. ...
  193. return { found = foundLib, libDirs = { }, libs = { libname } }
  194. end
  195. ...
  196. SDL_registerDependencyChecker("OpenGL", openGLDep)
  197. This function is called when it's time to decide whether testgl2 should be
  198. generated or not. openGLDep can use any and all functions to decide whether
  199. OpenGL is supported.
  200. Dependencies and projects can become much more sophisticate, if necessary. Take
  201. the following example from the SDL2.lua project definition:
  202. -- DirectX dependency
  203. SDL_dependency "directx"
  204. SDL_os "windows|mingw"
  205. SDL_depfunc "DirectX"
  206. SDL_config
  207. {
  208. ["SDL_AUDIO_DRIVER_DSOUND"] = 1,
  209. ["SDL_AUDIO_DRIVER_XAUDIO2"] = 1,
  210. ["SDL_JOYSTICK_DINPUT"] = 1,
  211. ["SDL_HAPTIC_DINPUT"] = 1,
  212. ["SDL_VIDEO_RENDER_D3D"] = 1
  213. }
  214. SDL_paths
  215. {
  216. "/audio/directsound/",
  217. "/audio/xaudio2/",
  218. "/render/direct3d/",
  219. -- these two depend on Xinput
  220. "/haptic/windows/",
  221. "/joystick/windows/",
  222. }
  223. This dependency is, as expected, for DirectX. One thing to note here is even
  224. dependencies can be dependent on an operating system. This dependency will not
  225. even be resolved if SDL2 is being generated on, say, Linux or Mac OS X. Two new
  226. things shown here are 'SDL_config' and 'SDL_paths' directives. SDL_config allows
  227. you to set preprocessor definitions that will be pasted into
  228. SDL_config_premake.h (which acts as a replacement to SDL_config.h when building
  229. the project). This allows for significant flexibility (look around SDL2.lua's
  230. dependencies, especially for Linux). SDL_paths works like SDL_files, except it
  231. includes all .c, .h, and .m files within that directory. The directory is still
  232. relative to the source directory of the project (in this case, <sdl_root>/src).
  233. Finally, dependency checking can be done in a huge variety of ways, ranging
  234. from simply checking for an environmental variable to scanning directories on
  235. Windows. Even more flexibly, the build environment itself can be checked using
  236. functions similar to those provided in CMake to check if a function compiles,
  237. library exists, etc. The following example comes from
  238. sdl_dependency_checkers.lua and is used by the Linux dependency in the SDL2
  239. project to determine whether the OSS sound system is supported:
  240. function ossDep()
  241. print("Checking for OSS support...")
  242. if not check_cxx_source_compiles([[
  243. #include <sys/soundcard.h>
  244. int main() { int arg = SNDCTL_DSP_SETFRAGMENT; return 0; }]])
  245. and not check_cxx_source_compiles([[
  246. #include <soundcard.h>
  247. int main() { int arg = SNDCTL_DSP_SETFRAGMENT; return 0; }]]) then
  248. print("Warning: OSS unsupported!")
  249. return { found = false }
  250. end
  251. return { found = true }
  252. end
  253. Notice how it uses 'check_cxx_source_compiles'. There are even more functions
  254. than this to check and, rather than going in detail with them here, I encourage
  255. you to look at the documented functions within ./util/sdl_check_compile.lua.
  256. In order to support new platforms, start with the minimal configuration template
  257. provided and work off of the initial SDL2 project. You may add additional
  258. dependencies to define other source files specific to that platform (see how
  259. it's done with Windows and Mac OS X), or you can add special dependencies that
  260. rely on dependency functions you may implement yourself (see DirectX and
  261. OpenGL). Dependencies can use the 'SDL_config' directive to specify special
  262. values that can be pasted into the resulting configuration header file upon
  263. generation.
  264. For more detailed information about the functions supported and how they work,
  265. look at all of the Lua files in the util directory, as well as any of the
  266. example projects in the projects directory to demonstrate how many of these
  267. functions are used. The information above is only a quick subset of the
  268. capabilities of the meta-build system.