set(ARCHEUS_STD_SDL2_WINDOW_SOURCES
    packages/graphics/sdl/window.c
    packages/graphics/sdl/renderer.c
)

set(ARCHEUS_STD_SDL2_INPUT_SOURCES
    packages/input/sdl/input.c
    packages/input/sdl/keyboard.c
    packages/input/sdl/mouse.c

    #TODO: remove this
    packages/audio/sdl/config.c
)

set(ARCHEUS_STD_SDL2_GRAPHICS_SOURCES
    packages/graphics/sdl/circle.c
    packages/graphics/sdl/config.c
    packages/graphics/sdl/line.c
    packages/graphics/sdl/obround.c
    packages/graphics/sdl/rectangle.c
    packages/graphics/sdl/sprite.c
    packages/graphics/sdl/spritesheet.c
    packages/graphics/sdl/text.c
)

function(sdl2_check_and_init_needed _ARCHEUS_STD_SOURCES _ARCHEUS_STD_INCLUDE_DIRECTORIES _ARCHEUS_STD_LINK_LIBRARIES ARCHEUS_STD_WINDOW_BACKEND ARCHEUS_STD_INPUT_BACKEND ARCHEUS_STD_GRAPHICS_BACKEND)
    #if no backend uses sdl return
    if(NOT ${ARCHEUS_STD_WINDOW_BACKEND} STREQUAL "SDL2" AND NOT ${ARCHEUS_STD_INPUT_BACKEND} STREQUAL "SDL2" AND NOT ${ARCHEUS_STD_GRAPHICS_BACKEND} STREQUAL "SDL2")
        return()
    endif()

    #get needed libraries for backends
    find_package(SDL2 REQUIRED)

    #add to include directories
    list(APPEND ${_ARCHEUS_STD_INCLUDE_DIRECTORIES}
        PRIVATE ${SDL2_INCLUDE_DIRS}
    )

    #add to link libraries
    list(APPEND ${_ARCHEUS_STD_LINK_LIBRARIES}
        PUBLIC ${SDL2_LIBRARIES}
    )

    #add matching files for the selected backends
    if(${ARCHEUS_STD_WINDOW_BACKEND} STREQUAL "SDL2")
        list(APPEND ${_ARCHEUS_STD_SOURCES} ${ARCHEUS_STD_SDL2_WINDOW_SOURCES})
    endif()

    if(${ARCHEUS_STD_INPUT_BACKEND} STREQUAL "SDL2")
        #TODO: remove this
        find_package(SDL2_mixer REQUIRED)

        list(APPEND ${_ARCHEUS_STD_SOURCES} ${ARCHEUS_STD_SDL2_INPUT_SOURCES})

        #TODO: remove this
        list(APPEND ${_ARCHEUS_STD_LINK_LIBRARIES}
            PUBLIC SDL2_mixer::SDL2_mixer
        )
    endif()

    if(${ARCHEUS_STD_GRAPHICS_BACKEND} STREQUAL "SDL2")
        find_package(SDL2_image REQUIRED)
        find_package(SDL2_ttf REQUIRED)

        list(APPEND ${_ARCHEUS_STD_SOURCES} ${ARCHEUS_STD_SDL2_GRAPHICS_SOURCES})

        #add to include directories
        list(APPEND ${_ARCHEUS_STD_INCLUDE_DIRECTORIES}
            PRIVATE ${SDL2IMAGE_INCLUDE_DIRS}
        )

        #add to link libraries
        list(APPEND ${_ARCHEUS_STD_LINK_LIBRARIES}
            PUBLIC SDL2_image::SDL2_image
            PUBLIC SDL2_ttf::SDL2_ttf
        )
    endif()

    set(${_ARCHEUS_STD_SOURCES} ${${_ARCHEUS_STD_SOURCES}} PARENT_SCOPE)
    set(${_ARCHEUS_STD_INCLUDE_DIRECTORIES} ${${_ARCHEUS_STD_INCLUDE_DIRECTORIES}} PARENT_SCOPE)
    set(${_ARCHEUS_STD_LINK_LIBRARIES} ${${_ARCHEUS_STD_LINK_LIBRARIES}} PARENT_SCOPE)
endfunction()
