diff --git a/.gitignore b/.gitignore index 246db4b..a8b1fc0 100644 --- a/.gitignore +++ b/.gitignore @@ -5,7 +5,6 @@ /CMakeFiles/ /CMakeCache.txt /cmake_install.cmake -/Makefile /*.cmake /*.obj /*.o @@ -20,7 +19,7 @@ # Generated by CMake/IDE /compile_commands.json -/.ninja* +/.ninja* /_deps/ /install_manifest.txt @@ -29,9 +28,16 @@ third_party/**/build/ third_party/**/CMakeFiles/ third_party/**/CMakeCache.txt +# Release artifacts +shadertoy_release/ +*.zip +*.tar.gz +*.dmg + # IDEs and editors .vscode/ .idea/ +.claude/ *.suo *.user *.userprefs diff --git a/CMakeLists.txt b/CMakeLists.txt index a1d8480..38f91a8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,143 +1,77 @@ -cmake_minimum_required(VERSION 3.14) -project(shadertoy_sdl3 LANGUAGES C CXX) +# CMakeLists.txt +cmake_minimum_required(VERSION 3.10) +project(shadertoy VERSION 1.00) + +# Establecer estándar de C++ set(CMAKE_CXX_STANDARD 17) -set(CMAKE_CXX_STANDARD_REQUIRED ON) +set(CMAKE_CXX_STANDARD_REQUIRED True) -# Default to Release for single-config generators when none specified -if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) - set(CMAKE_BUILD_TYPE Release CACHE STRING "Build type" FORCE) -endif() +# Establece la política CMP0072 para indicar cómo se debe seleccionar la implementación de OpenGL. +# En este caso, se elige la opción "GLVND", que utiliza bibliotecas modernas y modulares (libOpenGL, libGLX), +# en lugar de la biblioteca OpenGL clásica (libGL). Esto mejora la compatibilidad con drivers recientes +# y evita ambigüedades cuando se encuentran múltiples implementaciones de OpenGL en el sistema. +cmake_policy(SET CMP0072 NEW) +set(OpenGL_GL_PREFERENCE GLVND) -# Paths -set(GLAD_SRC "${CMAKE_CURRENT_SOURCE_DIR}/third_party/glad/src/glad.c") -if(NOT EXISTS "${GLAD_SRC}") - message(FATAL_ERROR "glad.c no encontrado en: ${GLAD_SRC}") -endif() - -# glad library -add_library(glad_src STATIC "${GLAD_SRC}") -target_include_directories(glad_src PUBLIC - ${CMAKE_CURRENT_SOURCE_DIR}/third_party/glad/include +# --- LISTA EXPLÍCITA DE FUENTES --- +set(APP_SOURCES + src/main.cpp ) -set_target_properties(glad_src PROPERTIES LINKER_LANGUAGE C) -# Executable -add_executable(shadertoy_sdl3 - src/main.cpp +# Fuentes de librerías de terceros +set(EXTERNAL_SOURCES + third_party/glad/src/glad.c ) -target_include_directories(shadertoy_sdl3 PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/third_party/glad/include) -# SDL3 -find_package(SDL3 REQUIRED) -target_link_libraries(shadertoy_sdl3 PRIVATE glad_src SDL3::SDL3) +# Configuración de SDL3 +find_package(SDL3 REQUIRED CONFIG REQUIRED COMPONENTS SDL3) +message(STATUS "SDL3 encontrado: ${SDL3_INCLUDE_DIRS}") -# Platform-specific flags and linkers (try to mimic your Makefile) +# --- AÑADIR EJECUTABLE --- +add_executable(${PROJECT_NAME} ${APP_SOURCES} ${EXTERNAL_SOURCES}) + +# --- DIRECTORIOS DE INCLUSIÓN --- +target_include_directories(${PROJECT_NAME} PUBLIC + "${CMAKE_SOURCE_DIR}/src" + "${CMAKE_SOURCE_DIR}/third_party/glad/include" +) + +# Enlazar la librería SDL3 +target_link_libraries(${PROJECT_NAME} PRIVATE SDL3::SDL3) + + +# --- CONFIGURACIÓN PLATAFORMAS Y COMPILADOR --- +# Configuración de flags de compilación +target_compile_options(${PROJECT_NAME} PRIVATE -Wall) +target_compile_options(${PROJECT_NAME} PRIVATE $<$:-Os -ffunction-sections -fdata-sections>) + +# Definir _DEBUG en modo Debug +target_compile_definitions(${PROJECT_NAME} PRIVATE $<$:_DEBUG>) + + +# Configuración específica para cada plataforma if(WIN32) - target_compile_definitions(shadertoy_sdl3 PRIVATE WINDOWS_BUILD) - if(MSVC) - # MSVC: reasonable defaults; adjust as needed - target_compile_options(shadertoy_sdl3 PRIVATE /W3 /permissive-) - # Link to system libraries (MSVC uses system libs automatically for system includes) - target_link_libraries(shadertoy_sdl3 PRIVATE opengl32) - else() - # MinGW / GNU on Windows - target_compile_options(shadertoy_sdl3 PRIVATE -std=c++17 -Wall -Os -ffunction-sections -fdata-sections) - target_link_options(shadertoy_sdl3 PRIVATE "-Wl,--gc-sections" "-Wl,-Bstatic" "-Wl,-Bdynamic") - target_link_libraries(shadertoy_sdl3 PRIVATE -lmingw32 -lws2_32 -lSDL3 -lopengl32) - endif() -else() - # POSIX platforms - target_compile_options(shadertoy_sdl3 PRIVATE -std=c++17 -Wall -Os) - if(APPLE) - find_library(COCOA_LIBRARY Cocoa REQUIRED) - find_library(IOKIT_LIBRARY IOKit REQUIRED) - find_library(CORE_VIDEO_LIBRARY CoreVideo REQUIRED) - target_link_libraries(shadertoy_sdl3 PRIVATE ${COCOA_LIBRARY} ${IOKIT_LIBRARY} ${CORE_VIDEO_LIBRARY}) - target_compile_options(shadertoy_sdl3 PRIVATE -arch arm64) - else() + target_compile_definitions(${PROJECT_NAME} PRIVATE WINDOWS_BUILD) + target_link_libraries(${PROJECT_NAME} PRIVATE ws2_32 mingw32 opengl32) +elseif(APPLE) + target_compile_definitions(${PROJECT_NAME} PRIVATE MACOS_BUILD) + target_compile_options(${PROJECT_NAME} PRIVATE -Wno-deprecated) + set(CMAKE_OSX_ARCHITECTURES "arm64") +elseif(UNIX AND NOT APPLE) + target_compile_definitions(${PROJECT_NAME} PRIVATE LINUX_BUILD) +endif() + +# Configuración común para OpenGL +if(NOT WIN32) find_package(OpenGL REQUIRED) - target_link_libraries(shadertoy_sdl3 PRIVATE OpenGL::GL) - endif() + if(OPENGL_FOUND) + message(STATUS "OpenGL encontrado: ${OPENGL_LIBRARIES}") + target_link_libraries(${PROJECT_NAME} PRIVATE ${OPENGL_LIBRARIES}) + else() + message(FATAL_ERROR "OpenGL no encontrado") + endif() endif() -# Ensure RUNTIME output directory for single-config builds (Release/Debug) -set_target_properties(shadertoy_sdl3 PROPERTIES - RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin" - RUNTIME_OUTPUT_DIRECTORY_RELEASE "${CMAKE_BINARY_DIR}/bin/Release" - RUNTIME_OUTPUT_DIRECTORY_DEBUG "${CMAKE_BINARY_DIR}/bin/Debug" -) - -if(WIN32) - set(RELEASE_DIR "${CMAKE_BINARY_DIR}/release_package") - set(WINDOWS_ZIP "${CMAKE_BINARY_DIR}/${PROJECT_NAME}-${CMAKE_SYSTEM_PROCESSOR}-win.zip") - set(DLL_SOURCE_DIR "${CMAKE_SOURCE_DIR}/release") # coloca tus SDL3.dll aquí - - # PowerShell script que realizará las copias y el ZIP de forma robusta. - set(PS_SCRIPT "${CMAKE_BINARY_DIR}/package_windows.ps1") - file(WRITE "${PS_SCRIPT}" -"param(\n" -" [string]\$srcExe,\n" -" [string]\$releaseDir,\n" -" [string]\$readme,\n" -" [string]\$license,\n" -" [string]\$shadersDir,\n" -" [string]\$dllDir,\n" -" [string]\$outZip\n" -")\n" -"\n" -"# Remove old\n" -"if (Test-Path \$releaseDir) { Remove-Item -Recurse -Force \$releaseDir }\n" -"New-Item -ItemType Directory -Path \$releaseDir | Out-Null\n" -"\n" -"# Copy exe\n" -"Write-Host 'Copying executable...'\n" -"Copy-Item -Path \$srcExe -Destination (Join-Path \$releaseDir (Split-Path \$srcExe -Leaf)) -Force\n" -"\n" -"# Copy README / LICENSE if exist\n" -"if (Test-Path \$readme) { Copy-Item -Path \$readme -Destination (Join-Path \$releaseDir 'README.md') -Force }\n" -"if (Test-Path \$license) { Copy-Item -Path \$license -Destination (Join-Path \$releaseDir 'LICENSE') -Force }\n" -"\n" -"# Copy shaders if present\n" -"if (Test-Path \$shadersDir) { Copy-Item -Path (Join-Path \$shadersDir '*') -Destination (Join-Path \$releaseDir 'shaders') -Recurse -Force }\n" -"\n" -"# Copy DLLs if present\n" -"if (Test-Path \$dllDir) { Copy-Item -Path (Join-Path \$dllDir '*') -Destination (Join-Path \$releaseDir 'release') -Recurse -Force }\n" -"\n" -"# Create ZIP\n" -"Write-Host 'Creating zip: ' \$outZip\n" -"if (Test-Path \$outZip) { Remove-Item -Force \$outZip }\n" -"Compress-Archive -Path (Join-Path \$releaseDir '*') -DestinationPath \$outZip\n" -"Write-Host 'Package created: ' \$outZip\n" -) - - add_custom_target(package_windows - COMMAND "${CMAKE_COMMAND}" --build "${CMAKE_BINARY_DIR}" --config Release - COMMAND powershell.exe -NoProfile -ExecutionPolicy Bypass -File "${PS_SCRIPT}" - -srcExe "$" - -releaseDir "${RELEASE_DIR}" - -readme "${CMAKE_SOURCE_DIR}/README.md" - -license "${CMAKE_SOURCE_DIR}/LICENSE" - -shadersDir "${CMAKE_SOURCE_DIR}/shaders" - -dllDir "${DLL_SOURCE_DIR}" - -outZip "${WINDOWS_ZIP}" - COMMENT "Building Release and creating Windows package" - BYPRODUCTS "${WINDOWS_ZIP}" - ) - -endif() - -# Helpful messages -message(STATUS "CMake generator: ${CMAKE_GENERATOR}") -message(STATUS "Build type: ${CMAKE_BUILD_TYPE}") -message(STATUS "Binary output (runtime): ${CMAKE_BINARY_DIR}/bin") - -# Developer target: build Release and then package on Windows -add_custom_target(build_release - COMMAND ${CMAKE_COMMAND} --build "${CMAKE_BINARY_DIR}" --config Release - COMMENT "Building Release configuration" -) - -if(WIN32) - add_dependencies(package_windows build_release) -endif() +# Especificar la ubicación del ejecutable en la raíz del proyecto +set_target_properties(${PROJECT_NAME} PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}) diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..f2047b1 --- /dev/null +++ b/Makefile @@ -0,0 +1,223 @@ +# Directorios +DIR_ROOT := $(dir $(abspath $(MAKEFILE_LIST))) +DIR_SOURCES := $(addsuffix /, $(DIR_ROOT)src) +DIR_BIN := $(addsuffix /, $(DIR_ROOT)) +DIR_BUILD := $(addsuffix /, $(DIR_ROOT)build) + +# Variables +TARGET_NAME := shadertoy +TARGET_FILE := $(DIR_BIN)$(TARGET_NAME) +APP_NAME := Shadertoy +RELEASE_FOLDER := shadertoy_release + +# Versión automática basada en la fecha actual (específica por SO) +ifeq ($(OS),Windows_NT) + VERSION := $(shell powershell -Command "Get-Date -Format 'yyyy-MM-dd'") +else + VERSION := $(shell date +%Y-%m-%d) +endif + +# Variables específicas para Windows (usando APP_NAME) +ifeq ($(OS),Windows_NT) + WIN_TARGET_FILE := $(DIR_BIN)$(APP_NAME) + WIN_RELEASE_FILE := $(RELEASE_FOLDER)/$(APP_NAME) +else + WIN_TARGET_FILE := $(TARGET_FILE) + WIN_RELEASE_FILE := $(RELEASE_FOLDER)/$(TARGET_NAME) +endif + +# Nombres para los ficheros de lanzamiento +WINDOWS_RELEASE := $(TARGET_NAME)-$(VERSION)-win32-x64.zip +MACOS_APPLE_SILICON_RELEASE := $(TARGET_NAME)-$(VERSION)-macos-apple-silicon.dmg +LINUX_RELEASE := $(TARGET_NAME)-$(VERSION)-linux.tar.gz + +# Lista completa de archivos fuente +APP_SOURCES := \ + src/main.cpp \ + third_party/glad/src/glad.c + +# Includes +INCLUDES := -Isrc -Ithird_party/glad/include + +# Variables según el sistema operativo +ifeq ($(OS),Windows_NT) + FixPath = $(subst /,\\,$1) + CXXFLAGS := -std=c++17 -Wall -Os -ffunction-sections -fdata-sections -Wl,--gc-sections -static-libstdc++ -static-libgcc -Wl,-Bstatic -lpthread -Wl,-Bdynamic -Wl,-subsystem,windows -DWINDOWS_BUILD + CXXFLAGS_DEBUG := -std=c++17 -Wall -g -D_DEBUG -DWINDOWS_BUILD + LDFLAGS := -lmingw32 -lws2_32 -lSDL3 -lopengl32 + RM := del /Q + MKDIR := mkdir +else + FixPath = $1 + CXXFLAGS := -std=c++17 -Wall -Os -ffunction-sections -fdata-sections + CXXFLAGS_DEBUG := -std=c++17 -Wall -g -D_DEBUG + LDFLAGS := -lSDL3 + RMFILE := rm -f + RMDIR := rm -rdf + MKDIR := mkdir -p + UNAME_S := $(shell uname -s) + ifeq ($(UNAME_S),Linux) + CXXFLAGS += -DLINUX_BUILD + LDFLAGS += -lGL + endif + ifeq ($(UNAME_S),Darwin) + CXXFLAGS += -Wno-deprecated -DMACOS_BUILD + CXXFLAGS_DEBUG += -Wno-deprecated -DMACOS_BUILD + LDFLAGS += -framework OpenGL + # Configurar arquitectura (por defecto arm64, como en CMake) + CXXFLAGS += -arch arm64 + CXXFLAGS_DEBUG += -arch arm64 + endif +endif + +# Reglas para compilación +windows: + @echo off + @echo Compilando para Windows con nombre: "$(APP_NAME).exe" + $(CXX) $(APP_SOURCES) $(INCLUDES) $(CXXFLAGS) $(LDFLAGS) -o "$(WIN_TARGET_FILE).exe" + strip -s -R .comment -R .gnu.version "$(WIN_TARGET_FILE).exe" --strip-unneeded + +windows_debug: + @echo off + @echo Compilando version debug para Windows: "$(APP_NAME)_debug.exe" + $(CXX) $(APP_SOURCES) $(INCLUDES) -DDEBUG $(CXXFLAGS_DEBUG) $(LDFLAGS) -o "$(WIN_TARGET_FILE)_debug.exe" + +windows_release: + @echo off + @echo Creando release para Windows - Version: $(VERSION) + +# Crea carpeta temporal 'RELEASE_FOLDER' + powershell if (Test-Path "$(RELEASE_FOLDER)") {Remove-Item "$(RELEASE_FOLDER)" -Recurse -Force} + powershell if (-not (Test-Path "$(RELEASE_FOLDER)")) {New-Item "$(RELEASE_FOLDER)" -ItemType Directory} + +# Copia la carpeta 'shaders' + powershell Copy-Item -Path "shaders" -Destination "$(RELEASE_FOLDER)" -recurse -Force + +# Copia los ficheros que están en la raíz del proyecto + powershell Copy-Item "LICENSE" -Destination "$(RELEASE_FOLDER)" + powershell Copy-Item "README.md" -Destination "$(RELEASE_FOLDER)" + powershell Copy-Item "release\*.dll" -Destination "$(RELEASE_FOLDER)" + +# Compila + $(CXX) $(APP_SOURCES) $(INCLUDES) -DRELEASE_BUILD $(CXXFLAGS) $(LDFLAGS) -o "$(WIN_RELEASE_FILE).exe" + strip -s -R .comment -R .gnu.version "$(WIN_RELEASE_FILE).exe" --strip-unneeded + +# Crea el fichero .zip + powershell if (Test-Path "$(WINDOWS_RELEASE)") {Remove-Item "$(WINDOWS_RELEASE)"} + powershell Compress-Archive -Path "$(RELEASE_FOLDER)"/* -DestinationPath "$(WINDOWS_RELEASE)" + @echo Release creado: $(WINDOWS_RELEASE) + +# Elimina la carpeta temporal 'RELEASE_FOLDER' + powershell if (Test-Path "$(RELEASE_FOLDER)") {Remove-Item "$(RELEASE_FOLDER)" -Recurse -Force} + +macos: + @echo "Compilando para macOS: $(TARGET_NAME)" + $(CXX) $(APP_SOURCES) $(INCLUDES) $(CXXFLAGS) $(LDFLAGS) -o "$(TARGET_FILE)" + +macos_debug: + @echo "Compilando version debug para macOS: $(TARGET_NAME)_debug" + $(CXX) $(APP_SOURCES) $(INCLUDES) -DDEBUG $(CXXFLAGS_DEBUG) $(LDFLAGS) -o "$(TARGET_FILE)_debug" + +macos_release: + @echo "Creando release para macOS - Version: $(VERSION)" + +# Verificar e instalar create-dmg si es necesario + @which create-dmg > /dev/null || (echo "Instalando create-dmg..." && brew install create-dmg) + +# Elimina datos de compilaciones anteriores + $(RMDIR) "$(RELEASE_FOLDER)" + $(RMFILE) tmp.dmg + $(RMFILE) "$(MACOS_APPLE_SILICON_RELEASE)" + +# Crea la carpeta temporal para hacer el trabajo y las carpetas obligatorias para crear una app de macos + $(MKDIR) "$(RELEASE_FOLDER)/$(APP_NAME).app/Contents/MacOS" + $(MKDIR) "$(RELEASE_FOLDER)/$(APP_NAME).app/Contents/Resources" + +# Copia carpetas y ficheros + cp -R shaders "$(RELEASE_FOLDER)/$(APP_NAME).app/Contents/Resources" + cp LICENSE "$(RELEASE_FOLDER)" + cp README.md "$(RELEASE_FOLDER)" + +# Compila la versión para procesadores Apple Silicon + $(CXX) $(APP_SOURCES) $(INCLUDES) -DMACOS_BUNDLE -DRELEASE_BUILD $(CXXFLAGS) $(LDFLAGS) -o "$(RELEASE_FOLDER)/$(APP_NAME).app/Contents/MacOS/$(TARGET_NAME)" -target arm64-apple-macos11 + +# Firma la aplicación + codesign --deep --force --sign - --timestamp=none "$(RELEASE_FOLDER)/$(APP_NAME).app" + +# Empaqueta el .dmg de la versión Apple Silicon con create-dmg + @echo "Creando DMG Apple Silicon con iconos de 96x96..." + create-dmg \ + --volname "$(APP_NAME)" \ + --window-pos 200 120 \ + --window-size 720 300 \ + --icon-size 96 \ + --text-size 12 \ + --icon "$(APP_NAME).app" 278 102 \ + --icon "LICENSE" 441 102 \ + --icon "README.md" 604 102 \ + --app-drop-link 115 102 \ + --hide-extension "$(APP_NAME).app" \ + "$(MACOS_APPLE_SILICON_RELEASE)" \ + "$(RELEASE_FOLDER)" || true + @echo "Release Apple Silicon creado: $(MACOS_APPLE_SILICON_RELEASE)" + +# Elimina las carpetas temporales + $(RMDIR) "$(RELEASE_FOLDER)" + +linux: + @echo "Compilando para Linux: $(TARGET_NAME)" + $(CXX) $(APP_SOURCES) $(INCLUDES) $(CXXFLAGS) $(LDFLAGS) -o "$(TARGET_FILE)" + strip -s -R .comment -R .gnu.version "$(TARGET_FILE)" --strip-unneeded + +linux_debug: + @echo "Compilando version debug para Linux: $(TARGET_NAME)_debug" + $(CXX) $(APP_SOURCES) $(INCLUDES) -DDEBUG $(CXXFLAGS_DEBUG) $(LDFLAGS) -o "$(TARGET_FILE)_debug" + +linux_release: + @echo "Creando release para Linux - Version: $(VERSION)" +# Elimina carpetas previas + $(RMDIR) "$(RELEASE_FOLDER)" + +# Crea la carpeta temporal para realizar el lanzamiento + $(MKDIR) "$(RELEASE_FOLDER)" + +# Copia ficheros + cp -R shaders "$(RELEASE_FOLDER)" + cp LICENSE "$(RELEASE_FOLDER)" + cp README.md "$(RELEASE_FOLDER)" + +# Compila + $(CXX) $(APP_SOURCES) $(INCLUDES) -DRELEASE_BUILD $(CXXFLAGS) $(LDFLAGS) -o "$(RELEASE_FOLDER)/$(TARGET_NAME)" + strip -s -R .comment -R .gnu.version "$(RELEASE_FOLDER)/$(TARGET_NAME)" --strip-unneeded + +# Empaqueta ficheros + $(RMFILE) "$(LINUX_RELEASE)" + tar -czvf "$(LINUX_RELEASE)" -C "$(RELEASE_FOLDER)" . + @echo "Release creado: $(LINUX_RELEASE)" + +# Elimina la carpeta temporal + $(RMDIR) "$(RELEASE_FOLDER)" + +# Regla para mostrar la versión actual +show_version: + @echo "Version actual: $(VERSION)" + +# Regla de ayuda +help: + @echo "Makefile para Shadertoy" + @echo "Comandos disponibles:" + @echo " windows - Compilar para Windows" + @echo " windows_debug - Compilar debug para Windows" + @echo " windows_release - Crear release completo para Windows" + @echo " linux - Compilar para Linux" + @echo " linux_debug - Compilar debug para Linux" + @echo " linux_release - Crear release completo para Linux" + @echo " macos - Compilar para macOS" + @echo " macos_debug - Compilar debug para macOS" + @echo " macos_release - Crear release completo para macOS" + @echo " show_version - Mostrar version actual ($(VERSION))" + @echo " help - Mostrar esta ayuda" + +.PHONY: windows windows_debug windows_release macos macos_debug macos_release linux linux_debug linux_release show_version help + +FORCE: