# SPDX-License-Identifier: GPL-3.0-or-later
# SDL2 front-end (T-M2-01 part B). Only added when SDL2 is found; the core lib
# and its tests never depend on it.
add_library(realmrun_platform STATIC
    sdl_loop.c
    sdl_preset.c
)
target_include_directories(realmrun_platform PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
target_link_libraries(realmrun_platform PUBLIC realmrun_core realmrun_ui SDL2::SDL2)
target_compile_options(realmrun_platform PRIVATE -Wall -Wextra)
# Instrument this lib's objects under ASan/UBSan; the `realmrun` exe that links
# it carries the sanitize link flags + its own check (see top CMakeLists.txt).
if(REALMRUN_SANITIZE)
    target_compile_options(realmrun_platform PRIVATE
        -fsanitize=address,undefined -fno-omit-frame-pointer -g)
endif()

# Optional SDL_ttf font backend (T-M3-04a). Only built when SDL2_ttf was found
# (REALMRUN_HAVE_SDL2_TTF, set in the top CMakeLists). Links realmrun_ui for the
# realmrun_font vtable it implements; kept out of CI since the box has no
# SDL2_ttf. The pure-C fixed-cell fallback in src/ui/font.c is always built.
if(REALMRUN_HAVE_SDL2_TTF)
    add_library(realmrun_font_sdl STATIC font_sdl_ttf.c)
    target_link_libraries(realmrun_font_sdl PUBLIC realmrun_ui PkgConfig::SDL2_TTF SDL2::SDL2)
    target_include_directories(realmrun_font_sdl PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
    target_compile_options(realmrun_font_sdl PRIVATE -Wall -Wextra -Werror)
    if(REALMRUN_SANITIZE)
        target_compile_options(realmrun_font_sdl PRIVATE
            -fsanitize=address,undefined -fno-omit-frame-pointer -g)
    endif()
endif()
