Skip to content

Commit

Permalink
Updated README-cmake.md with build instructions for several platforms
Browse files Browse the repository at this point in the history
  • Loading branch information
slouken committed Jan 14, 2025
1 parent f731741 commit 2c54745
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 19 deletions.
12 changes: 7 additions & 5 deletions docs/INTRO-cmake.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,19 @@ target_link_libraries(hello PRIVATE SDL3::SDL3)

Build:
```sh
cmake .
cmake --build .
cmake -S . -B build
cmake --build build
```

Run:
- On Windows the executable is in the Debug directory:
- On Windows the executable is in the build Debug directory:
```sh
./Debug/hello
cd build/Debug
./hello
```
- On other platforms the executable is in the current directory:
- On other platforms the executable is in the build directory:
```sh
cd build
./hello
```

Expand Down
41 changes: 27 additions & 14 deletions docs/README-cmake.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ The CMake build system is supported on the following platforms:

* FreeBSD
* Linux
* Microsoft Visual C
* Microsoft Visual Studio
* MinGW and Msys
* macOS, iOS, tvOS, and visionOS with support for XCode
* Android
Expand All @@ -20,42 +20,55 @@ The CMake build system is supported on the following platforms:
* QNX 7.x/8.x
* RiscOS

## Building SDL
# Building SDL on Windows

Assuming the source tree of SDL is located at `~/sdl`,
this will configure and build SDL in the `~/build` directory:
Assuming you're in the SDL source directory, building and installing to C:/SDL can be done with:
```sh
cmake -S ~/sdl -B ~/build
cmake --build ~/build
cmake -S . -B build
cmake --build build --config RelWithDebInfo
cmake --install build --config RelWithDebInfo --prefix C:/SDL
```

Installation can be done using:
# Building SDL on UNIX

SDL will build with very few dependencies, but for full functionality you should install the packages detailed in [README-linux.md](README-linux.md).

Assuming you're in the SDL source directory, building and installing to /usr/local can be done with:
```sh
cmake --install ~/build --prefix /usr/local # '--install' requires CMake 3.15, or newer
cmake -S . -B build
cmake --build build
sudo cmake --install build --prefix /usr/local
```

This will install SDL to /usr/local.
# Building SDL on macOS

Assuming you're in the SDL source directory, building and installing to ~/SDL can be done with:
```sh
cmake -S . -B build -DSDL_FRAMEWORK=ON -DCMAKE_OSX_ARCHITECTURES="arm64;x86_64"
cmake --build build
cmake --install build --prefix ~/SDL
```

### Building SDL tests

You can build the SDL test programs by adding `-DSDL_TESTS=ON` to the first cmake command above:
```sh
cmake -S ~/sdl -B ~/build -DSDL_TEST_LIBRARY=ON -DSDL_TESTS=ON
cmake -S . -B build -DSDL_TESTS=ON
```
and then building normally. In this example, the test programs will be built and can be run from `~/build/tests/`.
and then building normally. The test programs will be built and can be run from `test/`.

### Building SDL examples

You can build the SDL example programs by adding `-DSDL_EXAMPLES=ON` to the first cmake command above:
```sh
cmake -S ~/sdl -B ~/build -DSDL_EXAMPLES=ON
cmake -S . -B build -DSDL_EXAMPLES=ON
```
and then building normally. In this example, the example programs will be built and can be run from `~/build/examples/`.
and then building normally. The example programs will be built and can be run from `examples/`.

## Including SDL in your project

SDL can be included in your project in 2 major ways:
- using a system SDL library, provided by your (*nix) distribution or a package manager
- using a system SDL library, provided by your (UNIX) distribution or a package manager
- using a vendored SDL library: this is SDL copied or symlinked in a subfolder.

The following CMake script supports both, depending on the value of `MYGAME_VENDORED`.
Expand Down

0 comments on commit 2c54745

Please sign in to comment.