somestrategiegame/README.md
2026-03-16 11:55:10 +01:00

209 lines
4.1 KiB
Markdown

# SFML Strategy Game - CMake Setup
Dieses Projekt nutzt **CMake** für plattformunabhängiges Bauen mit SFML 3.x.
## Voraussetzungen
### Windows
1. **MSYS2 installieren**
- Download: https://www.msys2.org/
- Installiere nach `C:\msys64` (Standard)
- Nach Installation: MSYS2 MINGW64 Terminal öffnen
2. **Pakete installieren**
```bash
pacman -Syu
pacman -S mingw-w64-x86_64-gcc
pacman -S mingw-w64-x86_64-sfml
pacman -S mingw-w64-x86_64-cmake
pacman -S mingw-w64-x86_64-gdb
pacman -S make
```
3. **VSCodium / VS Code**
- Installiere VSCodium oder VS Code
- Installiere Extensions:
- `C/C++` (Microsoft)
- `CMake Tools` (optional, aber empfohlen)
- `cppdbg` (für Debugging)
### Linux (Ubuntu/Debian)
1. **Pakete installieren**
```bash
sudo apt update
sudo apt install build-essential
sudo apt install cmake
sudo apt install libsfml-dev
sudo apt install gdb
```
2. **VSCodium / VS Code**
- Installiere VSCodium oder VS Code
- Installiere Extensions:
- `C/C++` (Microsoft)
- `CMake Tools` (optional)
- `cppdbg` (für Debugging)
## Projekt Setup
### Mit VSCodium (empfohlen)
1. **Projekt öffnen** in VSCodium
2. **Bauen:**
- Drücke `Ctrl+Shift+B` → Wähle "CMake: Build"
- Oder einfach `Ctrl+Shift+B` (Standard Build-Task)
3. **Ausführen:**
- `Ctrl+Shift+P` → "Tasks: Run Test Task"
- Oder `F5` zum Debuggen
### Manuell (Terminal)
**Konfigurieren:**
```bash
cmake -B build -S .
```
**Bauen:**
```bash
cmake --build build
```
**Ausführen:**
Windows (MSYS2):
```bash
./build/bin/StrategyGame.exe
```
Linux:
```bash
./build/bin/StrategyGame
```
## Projekt-Struktur
```
projekt/
├── CMakeLists.txt # CMake Konfiguration
├── .vscode/
│ ├── tasks.json # Build-Tasks
│ ├── launch.json # Debug-Konfiguration
│ ├── c_cpp_properties.json
│ └── settings.json # Terminal-Einstellungen
├── src/
│ └── main.cpp # Haupt-Spielcode
├── build/ # Generierter Build-Ordner
│ └── bin/ # Kompilierte Executable
└── README.md
```
## Debugging
### Breakpoints setzen
- Klicke links neben die Zeilennummer (roter Punkt)
### Debugging starten
- `F5` - Start Debugging
- `F10` - Step Over
- `F11` - Step Into
- `Shift+F11` - Step Out
- `Shift+F5` - Stop
## Build-Typen
**Debug (Standard):**
```bash
cmake -B build -S . -DCMAKE_BUILD_TYPE=Debug
cmake --build build
```
**Release (optimiert):**
```bash
cmake -B build -S . -DCMAKE_BUILD_TYPE=Release
cmake --build build
```
## DLL-Verwaltung (Windows)
CMake kopiert **automatisch** alle benötigten SFML-DLLs in den `build/bin/` Ordner!
Kein manuelles Kopieren nötig. 🎉
## Distribution / Release
### Windows
**Release bauen:**
```bash
cmake -B build -S . -DCMAKE_BUILD_TYPE=Release
cmake --build build --config Release
```
Der `build/bin/` Ordner enthält dann:
- `StrategyGame.exe`
- Alle benötigten `.dll` Dateien
→ Diesen Ordner verteilen!
### Linux
```bash
cmake -B build -S . -DCMAKE_BUILD_TYPE=Release
cmake --build build
```
Die Executable ist in `build/bin/StrategyGame`.
## Troubleshooting
### Windows: CMake not found
```bash
# In MSYS2 MINGW64:
pacman -S mingw-w64-x86_64-cmake
```
### Linux: SFML not found
```bash
sudo apt install libsfml-dev
```
### "No such file or directory" beim Build
- Stelle sicher, dass du im Projekt-Root-Verzeichnis bist
- `CMakeLists.txt` muss im aktuellen Verzeichnis sein
### Build-Ordner aufräumen
```bash
rm -rf build
cmake -B build -S .
cmake --build build
```
## Nützliche CMake-Befehle
```bash
# Neukonfigurieren
cmake -B build -S .
# Bauen (verbose)
cmake --build build --verbose
# Nur bestimmtes Target bauen
cmake --build build --target StrategyGame
# Clean
cmake --build build --target clean
# Kompletter Rebuild
rm -rf build && cmake -B build -S . && cmake --build build
```
## Nützliche Links
- CMake Dokumentation: https://cmake.org/documentation/
- SFML Dokumentation: https://www.sfml-dev.org/documentation/3.0.0/
- SFML mit CMake: https://www.sfml-dev.org/tutorials/3.0/compile-with-cmake.php