Migrate to CMake-based build with packaging

Major build system refactoring:

**CMake (build authority)**:
- Auto-discovers .cpp files (GLOB_RECURSE in source/core/ and source/game/)
- No manual file list maintenance needed
- Excludes source/legacy/ automatically
- Generates build/project.h from template

**Makefile (simplified wrapper)**:
- Delegates compilation to CMake (make → cmake --build build)
- Contains 5 release packaging targets:
  * macos_release: .app bundle + .dmg (Apple Silicon)
  * linux_release: .tar.gz
  * windows_release: .zip with .exe + DLLs
  * windows_cross: cross-compile from Linux/macOS
  * rpi_release: ARM64 cross-compile
- Complex packaging logic preserved (code signing, symlinks, DMG creation)

**Benefits**:
- Add new .cpp file → automatically compiled (no manual updates)
- Single source of truth in CMakeLists.txt (no duplication)
- IDE-friendly (VSCode, CLion, etc.)
- Complete packaging support (5 platforms)

**Files changed**:
- CMakeLists.txt: GLOB_RECURSE replaces 23-file hardcoded list
- Makefile: Simplified compilation + added 5 release targets (~220 lines)
- CLAUDE.md: Updated build system documentation
- escena_titol.cpp: Fixed include path (build/project.h → project.h)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
2025-12-03 07:36:53 +01:00
parent d6b2e97777
commit 69fb5f3cc1
4 changed files with 352 additions and 171 deletions

View File

@@ -12,59 +12,98 @@ This is **Orni Attack**, an **Asteroids-style game** originally written in **Tur
## Build System
Based on `/home/sergio/gitea/pollo` project structure.
Based on `/home/sergio/gitea/pollo` project structure, now with **CMake as build authority** and **automatic file discovery**.
### Build Commands
### Basic Build Commands
```bash
# Clean + compile
make clean && make
make # Compile (delegates to CMake)
make debug # Debug build
make clean # Clean artifacts
./orni # Run
```
# Run
./orni
### Release Packaging
# Individual targets
make linux # Linux build
make macos # macOS build
make windows # Windows build (MinGW)
```bash
make macos_release # macOS .app bundle + .dmg (Apple Silicon)
make linux_release # Linux .tar.gz
make windows_release # Windows .zip (requires MinGW on Windows)
make windows_cross # Cross-compile Windows from Linux/macOS
make rpi_release # Raspberry Pi ARM64 cross-compile
```
### Build Files
- **CMakeLists.txt** - CMake configuration (C++20, SDL3, project metadata)
- **Makefile** - Cross-platform wrapper, extracts project info from CMakeLists.txt
- **CMakeLists.txt** - CMake configuration (C++20, SDL3, auto-discovers .cpp files)
- **Makefile** - Wrapper for compilation + complex packaging recipes
- **source/project.h.in** - Template for auto-generated project.h
- **build/project.h** - Auto-generated (by CMake) with project constants
- **release/** - Platform-specific resources (icons, .rc, .plist)
- **release/** - Platform-specific resources (icons, .rc, .plist, frameworks, DLLs)
### Architecture: Hybrid CMake + Makefile
**CMake handles**: Compilation (simple, standard, IDE-friendly)
- Auto-discovers all `.cpp` files in `source/core/` and `source/game/`
- Excludes `source/legacy/` automatically
- Generates `build/project.h` from template
- Links SDL3
**Makefile handles**: Packaging (complex bash scripts)
- Delegates compilation to CMake (`make``cmake --build build`)
- Contains 5 release packaging targets (macOS, Linux, Windows, RPI, Windows-cross)
- Includes: code signing, framework symlinks, DMG creation, cross-compilation
### Project Metadata System
**Auto-generation with CMake**:
**Single source of truth** in `CMakeLists.txt`:
CMake generates `build/project.h` from `source/project.h.in` template on every compilation:
```cmake
project(orni VERSION 0.3.0)
set(PROJECT_LONG_NAME "Orni Attack")
set(PROJECT_COPYRIGHT "© 1999 Visente i Sergi, 2025 Port")
```
**Auto-generated** `build/project.h`:
```cpp
// build/project.h (generated automatically)
namespace Project {
constexpr const char* NAME = "orni"; // From project(orni ...)
constexpr const char* LONG_NAME = "Orni Attack"; // From PROJECT_LONG_NAME
constexpr const char* VERSION = "0.1.0"; // From VERSION
constexpr const char* COPYRIGHT = "© 1999..."; // From PROJECT_COPYRIGHT
constexpr const char* GIT_HASH = "abc1234"; // From git rev-parse
constexpr const char* NAME = "orni";
constexpr const char* LONG_NAME = "Orni Attack";
constexpr const char* VERSION = "0.3.0";
constexpr const char* COPYRIGHT = "© 1999 Visente i Sergi, 2025 Port";
constexpr const char* GIT_HASH = "abc1234"; // From git rev-parse
}
```
**Window title format** (dynamic, in sdl_manager.cpp):
```cpp
std::format("{} v{} ({})",
Project::LONG_NAME, // "Orni Attack"
Project::VERSION, // "0.1.0"
Project::COPYRIGHT) // "© 1999 Visente i Sergi, 2025 Port"
**Window title** (dynamic): `Orni Attack v0.3.0 (© 1999 Visente i Sergi, 2025 Port)`
### File Discovery
**Automatic** - no manual maintenance needed:
```cmake
# CMakeLists.txt automatically finds:
file(GLOB_RECURSE CORE_SOURCES "source/core/*.cpp")
file(GLOB_RECURSE GAME_SOURCES "source/game/*.cpp")
# + source/main.cpp
# - source/legacy/* (excluded)
```
Result: `Orni Attack v0.1.0 (© 1999 Visente i Sergi, 2025 Port)`
**When you create a new file** like `source/game/entities/asteroide.cpp`:
1. Just create it in the appropriate directory
2. Run `make`
3. CMake automatically detects and compiles it
**Single source of truth**: All project info in CMakeLists.txt, no hardcoded strings.
**No need to edit** Makefile or CMakeLists.txt!
### Cross-Platform Notes
- **macOS**: Requires `create-dmg` (auto-installed via Homebrew)
- **Windows**: Compile natively with MinGW or use `make windows_cross` on Linux/macOS
- **Windows cross**: Requires `x86_64-w64-mingw32-g++` toolchain
- **RPI cross**: Requires `aarch64-linux-gnu-g++` toolchain
- **Frameworks**: macOS release includes SDL3.xcframework with symlink recreation
## Architecture