2026-03-16 11:55:10 +01:00

4.1 KiB

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

    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

    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:

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 Debugging
  • F10 - Step Over
  • F11 - Step Into
  • Shift+F11 - Step Out
  • Shift+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 .dll Dateien

→ 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.txt muss 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