cmake_minimum_required(VERSION 3.18)
project(Re3D
        VERSION 1.0
        LANGUAGES CXX C
)


if (PROJECT_SOURCE_DIR STREQUAL PROJECT_BINARY_DIR)
    message(FATAL_ERROR "In-source builds are not allowed")
endif()

set(CMAKE_CXX_STANDARD 20)

set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake")

# Enable Package Managers
include(cmake/CPM.cmake)

file(GLOB_RECURSE HEADERS "include/*")
file(GLOB_RECURSE SOURCES "src/*")
file(GLOB_RECURSE ASSETS  "assets/*")

#Move all libraries to lib after building.
SET(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/lib")
SET(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/lib")

#TODO: Publish release

#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3")

CPMAddPackage(
        NAME ReWindow
        URL https://git.redacted.cc/Redacted/ReWindow/archive/Prerelease-2.zip
)

CPMAddPackage(
        NAME Event
        URL https://git.redacted.cc/josh/Event/archive/Release-6.zip
)

#Temporarily removed due to SystemD requirement.
#CPMAddPackage(
#        NAME ReHardwareID
#        URL https://git.redacted.cc/Redacted/ReHardwareID/archive/v1.1.zip
#)

CPMAddPackage(
        NAME J3ML
        URL https://git.redacted.cc/josh/j3ml/archive/Release-2.1.zip
)

CPMAddPackage(
        NAME JGL
        URL https://git.redacted.cc/josh/JGL/archive/Prerelease-14.zip
)

CPMAddPackage(
        NAME ReTexture
        URL https://git.redacted.cc/Redacted/ReTexture/archive/Prerelease-1.zip
)

CPMAddPackage(
        NAME UUID
        URL https://git.redacted.cc/Redacted/uuid/archive/v1.zip
)

CPMAddPackage(
        NAME glad
        URL https://git.redacted.cc/Redacted/glad/archive/v2.1ext_mt.zip
)

CPMAddPackage(
        NAME archive
        URL https://git.redacted.cc/Redacted/archive/archive/v1.0.zip
)

CPMAddPackage(
        NAME Collage
        URL https://git.redacted.cc/Redacted/Collage/archive/v0.4.zip
)

CPMAddPackage(
        NAME jlog
        URL https://git.redacted.cc/josh/jlog/archive/Prerelease-8.zip
)

add_library(Re3D SHARED ${SOURCES})

target_include_directories(Re3D PUBLIC
        ${PROJECT_SOURCE_DIR}/include
        ${jlog_SOURCE_DIR}/include
        ${JGL_SOURCE_DIR}/include
        ${ReWindow_SOURCE_DIR}/include
        #${ReHardwareID_SOURCE_DIR}/include
        ${J3ML_SOURCE_DIR}/include
        ${ReTexture_SOURCE_DIR}/include
        ${glad_SOURCE_DIR}/include
        ${UUID_SOURCE_DIR}/include
        ${archive_SOURCE_DIR}/include
        ${Collage_SOURCE_DIR}/include
        ${Event_SOURCE_DIR}/include
)

# Why god???
set_target_properties(Re3D PROPERTIES LINKER_LANGUAGE CXX)

find_package(OpenGL REQUIRED)

target_link_libraries(Re3D PUBLIC Event ReWindowLibrary ReTexture J3ML GL glad Collage JGL archive jlog)

include(src/demo/RuntimeTest/CMakeLists.txt)


