SFML Strategy Game - CMake Setup
Dieses Projekt nutzt CMake für plattformunabhängiges Bauen mit SFML 3.x.
Voraussetzungen
Windows
-
MSYS2 installieren
- Download: https://www.msys2.org/
- Installiere nach
C:\msys64(Standard) - Nach Installation: MSYS2 MINGW64 Terminal öffnen
-
Pakete installieren
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 -
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)
-
Pakete installieren
sudo apt update sudo apt install build-essential sudo apt install cmake sudo apt install libsfml-dev sudo apt install gdb -
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)
-
Projekt öffnen in VSCodium
-
Bauen:
- Drücke
Ctrl+Shift+B→ Wähle "CMake: Build" - Oder einfach
Ctrl+Shift+B(Standard Build-Task)
- Drücke
-
Ausführen:
Ctrl+Shift+P→ "Tasks: Run Test Task"- Oder
F5zum Debuggen
Manuell (Terminal)
Konfigurieren:
cmake -B build -S .
Bauen:
cmake --build build
Ausführen:
Windows (MSYS2):
./build/bin/StrategyGame.exe
Linux:
./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 DebuggingF10- Step OverF11- Step IntoShift+F11- Step OutShift+F5- Stop
Build-Typen
Debug (Standard):
cmake -B build -S . -DCMAKE_BUILD_TYPE=Debug
cmake --build build
Release (optimiert):
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:
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
.dllDateien
→ Diesen Ordner verteilen!
Linux
cmake -B build -S . -DCMAKE_BUILD_TYPE=Release
cmake --build build
Die Executable ist in build/bin/StrategyGame.
Troubleshooting
Windows: CMake not found
# In MSYS2 MINGW64:
pacman -S mingw-w64-x86_64-cmake
Linux: SFML not found
sudo apt install libsfml-dev
"No such file or directory" beim Build
- Stelle sicher, dass du im Projekt-Root-Verzeichnis bist
CMakeLists.txtmuss im aktuellen Verzeichnis sein
Build-Ordner aufräumen
rm -rf build
cmake -B build -S .
cmake --build build
Nützliche CMake-Befehle
# 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
Description
Languages
CMake
64.8%
C++
35.2%