diff options
Diffstat (limited to 'src/contrib/SDL-2.30.2/docs/README-cmake.md')
-rw-r--r-- | src/contrib/SDL-2.30.2/docs/README-cmake.md | 163 |
1 files changed, 163 insertions, 0 deletions
diff --git a/src/contrib/SDL-2.30.2/docs/README-cmake.md b/src/contrib/SDL-2.30.2/docs/README-cmake.md new file mode 100644 index 0000000..cfd4066 --- /dev/null +++ b/src/contrib/SDL-2.30.2/docs/README-cmake.md | |||
@@ -0,0 +1,163 @@ | |||
1 | # CMake | ||
2 | |||
3 | (www.cmake.org) | ||
4 | |||
5 | SDL's build system was traditionally based on autotools. Over time, this | ||
6 | approach has suffered from several issues across the different supported | ||
7 | platforms. | ||
8 | To solve these problems, a new build system based on CMake was introduced. | ||
9 | It is developed in parallel to the legacy autotools build system, so users | ||
10 | can experiment with it without complication. | ||
11 | |||
12 | The CMake build system is supported on the following platforms: | ||
13 | |||
14 | * FreeBSD | ||
15 | * Linux | ||
16 | * Microsoft Visual C | ||
17 | * MinGW and Msys | ||
18 | * macOS, iOS, and tvOS, with support for XCode | ||
19 | * Android | ||
20 | * Emscripten | ||
21 | * RiscOS | ||
22 | * Playstation Vita | ||
23 | |||
24 | ## Building SDL | ||
25 | |||
26 | Assuming the source for SDL is located at `~/sdl` | ||
27 | ```sh | ||
28 | cd ~ | ||
29 | mkdir build | ||
30 | cd build | ||
31 | cmake ~/sdl | ||
32 | cmake --build . | ||
33 | ``` | ||
34 | |||
35 | This will build the static and dynamic versions of SDL in the `~/build` directory. | ||
36 | Installation can be done using: | ||
37 | |||
38 | ```sh | ||
39 | cmake --install . # '--install' requires CMake 3.15, or newer | ||
40 | ``` | ||
41 | |||
42 | ## Including SDL in your project | ||
43 | |||
44 | SDL can be included in your project in 2 major ways: | ||
45 | - using a system SDL library, provided by your (*nix) distribution or a package manager | ||
46 | - using a vendored SDL library: this is SDL copied or symlinked in a subfolder. | ||
47 | |||
48 | The following CMake script supports both, depending on the value of `MYGAME_VENDORED`. | ||
49 | |||
50 | ```cmake | ||
51 | cmake_minimum_required(VERSION 3.5) | ||
52 | project(mygame) | ||
53 | |||
54 | # Create an option to switch between a system sdl library and a vendored sdl library | ||
55 | option(MYGAME_VENDORED "Use vendored libraries" OFF) | ||
56 | |||
57 | if(MYGAME_VENDORED) | ||
58 | add_subdirectory(vendored/sdl EXCLUDE_FROM_ALL) | ||
59 | else() | ||
60 | # 1. Look for a SDL2 package, 2. look for the SDL2 component and 3. fail if none can be found | ||
61 | find_package(SDL2 REQUIRED CONFIG REQUIRED COMPONENTS SDL2) | ||
62 | |||
63 | # 1. Look for a SDL2 package, 2. Look for the SDL2maincomponent and 3. DO NOT fail when SDL2main is not available | ||
64 | find_package(SDL2 REQUIRED CONFIG COMPONENTS SDL2main) | ||
65 | endif() | ||
66 | |||
67 | # Create your game executable target as usual | ||
68 | add_executable(mygame WIN32 mygame.c) | ||
69 | |||
70 | # SDL2::SDL2main may or may not be available. It is e.g. required by Windows GUI applications | ||
71 | if(TARGET SDL2::SDL2main) | ||
72 | # It has an implicit dependency on SDL2 functions, so it MUST be added before SDL2::SDL2 (or SDL2::SDL2-static) | ||
73 | target_link_libraries(mygame PRIVATE SDL2::SDL2main) | ||
74 | endif() | ||
75 | |||
76 | # Link to the actual SDL2 library. SDL2::SDL2 is the shared SDL library, SDL2::SDL2-static is the static SDL libarary. | ||
77 | target_link_libraries(mygame PRIVATE SDL2::SDL2) | ||
78 | ``` | ||
79 | |||
80 | ### A system SDL library | ||
81 | |||
82 | For CMake to find SDL, it must be installed in [a default location CMake is looking for](https://cmake.org/cmake/help/latest/command/find_package.html#config-mode-search-procedure). | ||
83 | |||
84 | The following components are available, to be used as an argument of `find_package`. | ||
85 | |||
86 | | Component name | Description | | ||
87 | |----------------|--------------------------------------------------------------------------------------------| | ||
88 | | SDL2 | The SDL2 shared library, available through the `SDL2::SDL2` target [^SDL_TARGET_EXCEPTION] | | ||
89 | | SDL2-static | The SDL2 static library, available through the `SDL2::SDL2-static` target | | ||
90 | | SDL2main | The SDL2main static library, available through the `SDL2::SDL2main` target | | ||
91 | | SDL2test | The SDL2test static library, available through the `SDL2::SDL2test` target | | ||
92 | |||
93 | ### Using a vendored SDL | ||
94 | |||
95 | This only requires a copy of SDL in a subdirectory. | ||
96 | |||
97 | ## CMake configuration options for platforms | ||
98 | |||
99 | ### iOS/tvOS | ||
100 | |||
101 | CMake 3.14+ natively includes support for iOS and tvOS. SDL binaries may be built | ||
102 | using Xcode or Make, possibly among other build-systems. | ||
103 | |||
104 | When using a recent version of CMake (3.14+), it should be possible to: | ||
105 | |||
106 | - build SDL for iOS, both static and dynamic | ||
107 | - build SDL test apps (as iOS/tvOS .app bundles) | ||
108 | - generate a working SDL_config.h for iOS (using SDL_config.h.cmake as a basis) | ||
109 | |||
110 | To use, set the following CMake variables when running CMake's configuration stage: | ||
111 | |||
112 | - `CMAKE_SYSTEM_NAME=<OS>` (either `iOS` or `tvOS`) | ||
113 | - `CMAKE_OSX_SYSROOT=<SDK>` (examples: `iphoneos`, `iphonesimulator`, `iphoneos12.4`, `/full/path/to/iPhoneOS.sdk`, | ||
114 | `appletvos`, `appletvsimulator`, `appletvos12.4`, `/full/path/to/AppleTVOS.sdk`, etc.) | ||
115 | - `CMAKE_OSX_ARCHITECTURES=<semicolon-separated list of CPU architectures>` (example: "arm64;armv7s;x86_64") | ||
116 | |||
117 | |||
118 | #### Examples | ||
119 | |||
120 | - for iOS-Simulator, using the latest, installed SDK: | ||
121 | |||
122 | ```bash | ||
123 | cmake ~/sdl -DCMAKE_SYSTEM_NAME=iOS -DCMAKE_OSX_SYSROOT=iphonesimulator -DCMAKE_OSX_ARCHITECTURES=x86_64 | ||
124 | ``` | ||
125 | |||
126 | - for iOS-Device, using the latest, installed SDK, 64-bit only | ||
127 | |||
128 | ```bash | ||
129 | cmake ~/sdl -DCMAKE_SYSTEM_NAME=iOS -DCMAKE_OSX_SYSROOT=iphoneos -DCMAKE_OSX_ARCHITECTURES=arm64 | ||
130 | ``` | ||
131 | |||
132 | - for iOS-Device, using the latest, installed SDK, mixed 32/64 bit | ||
133 | |||
134 | ```cmake | ||
135 | cmake ~/sdl -DCMAKE_SYSTEM_NAME=iOS -DCMAKE_OSX_SYSROOT=iphoneos -DCMAKE_OSX_ARCHITECTURES="arm64;armv7s" | ||
136 | ``` | ||
137 | |||
138 | - for iOS-Device, using a specific SDK revision (iOS 12.4, in this example): | ||
139 | |||
140 | ```cmake | ||
141 | cmake ~/sdl -DCMAKE_SYSTEM_NAME=iOS -DCMAKE_OSX_SYSROOT=iphoneos12.4 -DCMAKE_OSX_ARCHITECTURES=arm64 | ||
142 | ``` | ||
143 | |||
144 | - for iOS-Simulator, using the latest, installed SDK, and building SDL test apps (as .app bundles): | ||
145 | |||
146 | ```cmake | ||
147 | cmake ~/sdl -DSDL_TESTS=1 -DCMAKE_SYSTEM_NAME=iOS -DCMAKE_OSX_SYSROOT=iphonesimulator -DCMAKE_OSX_ARCHITECTURES=x86_64 | ||
148 | ``` | ||
149 | |||
150 | - for tvOS-Simulator, using the latest, installed SDK: | ||
151 | |||
152 | ```cmake | ||
153 | cmake ~/sdl -DCMAKE_SYSTEM_NAME=tvOS -DCMAKE_OSX_SYSROOT=appletvsimulator -DCMAKE_OSX_ARCHITECTURES=x86_64 | ||
154 | ``` | ||
155 | |||
156 | - for tvOS-Device, using the latest, installed SDK: | ||
157 | |||
158 | ```cmake | ||
159 | cmake ~/sdl -DCMAKE_SYSTEM_NAME=tvOS -DCMAKE_OSX_SYSROOT=appletvos -DCMAKE_OSX_ARCHITECTURES=arm64` | ||
160 | ``` | ||
161 | |||
162 | |||
163 | [^SDL_TARGET_EXCEPTION]: `SDL2::SDL2` can be an ALIAS to a static `SDL2::SDL2-static` target for multiple reasons. | ||