# Copyright (c) 2025 Dominic Masters
#
# This software is released under the MIT License.
# https://opensource.org/licenses/MIT

# Required Libraries
if(NOT cglm_FOUND)
  find_package(cglm REQUIRED)
  target_link_libraries(${DUSK_LIBRARY_TARGET_NAME} PUBLIC cglm)
endif()

if(NOT libzip_FOUND)
  find_package(libzip REQUIRED)
  target_link_libraries(${DUSK_LIBRARY_TARGET_NAME} PUBLIC zip)
endif()

if(NOT stb_image_FOUND)
  find_package(stb REQUIRED)
  if(STB_IMAGE_FOUND)
    target_link_libraries(${DUSK_LIBRARY_TARGET_NAME} PUBLIC stb_image)
  else()
    message(FATAL_ERROR "stb_image not found. Please ensure stb is correctly fetched.")
  endif()
endif()

if(NOT yyjson_FOUND)
  find_package(yyjson REQUIRED)
  if(yyjson_FOUND)
    target_link_libraries(${DUSK_LIBRARY_TARGET_NAME} PUBLIC yyjson::yyjson)
  else()
    message(FATAL_ERROR "yyjson not found. Please ensure yyjson is correctly fetched.")
  endif()
endif()

if(NOT Lua_FOUND)
  find_package(Lua REQUIRED)
  if(Lua_FOUND AND NOT TARGET Lua::Lua)
    add_library(Lua::Lua INTERFACE IMPORTED)
    set_target_properties(
      Lua::Lua
      PROPERTIES
        INTERFACE_INCLUDE_DIRECTORIES "${LUA_INCLUDE_DIR}"
        INTERFACE_LINK_LIBRARIES "${LUA_LIBRARIES}"
    )
  endif()
  target_link_libraries(${DUSK_LIBRARY_TARGET_NAME} PUBLIC Lua::Lua)
endif()

if(NOT jerryscript_FOUND)
  find_package(jerryscript REQUIRED)
  target_link_libraries(${DUSK_LIBRARY_TARGET_NAME} PUBLIC
    jerryscript::core
    jerryscript::ext
    jerryscript::port
  )
endif()

# Includes
target_include_directories(${DUSK_LIBRARY_TARGET_NAME}
  PUBLIC
    ${CMAKE_CURRENT_LIST_DIR}
)

# Main Binary Source
target_sources(${DUSK_BINARY_TARGET_NAME}
  PUBLIC
    main.c
)

# Subdirs
add_subdirectory(assert)
add_subdirectory(asset)
add_subdirectory(console)
add_subdirectory(display)
add_subdirectory(log)
add_subdirectory(engine)
add_subdirectory(entity)
add_subdirectory(error)
add_subdirectory(event)
add_subdirectory(input)
add_subdirectory(locale)
add_subdirectory(physics)
add_subdirectory(scene)
add_subdirectory(script)
add_subdirectory(system)
add_subdirectory(time)
add_subdirectory(ui)
add_subdirectory(network)
add_subdirectory(util)
add_subdirectory(thread)