# 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.
add_subdirectory(${DAWN_BUILDING})

# Validate game project includes the target name
if(NOT DEFINED DAWN_TARGET_NAME)
  message(FATAL_ERROR "You need to define a DAWN_TARGET_NAME")
endif()

# Add in base library
add_subdirectory(dawn)

# Compile entry targets
if(DAWN_TARGET_WIN32)
  add_subdirectory(dawnwin32)
elseif(DAWN_TARGET_LINUX64)
  add_subdirectory(dawnlinux64)
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()

add_subdirectory(dawnopenal)

# Late definitions, used by tools
if(NOT DAWN_TARGET_DEPENDENCIES_LAST)
  # message(FATAL_ERROR "List empty")
else()
  add_dependencies(${DAWN_TARGET_NAME} ${DAWN_TARGET_DEPENDENCIES_LAST})
endif()