binari i recursos a build/, targets en kebab

This commit is contained in:
2026-05-14 17:26:04 +02:00
parent e2bc6aa5c0
commit 118626dff6
3 changed files with 73 additions and 39 deletions
+21 -8
View File
@@ -136,13 +136,6 @@ endif()
# Includes relatius a source/ (p.e. `#include "core/rendering/texture.h"`) # Includes relatius a source/ (p.e. `#include "core/rendering/texture.h"`)
target_include_directories(${PROJECT_NAME} PRIVATE ${DIR_SOURCES}) target_include_directories(${PROJECT_NAME} PRIVATE ${DIR_SOURCES})
# Configuración de salida: el ejecutable principal va a la raíz del proyecto.
# Per-target (no global) perquè `pack_resources` acabe a `build/` com la resta
# de projectes.
if(NOT EMSCRIPTEN)
set_target_properties(${PROJECT_NAME} PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR})
endif()
# Añadir definiciones de compilación dependiendo del tipo de build # Añadir definiciones de compilación dependiendo del tipo de build
target_compile_definitions(${PROJECT_NAME} PRIVATE target_compile_definitions(${PROJECT_NAME} PRIVATE
$<$<CONFIG:DEBUG>:DEBUG PAUSE> $<$<CONFIG:DEBUG>:DEBUG PAUSE>
@@ -292,7 +285,7 @@ if(NOT EMSCRIPTEN)
# Regeneració automàtica de resources.pack en cada build si canvia data/. # Regeneració automàtica de resources.pack en cada build si canvia data/.
file(GLOB_RECURSE DATA_FILES CONFIGURE_DEPENDS "${CMAKE_SOURCE_DIR}/data/*") file(GLOB_RECURSE DATA_FILES CONFIGURE_DEPENDS "${CMAKE_SOURCE_DIR}/data/*")
set(RESOURCE_PACK "${CMAKE_SOURCE_DIR}/resources.pack") set(RESOURCE_PACK "${CMAKE_BINARY_DIR}/resources.pack")
add_custom_command( add_custom_command(
OUTPUT ${RESOURCE_PACK} OUTPUT ${RESOURCE_PACK}
@@ -307,4 +300,24 @@ if(NOT EMSCRIPTEN)
add_custom_target(resource_pack ALL DEPENDS ${RESOURCE_PACK}) add_custom_target(resource_pack ALL DEPENDS ${RESOURCE_PACK})
add_dependencies(${PROJECT_NAME} resource_pack) add_dependencies(${PROJECT_NAME} resource_pack)
# --- CÒPIA DE gamecontrollerdb.txt AL COSTAT DEL BINARI ---
# SDL_AddGamepadMappingsFromFile només llegeix del filesystem real (no del
# pack), així que el fitxer ha de viure al directori del binari. Es copia
# només si existeix per no fallar la build d'algú que encara no ha fet
# `make controllerdb`.
if(EXISTS "${CMAKE_SOURCE_DIR}/gamecontrollerdb.txt")
set(CONTROLLER_DB "${CMAKE_BINARY_DIR}/gamecontrollerdb.txt")
add_custom_command(
OUTPUT ${CONTROLLER_DB}
COMMAND ${CMAKE_COMMAND} -E copy_if_different
"${CMAKE_SOURCE_DIR}/gamecontrollerdb.txt"
"${CONTROLLER_DB}"
DEPENDS "${CMAKE_SOURCE_DIR}/gamecontrollerdb.txt"
COMMENT "Copiant gamecontrollerdb.txt → build/"
VERBATIM
)
add_custom_target(controller_db ALL DEPENDS ${CONTROLLER_DB})
add_dependencies(${PROJECT_NAME} controller_db)
endif()
endif() endif()
+46 -29
View File
@@ -2,13 +2,13 @@
# DIRECTORIES # DIRECTORIES
# ============================================================================== # ==============================================================================
DIR_ROOT := $(dir $(abspath $(MAKEFILE_LIST))) DIR_ROOT := $(dir $(abspath $(MAKEFILE_LIST)))
DIR_BIN := $(addsuffix /, $(DIR_ROOT)) BUILDDIR := build
# ============================================================================== # ==============================================================================
# TARGET NAMES # TARGET NAMES
# ============================================================================== # ==============================================================================
TARGET_NAME := coffee_crisis TARGET_NAME := coffee_crisis
TARGET_FILE := $(DIR_BIN)$(TARGET_NAME) TARGET_FILE := $(BUILDDIR)/$(TARGET_NAME)
APP_NAME := Coffee Crisis APP_NAME := Coffee Crisis
DIST_DIR := dist DIST_DIR := dist
RELEASE_FOLDER := dist/_tmp RELEASE_FOLDER := dist/_tmp
@@ -72,7 +72,7 @@ endif
# WINDOWS-SPECIFIC VARIABLES # WINDOWS-SPECIFIC VARIABLES
# ============================================================================== # ==============================================================================
ifeq ($(OS),Windows_NT) ifeq ($(OS),Windows_NT)
WIN_TARGET_FILE := $(DIR_BIN)$(APP_NAME) WIN_TARGET_FILE := $(BUILDDIR)/$(APP_NAME)
WIN_RELEASE_FILE := $(RELEASE_FOLDER)/$(APP_NAME) WIN_RELEASE_FILE := $(RELEASE_FOLDER)/$(APP_NAME)
# Escapa apòstrofs per a PowerShell (duplica ' → ''). Sense això, APP_NAMEs # Escapa apòstrofs per a PowerShell (duplica ' → ''). Sense això, APP_NAMEs
# com "JailDoctor's Dilemma" trencarien el parsing de -Destination '...'. # com "JailDoctor's Dilemma" trencarien el parsing de -Destination '...'.
@@ -122,32 +122,43 @@ debug:
@cmake $(CMAKE_GEN) -S . -B build -DCMAKE_BUILD_TYPE=Debug -DGIT_HASH=$(GIT_HASH) @cmake $(CMAKE_GEN) -S . -B build -DCMAKE_BUILD_TYPE=Debug -DGIT_HASH=$(GIT_HASH)
@cmake --build build @cmake --build build
run: all
@./$(TARGET_FILE)
run-debug: debug
@./$(TARGET_FILE)
clean:
@rm -rf $(BUILDDIR)
rebuild: clean all
# ============================================================================== # ==============================================================================
# EMPAQUETADO DE RECURSOS (build previ de l'eina + execució) # EMPAQUETADO DE RECURSOS (build previ de l'eina + execució)
# ============================================================================== # ==============================================================================
pack: pack:
@cmake $(CMAKE_GEN) -S . -B build -DCMAKE_BUILD_TYPE=Release -DGIT_HASH=$(GIT_HASH) @cmake $(CMAKE_GEN) -S . -B build -DCMAKE_BUILD_TYPE=Release -DGIT_HASH=$(GIT_HASH)
@cmake --build build --target pack_resources @cmake --build build --target pack_resources
@./build/pack_resources data resources.pack @./build/pack_resources data build/resources.pack
# ============================================================================== # ==============================================================================
# RELEASE AUTOMÁTICO (detecta SO) # RELEASE AUTOMÁTICO (detecta SO)
# ============================================================================== # ==============================================================================
release: release:
ifeq ($(OS),Windows_NT) ifeq ($(OS),Windows_NT)
@"$(MAKE)" _windows_release @"$(MAKE)" _windows-release
else else
ifeq ($(UNAME_S),Darwin) ifeq ($(UNAME_S),Darwin)
@$(MAKE) _macos_release @$(MAKE) _macos-release
else else
@$(MAKE) _linux_release @$(MAKE) _linux-release
endif endif
endif endif
# ============================================================================== # ==============================================================================
# COMPILACIÓN PARA WINDOWS (RELEASE) # COMPILACIÓN PARA WINDOWS (RELEASE)
# ============================================================================== # ==============================================================================
_windows_release: _windows-release:
@$(MAKE) pack @$(MAKE) pack
@echo off @echo off
@echo Creando release para Windows - Version: $(VERSION) @echo Creando release para Windows - Version: $(VERSION)
@@ -162,7 +173,7 @@ _windows_release:
@powershell -Command "if (-not (Test-Path '$(RELEASE_FOLDER)')) {New-Item '$(RELEASE_FOLDER)' -ItemType Directory}" @powershell -Command "if (-not (Test-Path '$(RELEASE_FOLDER)')) {New-Item '$(RELEASE_FOLDER)' -ItemType Directory}"
# Copia ficheros # Copia ficheros
@powershell -Command "Copy-Item 'resources.pack' -Destination '$(RELEASE_FOLDER)'" @powershell -Command "Copy-Item 'build/resources.pack' -Destination '$(RELEASE_FOLDER)'"
@powershell -Command "Copy-Item 'gamecontrollerdb.txt' -Destination '$(RELEASE_FOLDER)'" @powershell -Command "Copy-Item 'gamecontrollerdb.txt' -Destination '$(RELEASE_FOLDER)'"
@powershell -Command "Copy-Item 'LICENSE' -Destination '$(RELEASE_FOLDER)'" @powershell -Command "Copy-Item 'LICENSE' -Destination '$(RELEASE_FOLDER)'"
@powershell -Command "Copy-Item 'README.md' -Destination '$(RELEASE_FOLDER)'" @powershell -Command "Copy-Item 'README.md' -Destination '$(RELEASE_FOLDER)'"
@@ -181,7 +192,7 @@ _windows_release:
# ============================================================================== # ==============================================================================
# COMPILACIÓN PARA MACOS (RELEASE) # COMPILACIÓN PARA MACOS (RELEASE)
# ============================================================================== # ==============================================================================
_macos_release: _macos-release:
@$(MAKE) pack @$(MAKE) pack
@echo "Creando release para macOS - Version: $(VERSION)" @echo "Creando release para macOS - Version: $(VERSION)"
@@ -221,7 +232,7 @@ _macos_release:
$(MKDIR) "$(RELEASE_FOLDER)/$(APP_NAME).app/Contents/Resources" $(MKDIR) "$(RELEASE_FOLDER)/$(APP_NAME).app/Contents/Resources"
# Copia carpetas y ficheros # Copia carpetas y ficheros
cp resources.pack "$(RELEASE_FOLDER)/$(APP_NAME).app/Contents/Resources" cp build/resources.pack "$(RELEASE_FOLDER)/$(APP_NAME).app/Contents/Resources"
cp gamecontrollerdb.txt "$(RELEASE_FOLDER)/$(APP_NAME).app/Contents/Resources" cp gamecontrollerdb.txt "$(RELEASE_FOLDER)/$(APP_NAME).app/Contents/Resources"
cp -R release/macos/frameworks/SDL3.xcframework/macos-arm64_x86_64/SDL3.framework "$(RELEASE_FOLDER)/$(APP_NAME).app/Contents/Frameworks" cp -R release/macos/frameworks/SDL3.xcframework/macos-arm64_x86_64/SDL3.framework "$(RELEASE_FOLDER)/$(APP_NAME).app/Contents/Frameworks"
cp release/icons/*.icns "$(RELEASE_FOLDER)/$(APP_NAME).app/Contents/Resources" cp release/icons/*.icns "$(RELEASE_FOLDER)/$(APP_NAME).app/Contents/Resources"
@@ -311,7 +322,7 @@ _macos_release:
# ============================================================================== # ==============================================================================
# COMPILACIÓN PARA LINUX (RELEASE) # COMPILACIÓN PARA LINUX (RELEASE)
# ============================================================================== # ==============================================================================
_linux_release: _linux-release:
@$(MAKE) pack @$(MAKE) pack
@echo "Creando release para Linux - Version: $(VERSION)" @echo "Creando release para Linux - Version: $(VERSION)"
@@ -324,7 +335,7 @@ _linux_release:
$(MKDIR) "$(RELEASE_FOLDER)" $(MKDIR) "$(RELEASE_FOLDER)"
# Copia ficheros # Copia ficheros
cp resources.pack "$(RELEASE_FOLDER)" cp build/resources.pack "$(RELEASE_FOLDER)"
cp gamecontrollerdb.txt "$(RELEASE_FOLDER)" cp gamecontrollerdb.txt "$(RELEASE_FOLDER)"
cp LICENSE "$(RELEASE_FOLDER)" cp LICENSE "$(RELEASE_FOLDER)"
cp README.md "$(RELEASE_FOLDER)" cp README.md "$(RELEASE_FOLDER)"
@@ -362,8 +373,8 @@ wasm:
ssh maverick 'cd /home/sergio/gitea/web_jailgames && ./deploy.sh' ssh maverick 'cd /home/sergio/gitea/web_jailgames && ./deploy.sh'
@echo "Deployed to maverick" @echo "Deployed to maverick"
# Versió Debug del build wasm: build local sense deploy. Sortida a dist/wasm_debug/. # Versió Debug del build wasm: build local sense deploy. Sortida a dist/wasm-debug/.
wasm_debug: wasm-debug:
@$(MAKE) pack @$(MAKE) pack
@echo "Compilando WebAssembly Debug - Version: $(VERSION)" @echo "Compilando WebAssembly Debug - Version: $(VERSION)"
docker run --rm \ docker run --rm \
@@ -371,13 +382,13 @@ wasm_debug:
-v $(DIR_ROOT):/src \ -v $(DIR_ROOT):/src \
-w /src \ -w /src \
emscripten/emsdk:latest \ emscripten/emsdk:latest \
bash -c "emcmake cmake -S . -B build/wasm_debug -DCMAKE_BUILD_TYPE=Debug -DGIT_HASH=$(GIT_HASH) && cmake --build build/wasm_debug" bash -c "emcmake cmake -S . -B build/wasm-debug -DCMAKE_BUILD_TYPE=Debug -DGIT_HASH=$(GIT_HASH) && cmake --build build/wasm-debug"
$(MKDIR) "$(DIST_DIR)/wasm_debug" $(MKDIR) "$(DIST_DIR)/wasm-debug"
cp build/wasm_debug/$(TARGET_NAME).html $(DIST_DIR)/wasm_debug/ cp build/wasm-debug/$(TARGET_NAME).html $(DIST_DIR)/wasm-debug/
cp build/wasm_debug/$(TARGET_NAME).js $(DIST_DIR)/wasm_debug/ cp build/wasm-debug/$(TARGET_NAME).js $(DIST_DIR)/wasm-debug/
cp build/wasm_debug/$(TARGET_NAME).wasm $(DIST_DIR)/wasm_debug/ cp build/wasm-debug/$(TARGET_NAME).wasm $(DIST_DIR)/wasm-debug/
cp build/wasm_debug/$(TARGET_NAME).data $(DIST_DIR)/wasm_debug/ cp build/wasm-debug/$(TARGET_NAME).data $(DIST_DIR)/wasm-debug/
@echo "Output: $(DIST_DIR)/wasm_debug/" @echo "Output: $(DIST_DIR)/wasm-debug/"
# ============================================================================== # ==============================================================================
# ============================================================================== # ==============================================================================
@@ -404,7 +415,7 @@ cppcheck:
@cmake --build build --target cppcheck @cmake --build build --target cppcheck
# SHADERS (SPIR-V) — sólo Linux/Windows. Requiere glslc en el PATH. # SHADERS (SPIR-V) — sólo Linux/Windows. Requiere glslc en el PATH.
compile_shaders: compile-shaders:
@cmake $(CMAKE_GEN) -S . -B build -DCMAKE_BUILD_TYPE=Release -DGIT_HASH=$(GIT_HASH) @cmake $(CMAKE_GEN) -S . -B build -DCMAKE_BUILD_TYPE=Release -DGIT_HASH=$(GIT_HASH)
@cmake --build build --target shaders @cmake --build build --target shaders
@@ -419,7 +430,7 @@ controllerdb:
# ============================================================================== # ==============================================================================
# REGLAS ESPECIALES # REGLAS ESPECIALES
# ============================================================================== # ==============================================================================
show_version: show-version:
@echo "Version actual: $(VERSION)" @echo "Version actual: $(VERSION)"
help: help:
@@ -430,14 +441,18 @@ help:
@echo " make - Compilar con cmake (Release)" @echo " make - Compilar con cmake (Release)"
@echo " make debug - Compilar con cmake (Debug)" @echo " make debug - Compilar con cmake (Debug)"
@echo "" @echo ""
@echo " Ejecucion:"
@echo " make run - Compilar (Release) y ejecutar"
@echo " make run-debug - Compilar (Debug) y ejecutar"
@echo ""
@echo " Release:" @echo " Release:"
@echo " make release - Crear release (detecta SO automaticamente)" @echo " make release - Crear release (detecta SO automaticamente)"
@echo " make wasm - Compilar para WebAssembly (requiere Docker) y deploy a maverick" @echo " make wasm - Compilar para WebAssembly (requiere Docker) y deploy a maverick"
@echo " make wasm_debug - Compilar WebAssembly Debug local (sin deploy)" @echo " make wasm-debug - Compilar WebAssembly Debug local (sin deploy)"
@echo "" @echo ""
@echo " Herramientas:" @echo " Herramientas:"
@echo " make pack - Empaquetar recursos a resources.pack" @echo " make pack - Empaquetar recursos a $(BUILDDIR)/resources.pack"
@echo " make compile_shaders - Compilar shaders GLSL a headers SPIR-V (requiere glslc)" @echo " make compile-shaders - Compilar shaders GLSL a headers SPIR-V (requiere glslc)"
@echo " make controllerdb - Descargar gamecontrollerdb.txt actualizado" @echo " make controllerdb - Descargar gamecontrollerdb.txt actualizado"
@echo "" @echo ""
@echo " Calidad de codigo:" @echo " Calidad de codigo:"
@@ -448,7 +463,9 @@ help:
@echo " make cppcheck - Analisis estatico con cppcheck" @echo " make cppcheck - Analisis estatico con cppcheck"
@echo "" @echo ""
@echo " Otros:" @echo " Otros:"
@echo " make show_version - Mostrar version actual ($(VERSION))" @echo " make clean - Borrar carpeta $(BUILDDIR)/"
@echo " make rebuild - clean + all"
@echo " make show-version - Mostrar version actual ($(VERSION))"
@echo " make help - Mostrar esta ayuda" @echo " make help - Mostrar esta ayuda"
.PHONY: all debug release _windows_release _macos_release _linux_release wasm wasm_debug controllerdb pack format format-check tidy tidy-fix cppcheck compile_shaders show_version help .PHONY: all debug run run-debug clean rebuild release _windows-release _macos-release _linux-release wasm wasm-debug controllerdb pack format format-check tidy tidy-fix cppcheck compile-shaders show-version help
+6 -2
View File
@@ -11,9 +11,13 @@
cmake_minimum_required(VERSION 3.10) cmake_minimum_required(VERSION 3.10)
get_filename_component(SRC_NAME "${SRC}" NAME_WE) # Nom intermedi únic per stage (vert/frag/comp) per evitar col·lisions en
# builds paral·lels: postfx.vert i postfx.frag generarien el mateix
# `postfx.spv` si féssim servir el nom del SRC. Usem el del OUT_H, que ja
# inclou el stage (p.ex. `postfx_frag_spv.h` → `postfx_frag_spv.spv`).
get_filename_component(OUT_DIR "${OUT_H}" DIRECTORY) get_filename_component(OUT_DIR "${OUT_H}" DIRECTORY)
set(OUT_SPV "${OUT_DIR}/${SRC_NAME}.spv") get_filename_component(OUT_NAME "${OUT_H}" NAME_WE)
set(OUT_SPV "${OUT_DIR}/${OUT_NAME}.spv")
# Compilar GLSL → SPIR-V # Compilar GLSL → SPIR-V
if(DEFINED STAGE AND NOT STAGE STREQUAL "") if(DEFINED STAGE AND NOT STAGE STREQUAL "")