# SPDX-License-Identifier: GPL-3.0-or-later
add_library(realmrun_core STATIC
    error.c
    vfs.c
    pcx.c
    bmp.c
    pal.c
    records.c
    gamedata.c
    sage_res.c
    wav.c
    ogg.c
    rul.c
    rng.c
    rules.c
    sha256.c
    manifest.c
    seats.c
    seat_overlay.c
    touch.c
    input_backends.c
    controller.c
    mapper.c
    mixer.c
    music.c
    movie.c
    movie_audio.c
    movie_libav.c
    redraw.c
    map_scroll.c
    viewport.c
    probe.c
    scenario.c
    campaign.c
    campaign_game.c
    map_render.c
    frontend_session.c
    stack.c
    movement.c
    fog.c
    city.c
    game.c
    session.c
    ai.c
    savegame.c
    combat.c
    combat_effects.c
    hero.c
    item.c
    spell.c
    ruin.c
    quest.c
    codepatch.c
    codepatch_units.c
    codepatch_misc.c
    diplomacy.c
    diplo_game.c
    diplo_bribe.c
    ruin_search.c
    preset.c
    preset_apply.c
)
target_include_directories(realmrun_core PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
target_compile_options(realmrun_core PRIVATE -Wall -Wextra -Werror)
realmrun_apply_tune(realmrun_core)

# touch.c uses the C math library.
target_link_libraries(realmrun_core PUBLIC m)
target_link_libraries(realmrun_core PUBLIC ${CMAKE_DL_LIBS})
if(REALMRUN_MOVIE_LIBAV)
    target_compile_definitions(realmrun_core PRIVATE REALMRUN_HAVE_LIBAV_HEADERS)
    target_include_directories(realmrun_core SYSTEM PRIVATE
        ${REALMRUN_LIBAV_HEADER_PATH} ${MOVIE_LIBAV_INCLUDE_DIRS})
endif()

# OGG music (music.c): link the system libvorbisfile when the root found it
# (D-020 proposed) and compile the real decoder in; otherwise music.c stays a
# graceful stub. PUBLIC so the dependency reaches whoever links realmrun_core.
if(VORBISFILE_FOUND)
    target_compile_definitions(realmrun_core PRIVATE REALMRUN_HAVE_VORBIS)
    target_link_libraries(realmrun_core PUBLIC PkgConfig::VORBISFILE)
endif()

if(REALMRUN_SANITIZE)
    target_compile_options(realmrun_core PUBLIC -fsanitize=address,undefined -fno-omit-frame-pointer -g)
    target_link_options(realmrun_core PUBLIC -fsanitize=address,undefined)
endif()
