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

# Custom variables
set(
  DAWN_TARGET_DEPENDENCIES_LAST
  CACHE INTERNAL ${DAWN_CACHE_TARGET}
)

# Include shared libs
add_subdirectory(dawnshared)

# Include tools
add_subdirectory(dawntools)

# Change what we are building. Pulled from the cmake/targets dir.
if(DEFINED DAWN_BUILDING)
  add_subdirectory(${DAWN_BUILDING})
endif()

# Validate game project includes the target name
if(DEFINED DAWN_TARGET_NAME)
  # Add in base library
  add_subdirectory(dawn)

  # Compile entry targets
  if(DAWN_TARGET_WIN32)
    add_subdirectory(dawnwin32)
  elseif(DAWN_TARGET_LINUX64)
    add_subdirectory(dawnlinux64)
  elseif(DAWN_TARGET_VITA)
    add_subdirectory(dawnvita)
  else()
    message(FATAL_ERROR "You need to define an entry target")
  endif()

  # Host Libraries
  target_link_libraries(${DAWN_TARGET_NAME}
    PUBLIC
      ${DAWN_BUILD_HOST_LIBS}
  )

  # Compile support targets
  if(DAWN_TARGET_GLFW)
    add_subdirectory(dawnglfw)
    add_subdirectory(dawnopengl)
  endif()

  if(DAWN_TARGET_SDL2)
    add_subdirectory(dawnsdl2)
    add_subdirectory(dawnopengl)
  endif()

  if(DAWN_TARGET_VITA)
    add_subdirectory(dawnopengl)
  endif()

  if(DAWN_TARGET_OPENAL)
    add_subdirectory(dawnopenal)
  endif()

  # Late definitions, used by tools
  if(NOT DAWN_TARGET_DEPENDENCIES_LAST)
  else()
    add_dependencies(${DAWN_TARGET_NAME} ${DAWN_TARGET_DEPENDENCIES_LAST})
  endif()
endif()