cmake_minimum_required(VERSION 3.25)

project(podium LANGUAGES C)

if(WIN32)
    enable_language(RC)
endif()

set(CMAKE_C_STANDARD 11)
set(CMAKE_C_STANDARD_REQUIRED ON)
set(CMAKE_C_EXTENSIONS OFF)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

option(ECHO_SANITIZE "Build host code with UndefinedBehaviorSanitizer" OFF)
option(ECHO_ADDRESS_SANITIZER "Build host code with AddressSanitizer" OFF)
option(ECHO_BUILD_SIM "Build the SDL2 simulator" ON)
option(ECHO_BUILD_TESTS "Build the host tests" ON)
option(ECHO_BUILD_DEVICE "Build the device firmware with cmake/arm-none-eabi.cmake" OFF)
option(ECHO_RELEASE "Leave the developer-only Diagnostics rows out of the build" OFF)
set(PODIUM_VERSION 4.5.7)
if(NOT PODIUM_VERSION MATCHES "^([1-4])\\.([0-9])\\.([0-9])$")
    message(FATAL_ERROR "PODIUM_VERSION must be d.d.d with major 1 to 4")
endif()
set(PODIUM_IMAGE_NAME "ECHOV${CMAKE_MATCH_1}${CMAKE_MATCH_2}${CMAKE_MATCH_3}.IMG")
if(PODIUM_IMAGE_NAME STRGREATER "ECHOV498.IMG")
    message(FATAL_ERROR "PODIUM_VERSION ${PODIUM_VERSION} is above 4.9.8, the highest update file stock scans")
endif()
option(ECHO_BOOT_TRACE "Show each start-up step on screen and skip the updater" OFF)
set(ECHO_PANEL_MADCTL 0x28 CACHE STRING "Memory access control byte of the full-size Echo panel (0x28, or 0x68 to mirror columns)")
set(ECHO_APP_RAM_BUDGET_BYTES 131072 CACHE STRING "Static RAM budget for src/ on the device")

include(cmake/project_options.cmake)

add_subdirectory(src)
add_subdirectory(platform/device/logic)

if(ECHO_BUILD_SIM)
    add_subdirectory(platform/sim)
endif()

if(ECHO_BUILD_DEVICE)
    add_subdirectory(platform/device)
endif()

if(ECHO_BUILD_TESTS)
    enable_testing()
    add_subdirectory(tests)
endif()
