cmake_minimum_required(VERSION 3.16)
project(critterfolio LANGUAGES CXX)

set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

find_package(PkgConfig REQUIRED)
find_package(Freetype REQUIRED)
find_package(Lua REQUIRED)
find_package(SDL3 CONFIG REQUIRED)
find_package(SDL3_image CONFIG REQUIRED)
find_package(SQLiteCpp REQUIRED)
find_package(toml11 CONFIG REQUIRED)

pkg_check_modules(LUNASVG REQUIRED IMPORTED_TARGET lunasvg)
add_library(lunasvg::lunasvg ALIAS PkgConfig::LUNASVG)

find_package(RmlUi CONFIG REQUIRED)

add_library(rmlui_backend STATIC
  vendor/rmlui_backend/RmlUi_Backend_SDL_SDLrenderer.cpp
  vendor/rmlui_backend/RmlUi_Platform_SDL.cpp
  vendor/rmlui_backend/RmlUi_Renderer_SDL.cpp
)

target_include_directories(rmlui_backend PUBLIC
  vendor/rmlui_backend
)

target_compile_definitions(rmlui_backend PUBLIC
  RMLUI_SDL_VERSION_MAJOR=3
)

target_link_libraries(rmlui_backend PUBLIC
  RmlUi::RmlUi
  SDL3::SDL3
  SDL3_image::SDL3_image
  Freetype::Freetype
)

add_executable(${PROJECT_NAME}
  src/main.cpp
  src/database.cpp
  src/ui.cpp
  src/image_utils.cpp
)

target_include_directories(${PROJECT_NAME} PRIVATE
  src
  ${FREETYPE_INCLUDE_DIRS}
)

target_link_libraries(${PROJECT_NAME} PRIVATE
  rmlui_backend
  RmlUi::RmlUi
  RmlUi::Debugger
  RmlUi::Lua
  ${LUA_LIBRARIES}
  Freetype::Freetype
  lunasvg::lunasvg
  toml11::toml11
  SQLiteCpp
)

install(TARGETS ${PROJECT_NAME} DESTINATION bin)
install(DIRECTORY assets DESTINATION bin)

target_compile_definitions(${PROJECT_NAME} PRIVATE
  ASSETS_DIR="${CMAKE_SOURCE_DIR}/bin/assets"
)
