modificat .gitignore

modificat CMakeLists.txt per a windows
afegit Makefile
This commit is contained in:
2025-03-24 09:36:22 +01:00
parent a49297527b
commit a14d7ceb0f
3 changed files with 52 additions and 48 deletions

14
.gitignore vendored
View File

@@ -89,20 +89,6 @@ $RECYCLE.BIN/
# Windows shortcuts
*.lnk
# ---> CMake
CMakeLists.txt.user
CMakeCache.txt
CMakeFiles
CMakeScripts
Testing
Makefile
cmake_install.cmake
install_manifest.txt
compile_commands.json
CTestTestfile.cmake
_deps
CMakeUserPresets.json
# ---> Linux
*~

View File

@@ -5,51 +5,35 @@ project(demo3_pixels_bouncing)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
# Opciones comunes de compilación
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Os")
# Buscar todos los archivos `.cpp` en la carpeta `source`
file(GLOB SOURCE_FILES source/*.cpp)
# Definir el ejecutable
set(EXECUTABLE demo3_pixels_bouncing)
# Buscar SDL3 automáticamente
find_package(SDL3 REQUIRED)
# Si no se encuentra SDL3, generar un error
if (NOT SDL3_FOUND)
message(FATAL_ERROR "SDL3 no encontrado. Por favor, verifica su instalación.")
endif()
# Archivos fuente
file(GLOB SOURCE_FILES source/*.cpp)
# Comprobar si se encontraron archivos fuente
if(NOT SOURCE_FILES)
message(FATAL_ERROR "No se encontraron archivos fuente en el directorio 'source/'. Verifica la ruta.")
endif()
# Nombre del ejecutable
set(EXECUTABLE_NAME demo3_pixels_bouncing)
# Detectar la plataforma y configuraciones específicas
# Detectar la plataforma y ajustar configuraciones específicas
if(WIN32)
set(PLATFORM windows)
set(LINK_LIBS ${SDL3_LIBRARIES} mingw32 ws2_32)
set(EXECUTABLE_EXTENSION ".exe")
set(EXE_EXT ".exe")
set(EXTRA_LIBS mingw32 ws2_32)
elseif(UNIX AND NOT APPLE)
set(PLATFORM linux)
set(LINK_LIBS ${SDL3_LIBRARIES})
set(EXECUTABLE_EXTENSION ".out")
set(EXE_EXT ".out")
set(EXTRA_LIBS "")
elseif(APPLE)
set(PLATFORM macos)
set(LINK_LIBS ${SDL3_LIBRARIES})
set(EXECUTABLE_EXTENSION ".out")
set(EXE_EXT ".out")
set(EXTRA_LIBS "")
endif()
# Incluir directorios de SDL3
include_directories(${SDL3_INCLUDE_DIRS})
# Añadir el ejecutable con todos los archivos fuente
add_executable(${EXECUTABLE}${EXE_EXT} ${SOURCE_FILES})
# Añadir el ejecutable
add_executable(${EXECUTABLE_NAME}${EXECUTABLE_EXTENSION} ${SOURCE_FILES})
# Enlazar las bibliotecas específicas y SDL3
target_link_libraries(${EXECUTABLE}${EXE_EXT} ${EXTRA_LIBS} SDL3::SDL3)
# Especificar la ubicación del ejecutable (en la raíz del proyecto)
set_target_properties(${EXECUTABLE_NAME}${EXECUTABLE_EXTENSION} PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR})
# Enlazar las bibliotecas necesarias
target_link_libraries(${EXECUTABLE_NAME}${EXECUTABLE_EXTENSION} ${LINK_LIBS})
# Colocar el ejecutable en la raíz del proyecto
set_target_properties(${EXECUTABLE}${EXE_EXT} PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR})

34
Makefile Normal file
View File

@@ -0,0 +1,34 @@
# Makefile sin espacios adicionales y con sintaxis minimalista
CXXFLAGS := -std=c++20 -Wall -Os -ffunction-sections -fdata-sections
LDFLAGS := -lSDL3
SOURCE := source/*.cpp
EXECUTABLE := demo3_pixels_bouncing
RM := rm -f
# Detectar plataforma
ifeq ($(OS),Windows_NT)
PLATFORM := windows
LDFLAGS += -lmingw32 -lws2_32
EXE_EXT := .exe
else
UNAME_S:=$(shell uname -s)
ifeq ($(UNAME_S),Linux)
PLATFORM := linux
EXE_EXT := .out
endif
ifeq ($(UNAME_S),Darwin)
PLATFORM := macos
EXE_EXT := .out
endif
endif
# Regla principal
all: $(EXECUTABLE)
# Compilar
$(EXECUTABLE):
$(CXX) $(SOURCE) $(CXXFLAGS) $(LDFLAGS) -o $(EXECUTABLE)$(EXE_EXT)
# Limpiar
clean:
$(RM) $(EXECUTABLE)*