set(inc "inc")
set(privinc "privinc")
set(deps util)

if(PS1_BUILD)
    set(src ${src}
        "ps1/src/4line.c"
        "ps1/src/env.c"
        "ps1/src/heap.c"
        "ps1/src/init.c"
        "ps1/src/rect.c"
        "ps1/src/sort.c"
        "ps1/src/sprite.c"
        "ps1/src/quad.c")
    set(inc ${inc} "ps1/inc")
    set(privinc ${privinc} "ps1/privinc")
    set(privdeps ${privdeps} system PSXSDK::PSXSDK)
elseif(SDL1_2_BUILD)
    set(inc ${inc} "sdl-1.2/inc")
    set(privinc ${privinc} "sdl-1.2/privinc")
    set(src ${src}
        "sdl-1.2/src/env.c"
        "sdl-1.2/src/line.c"
        "sdl-1.2/src/rect.c"
        "sdl-1.2/src/sprite.c"
        "sdl-1.2/src/quad.c")
    set(deps ${deps} SDL::SDL)
    set(privdeps ${privdeps} header SDL::SDL_gfx)
elseif(ESP32_BUILD)
    set(inc ${inc} "esp32/inc")
    set(privinc ${privinc} "esp32/privinc")
    set(src ${src}
        "esp32/src/env.c"
        "esp32/src/line.c"
        "esp32/src/rect.c"
        "esp32/src/sprite.c"
        "esp32/src/quad.c")
endif()

add_library(gfx ${src})
target_include_directories(gfx PUBLIC ${inc})
target_include_directories(gfx PRIVATE ${privinc})
target_link_libraries(gfx PUBLIC ${deps} PRIVATE ${privdeps})

if(PS1_BUILD)
    set(modes VMODE_PAL VMODE_NTSC)

    if(VIDEO_MODE)
        if(NOT "${VIDEO_MODE}" IN_LIST modes)
            message(FATAL_ERROR "Invalid video mode ${VIDEO_MODE}. Available options:\n"
                "${modes}\n"
                "Run CMake again using one of the available video modes e.g.: cmake .. -DVIDEO_MODE=VMODE_PAL")
        endif()

        target_compile_definitions(gfx PRIVATE VIDEO_MODE=${VIDEO_MODE})
    else()
        message(FATAL_ERROR "Please define video mode. Available options:\n"
            "${modes}\n"
            "Run CMake again using one of the available video modes e.g.: cmake .. -DVIDEO_MODE=VMODE_PAL")
    endif()
endif()
