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

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

# Platform variables
target_compile_definitions(${DAWN_TARGET_NAME}
  PUBLIC
    DAWN_ASSET_BUILD_PREFIX="../../assets/"
    DAWN_OPENGL_HLSL=true
)

set(DAWN_OPENGL_EXCLUDE_LIBRARIES true CACHE INTERNAL ${DAWN_CACHE_TARGET})

# Subdirs
add_subdirectory(host)
add_subdirectory(input)
add_subdirectory(time)

# Toolchain
include("$ENV{VITASDK}/share/vita.cmake" REQUIRED)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu11" CACHE INTERNAL ${DAWN_CACHE_TARGET})
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11" CACHE INTERNAL ${DAWN_CACHE_TARGET})
set(VITA_MKSFOEX_FLAGS "${VITA_MKSFOEX_FLAGS} -d PARENTAL_LEVEL=1" CACHE INTERNAL ${DAWN_CACHE_TARGET})

# Libraries
target_link_libraries(${DAWN_TARGET_NAME}
  PUBLIC
    m
    stdc++
    vitaGL
    mathneon
    vitashark
    kubridge_stub
    SceAppMgr_stub
    SceAudio_stub
    SceCtrl_stub
    SceCommonDialog_stub
    SceDisplay_stub
    SceKernelDmacMgr_stub
    SceGxm_stub
    SceShaccCg_stub
    SceSysmodule_stub
    ScePower_stub
    SceTouch_stub
    SceVshBridge_stub
    SceIofilemgr_stub
    SceShaccCgExt
    libtaihen_stub.a
)

# VPK Packaging
if(NOT DEFINED DAWN_VITA_APP_NAME)
message(FATAL_ERROR "Please define DAWN_VITA_APP_NAME in your target.")
endif()
if(NOT DEFINED DAWN_VITA_TITLEID)
  message(FATAL_ERROR "Please define DAWN_VITA_TITLEID in your target.")
endif()
if(NOT DEFINED DAWN_VITA_VERSION)
  message(FATAL_ERROR "Please define DAWN_VITA_VERSION in your target.")
endif()

# The Vita SDK actually assumes that the binary is in the same dir as the build,
# so we actually need to hijack this and point to a file instead.
vita_create_self(${DAWN_TARGET_NAME}.self ${DAWN_BUILD_BINARY})
vita_create_vpk(${DAWN_TARGET_NAME}.vpk ${DAWN_VITA_TITLEID} ${DAWN_TARGET_NAME}.self
  VERSION ${DAWN_VITA_VERSION}
  NAME ${DAWN_VITA_APP_NAME}
)