# CMakeLists.txt

cmake_minimum_required(VERSION 3.10)
project(aee VERSION 1.00)

# Estándar de C++
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED True)

# Exportar comandos de compilación para herramientas de análisis
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

# --- LISTA EXPLÍCITA DE FUENTES ---
set(APP_SOURCES
    # Core - Motor "Jail"
    source/core/global_inputs.cpp
    source/core/jail_audio.cpp
    source/core/jdraw8.cpp
    source/core/jfile.cpp
    source/core/jgame.cpp
    source/core/jinput.cpp
    source/core/screen.cpp

    # Game
    source/game/options.cpp
    source/game/bola.cpp
    source/game/engendro.cpp
    source/game/info.cpp
    source/game/mapa.cpp
    source/game/marcador.cpp
    source/game/modulegame.cpp
    source/game/modulesequence.cpp
    source/game/momia.cpp
    source/game/prota.cpp
    source/game/sprite.cpp

    # Main
    source/main.cpp
)

# Configuración de SDL3
find_package(SDL3 REQUIRED CONFIG REQUIRED COMPONENTS SDL3)
message(STATUS "SDL3 encontrado: ${SDL3_INCLUDE_DIRS}")

# --- EJECUTABLE ---
add_executable(${PROJECT_NAME} ${APP_SOURCES})

# --- DIRECTORIOS DE INCLUSIÓN ---
target_include_directories(${PROJECT_NAME} PUBLIC
    "${CMAKE_SOURCE_DIR}/source"
)

# Enlazar SDL3
target_link_libraries(${PROJECT_NAME} PRIVATE SDL3::SDL3)

# --- FLAGS DE COMPILACIÓN ---
target_compile_options(${PROJECT_NAME} PRIVATE -Wall)
target_compile_options(${PROJECT_NAME} PRIVATE $<$<CONFIG:RELEASE>:-Os -ffunction-sections -fdata-sections>)

# --- CONFIGURACIÓN POR PLATAFORMA ---
if(WIN32)
    target_link_libraries(${PROJECT_NAME} PRIVATE mingw32)
endif()

# Ejecutable en la raíz del proyecto
set_target_properties(${PROJECT_NAME} PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR})

# --- CLANG-FORMAT TARGETS ---
find_program(CLANG_FORMAT_EXE NAMES clang-format)

# Recopilar todos los archivos fuente para formateo (excluir external/)
file(GLOB_RECURSE ALL_SOURCE_FILES
    "${CMAKE_SOURCE_DIR}/source/*.cpp"
    "${CMAKE_SOURCE_DIR}/source/*.hpp"
    "${CMAKE_SOURCE_DIR}/source/*.h"
)
list(FILTER ALL_SOURCE_FILES EXCLUDE REGEX ".*/external/.*")

if(CLANG_FORMAT_EXE)
    add_custom_target(format
        COMMAND ${CLANG_FORMAT_EXE}
            -i
            ${ALL_SOURCE_FILES}
        WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
        COMMENT "Running clang-format..."
    )

    add_custom_target(format-check
        COMMAND ${CLANG_FORMAT_EXE}
            --dry-run
            --Werror
            ${ALL_SOURCE_FILES}
        WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
        COMMENT "Checking clang-format..."
    )
else()
    message(STATUS "clang-format no encontrado - targets 'format' y 'format-check' no disponibles")
endif()
