archeus/cmake/archeus_sdl2.cmake
2025-02-11 00:57:39 -07:00

88 lines
2.7 KiB
CMake

set(ARCHEUS_SDL2_WINDOW_SOURCES
packages/graphics/sdl/window.c
packages/graphics/sdl/renderer.c
)
set(ARCHEUS_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_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_SOURCES _ARCHEUS_INCLUDE_DIRECTORIES _ARCHEUS_LINK_LIBRARIES ARCHEUS_WINDOW_BACKEND ARCHEUS_INPUT_BACKEND ARCHEUS_GRAPHICS_BACKEND)
#if no backend uses sdl return
if(NOT ${ARCHEUS_WINDOW_BACKEND} STREQUAL "SDL2" AND NOT ${ARCHEUS_INPUT_BACKEND} STREQUAL "SDL2" AND NOT ${ARCHEUS_GRAPHICS_BACKEND} STREQUAL "SDL2")
return()
endif()
#get needed libraries for backends
find_package(SDL2 REQUIRED)
#add to include directories
list(APPEND ${_ARCHEUS_INCLUDE_DIRECTORIES}
PRIVATE ${SDL2_INCLUDE_DIRS}
)
#add to link libraries
list(APPEND ${_ARCHEUS_LINK_LIBRARIES}
PUBLIC ${SDL2_LIBRARIES}
)
#add matching files for the selected backends
if(${ARCHEUS_WINDOW_BACKEND} STREQUAL "SDL2")
list(APPEND ${_ARCHEUS_SOURCES} ${ARCHEUS_SDL2_WINDOW_SOURCES})
endif()
if(${ARCHEUS_INPUT_BACKEND} STREQUAL "SDL2")
#TODO: remove this
find_package(SDL2_mixer REQUIRED)
list(APPEND ${_ARCHEUS_SOURCES} ${ARCHEUS_SDL2_INPUT_SOURCES})
#TODO: remove this
list(APPEND ${_ARCHEUS_LINK_LIBRARIES}
PUBLIC SDL2_mixer::SDL2_mixer
)
endif()
if(${ARCHEUS_GRAPHICS_BACKEND} STREQUAL "SDL2")
find_package(SDL2_image REQUIRED)
find_package(SDL2_ttf REQUIRED)
find_package(PkgConfig REQUIRED)
pkg_check_modules(SDL2_GFX REQUIRED SDL2_gfx)
list(APPEND ${_ARCHEUS_SOURCES} ${ARCHEUS_SDL2_GRAPHICS_SOURCES})
#add to include directories
list(APPEND ${_ARCHEUS_INCLUDE_DIRECTORIES}
PRIVATE ${SDL2IMAGE_INCLUDE_DIRS}
PRIVATE ${SDL2_GFX_INCLUDE_DIRS}
)
#add to link libraries
list(APPEND ${_ARCHEUS_LINK_LIBRARIES}
PUBLIC SDL2_image::SDL2_image
PUBLIC SDL2_ttf::SDL2_ttf
PUBLIC ${SDL2_GFX_LIBRARIES}
)
endif()
set(${_ARCHEUS_SOURCES} ${${_ARCHEUS_SOURCES}} PARENT_SCOPE)
set(${_ARCHEUS_INCLUDE_DIRECTORIES} ${${_ARCHEUS_INCLUDE_DIRECTORIES}} PARENT_SCOPE)
set(${_ARCHEUS_LINK_LIBRARIES} ${${_ARCHEUS_LINK_LIBRARIES}} PARENT_SCOPE)
endfunction()