# Platform/UI-glue layer: config, input, SDL backend, palette, state save.
# Static library shared by the binary and the test suite.  SDL3, the
# core/minizip libs and the KAT_DATADIR define are PUBLIC so consumers (incl.
# tests) inherit them automatically.
add_library(kat_interface STATIC
    atari_ntsc.c
    input.c
    katconfig.c
    logger.c
    md5.c
    media_if.c
    palette.c
    sdl_if.c
    sha1.c
    shader_bundle.c
    shader_gpu.c
    states.c
    toml.c
    util.c
    )

# Shaders render through SDL_GPU bundles, so desktop builds no longer link GL.
# Android still renders through GLES (+ EGL), so those libs must be present.
if(ANDROID)
    set(_kat_gl GLESv2 EGL)
else()
    set(_kat_gl "")
endif()

target_include_directories(kat_interface PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
target_link_libraries(kat_interface PUBLIC
    kat_core
    kat_minizip
    SDL3::SDL3
    SDL3_image::SDL3_image
    ${_kat_gl}
    m
    $<$<BOOL:${CURL_FOUND}>:CURL::libcurl>
    $<$<BOOL:${WIN32}>:winhttp>
    )

if(APPLE)
    # util.c uses CFBundle/CFURL to find .app bundle resources on macOS.
    # Keep the framework on kat_interface so tests inherit it too.
    target_link_libraries(kat_interface PUBLIC "-framework CoreFoundation")
endif()

# Runtime resource lookups need both the install seed dir and the source tree
# as a local-development fallback.
target_compile_definitions(kat_interface PUBLIC
    KAT_DATADIR="${KAT_DATADIR}"
    KAT_MANUAL_PDF_NAME="${KAT_MANUAL_PDF_NAME}"
    KAT_SOURCE_DIR="${CMAKE_SOURCE_DIR}")
