diff options
Diffstat (limited to 'src/contrib/SDL-3.2.20/docs/INTRO-mingw.md')
-rw-r--r-- | src/contrib/SDL-3.2.20/docs/INTRO-mingw.md | 95 |
1 files changed, 95 insertions, 0 deletions
diff --git a/src/contrib/SDL-3.2.20/docs/INTRO-mingw.md b/src/contrib/SDL-3.2.20/docs/INTRO-mingw.md new file mode 100644 index 0000000..d7c535d --- /dev/null +++ b/src/contrib/SDL-3.2.20/docs/INTRO-mingw.md | |||
@@ -0,0 +1,95 @@ | |||
1 | # Introduction to SDL with MinGW | ||
2 | |||
3 | Without getting deep into the history, MinGW is a long running project that aims to bring gcc to Windows. That said, there's many distributions, versions, and forks floating around. We recommend installing [MSYS2](https://www.msys2.org/), as it's the easiest way to get a modern toolchain with a package manager to help with dependency management. This would allow you to follow the MSYS2 section below. | ||
4 | |||
5 | Otherwise you'll want to follow the "Other Distributions" section below. | ||
6 | |||
7 | We'll start by creating a simple project to build and run [hello.c](hello.c). | ||
8 | |||
9 | # MSYS2 | ||
10 | |||
11 | Open the `MSYS2 UCRT64` prompt and then ensure you've installed the following packages. This will get you working toolchain, CMake, Ninja, and of course SDL3. | ||
12 | |||
13 | ```sh | ||
14 | pacman -S mingw-w64-ucrt-x86_64-gcc mingw-w64-ucrt-x86_64-ninja mingw-w64-ucrt-x86_64-cmake mingw-w64-ucrt-x86_64-sdl3 | ||
15 | ``` | ||
16 | |||
17 | ## Create the file CMakeLists.txt | ||
18 | ```cmake | ||
19 | cmake_minimum_required(VERSION 3.26) | ||
20 | project(hello C CXX) | ||
21 | |||
22 | find_package(SDL3 REQUIRED) | ||
23 | |||
24 | add_executable(hello) | ||
25 | |||
26 | target_sources(hello | ||
27 | PRIVATE | ||
28 | hello.c | ||
29 | ) | ||
30 | |||
31 | target_link_libraries(hello SDL3::SDL3) | ||
32 | ``` | ||
33 | |||
34 | ## Configure and Build: | ||
35 | ```sh | ||
36 | cmake -S . -B build | ||
37 | cmake --build build | ||
38 | ``` | ||
39 | |||
40 | ## Run: | ||
41 | |||
42 | The executable is in the `build` directory: | ||
43 | ```sh | ||
44 | cd build | ||
45 | ./hello | ||
46 | ``` | ||
47 | |||
48 | # Other Distributions | ||
49 | |||
50 | Things can get quite complicated with other distributions of MinGW. If you can't follow [the cmake intro](INTRO-cmake.md), perhaps due to issues getting cmake to understand your toolchain, this section should work. | ||
51 | |||
52 | ## Acquire SDL | ||
53 | |||
54 | Download the `SDL3-devel-<version>-mingw.zip` asset from [the latest release.](https://github.com/libsdl-org/SDL/releases/latest) Then extract it inside your project folder such that the output of `ls SDL3-<version>` looks like `INSTALL.md LICENSE.txt Makefile README.md cmake i686-w64-mingw32 x86_64-w64-mingw32`. | ||
55 | |||
56 | ## Know your Target Architecture | ||
57 | |||
58 | It is not uncommon for folks to not realize their distribution is targeting 32bit Windows despite things like the name of the toolchain, or the fact that they're running on a 64bit system. We'll ensure we know up front what we need: | ||
59 | |||
60 | Create a file named `arch.c` with the following contents: | ||
61 | ```c | ||
62 | #include <stddef.h> | ||
63 | #include <stdio.h> | ||
64 | int main() { | ||
65 | #if defined(__x86_64__) || defined(_M_X64) || defined(i386) || defined(__i386__) || defined(__i386) || defined(_M_IX86) | ||
66 | size_t ptr_size = sizeof(int*); | ||
67 | if (4 == ptr_size) puts("i686-w64-mingw32"); | ||
68 | else if (8 == ptr_size) puts("x86_64-w64-mingw32"); | ||
69 | else puts("Unknown Architecture"); | ||
70 | #else | ||
71 | puts("Unknown Architecture"); | ||
72 | #endif | ||
73 | return 0; | ||
74 | } | ||
75 | ``` | ||
76 | |||
77 | Then run | ||
78 | |||
79 | ```sh | ||
80 | gcc arch.c | ||
81 | ./a.exe | ||
82 | ``` | ||
83 | |||
84 | This should print out which library directory we'll need to use when compiling, keep this value in mind, you'll need to use it when compiling in the next section as `<arch>`. If you get "Unknown Architecture" please [report a bug](https://github.com/libsdl-org/SDL/issues). | ||
85 | |||
86 | |||
87 | ## Build and Run | ||
88 | |||
89 | Now we should have everything needed to compile and run our program. You'll need to ensure to replace `<version>` with the version of the release of SDL3 you downloaded, as well as use the `<arch>` we learned in the previous section. | ||
90 | |||
91 | ```sh | ||
92 | gcc hello.c -o hello.exe -I SDL3-<version>/<arch>/include -L SDL3-<version>/<arch>/lib -lSDL3 -mwindows | ||
93 | cp SDL3-<version>/<arch>/bin/SDL3.dll SDL3.dll | ||
94 | ./hello.exe | ||
95 | ``` | ||