#########################################
#### CMake generator file for Niotso ####
cmake_minimum_required(VERSION 3.21)
project(Niotso)
set(CMAKE_ROOT_DIR "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
list(APPEND CMAKE_MODULE_PATH ${CMAKE_ROOT_DIR})

enable_language(ASM)

#########################################
#### Options
option(BUILD_SHARED_LIBS "Build using shared libraries" ON) # default cmake
option(NIOTSO_BUILD_EXAMPLES "Build the render demos" ON)
option(NIOTSO_BUILD_TOOLS "Build niotso tools" ON)

if(WIN32)
    set(DIST_NAME "windows" CACHE STRING "Output folder name for the _dist folder (no start or end slash)")
    set_property(GLOBAL PROPERTY USE_FOLDERS ON)
    if(BUILD_SHARED_LIBS)
        # TODO-jip: this is terrible for release
        set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON)
    endif()
elseif(APPLE)
    set(DIST_NAME "mac" CACHE STRING "Output folder name for the _dist folder (no start or end slash)")
elseif(UNIX)
    set(DIST_NAME "linux" CACHE STRING "Output folder name for the _dist folder (no start or end slash)")
else()
    set(DIST_NAME "unknown" CACHE STRING "Output folder name for the _dist folder (no start or end slash)")
endif()

set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}/_dist/${DIST_NAME}")
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}/_dist/${DIST_NAME}")
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}/_dist/${DIST_NAME}")

#########################################
#### Dependencies
add_subdirectory(deps)

#########################################
#### Project
add_subdirectory(niotso)

if(NIOTSO_BUILD_TOOLS)
    add_subdirectory(tools)
endif()

if(NIOTSO_BUILD_EXAMPLES)
    add_subdirectory(examples)
endif()

#########################################
#### Unset Options
unset(BUILD_SHARED_LIBS CACHE)
unset(NIOTSO_BUILD_EXAMPLES CACHE)
unset(NIOTSO_BUILD_TOOLS CACHE)