Add CMake build and cross-platform cleanup

This commit is contained in:
Bram Verhulst
2026-04-12 23:15:20 +02:00
parent 81746db9ae
commit 1ba1c1f2cc
25 changed files with 350 additions and 56 deletions

83
BUILDING.md Normal file
View File

@@ -0,0 +1,83 @@
# Building Motherload
This repository now supports both the original Visual Studio solution files and a CMake-based build.
## Supported build paths
### 1. CMake on Windows
Recommended if you want a modern, editor-friendly build setup.
Requirements:
- Visual Studio 2022 with Desktop development with C++
- CMake 3.21+
The repository already contains the required prebuilt Windows SDL packages in `Libraries/`.
Configure and build:
```bash
cmake -S . -B build -G "Visual Studio 17 2022" -A x64
cmake --build build --config Debug
```
### 2. CMake on Linux
Requirements:
- C++ compiler
- CMake 3.21+
- SDL2 development packages
- OpenGL development package
Ubuntu / Debian example:
```bash
sudo apt install build-essential cmake libsdl2-dev libsdl2-image-dev libsdl2-mixer-dev libsdl2-ttf-dev libgl1-mesa-dev
cmake -S . -B build
cmake --build build
```
### 3. Legacy Visual Studio solution
The existing `.sln` and `.vcxproj` files are still in the repo and can still be opened directly in Visual Studio.
## Build output
The CMake build writes the executable to:
- `build/bin/` for single-config generators
- the active configuration output folder for Visual Studio generators
Resource files from `Resources/` are copied automatically after a successful build.
## Notes about dependencies
### Windows
CMake uses the bundled SDL package config files from:
- `Libraries/SDLMain/.../cmake`
- `Libraries/SDLImage/.../cmake`
- `Libraries/SDLMixer/.../cmake`
- `Libraries/SDLTtf/.../cmake`
### Linux
CMake falls back to `pkg-config` and expects these packages to be installed:
- `sdl2`
- `SDL2_image`
- `SDL2_mixer`
- `SDL2_ttf`
## Troubleshooting
### CMake fails at `find_package(OpenGL REQUIRED)`
Install the OpenGL development package.
Ubuntu / Debian:
```bash
sudo apt install libgl1-mesa-dev
```
### CMake cannot find SDL packages on Linux
Install the SDL development packages listed above.
### The game starts but cannot find assets
Run the executable from the build output directory, not from the source directory root. The post-build step copies `Resources/` next to the executable.
### Why are the old MSVC `#pragma comment(lib, ...)` lines still in the code?
They are still there for the legacy Visual Studio project files, but the CMake build disables them explicitly so dependency management stays inside CMake.