cmake_minimum_required(VERSION 3.15)
project(FxgbTurbo405 LANGUAGES C)
include(GenerateG1A)
find_package(Gint 2.9 REQUIRED)
option(FXGB_SAFE_RAM "Use smaller ROM cache to preserve heap memory" OFF)
add_executable(fxgbt405 src/main.c src/turbo_rom.c src/gb_core.c src/gb_video.c)
target_compile_definitions(fxgbt405 PRIVATE FXGB_TURBO_FAST=1 FXGB_FAST_HALT=1)
if(FXGB_SAFE_RAM)
    target_compile_definitions(fxgbt405 PRIVATE FXGB_TURBO_SAFE_RAM=1)
endif()
target_compile_options(fxgbt405 PRIVATE -O3 -fomit-frame-pointer -Wall -Wextra)
target_link_libraries(fxgbt405 Gint::Gint)
# LTO can inline hot paths across the CPU, ROM and LCD translation units.
# Probe before enabling: if this cross-toolchain does not support it, a
# standard -O3 binary will still be built.
option(FXGB_ENABLE_LTO "Use link-time optimization when supported" ON)
if(FXGB_ENABLE_LTO)
    include(CheckIPOSupported)
    check_ipo_supported(RESULT fxgb_ipo_ok OUTPUT fxgb_ipo_log LANGUAGES C)
    if(fxgb_ipo_ok)
        set_property(TARGET fxgbt405 PROPERTY INTERPROCEDURAL_OPTIMIZATION TRUE)
    else()
        message(STATUS "LTO unavailable: using regular -O3 compilation")
    endif()
endif()
generate_g1a(TARGET fxgbt405 OUTPUT "FXGBT405.g1a"
    NAME "FXGBT405" ICON assets/icon.png)
