cmake_minimum_required(VERSION 3.28 FATAL_ERROR)

if (EXISTS "${CMAKE_CURRENT_BINARY_DIR}/cmake_checks_cache.txt")
    FILE(REMOVE "${CMAKE_CURRENT_BINARY_DIR}/cmake_checks_cache.txt")
endif()

if ("${PLATFORM}" STREQUAL "OS64" OR "${PLATFORM}" STREQUAL "OS64COMBINED")
    set(ENABLE_ARC OFF)
    set(DEPLOYMENT_TARGET "14.0")
    set(CMAKE_TOOLCHAIN_FILE "${CMAKE_CURRENT_SOURCE_DIR}/cmake/toolchain/ios.toolchain.cmake")
endif ()

set(CMAKE_POLICY_DEFAULT_CMP0077 NEW)
set(CMAKE_CXX_STANDARD 20)

set_property(GLOBAL PROPERTY USE_FOLDERS ON)

if(LINUX)
    find_package(ECM REQUIRED NO_MODULE)
    set(CMAKE_MODULE_PATH ${ECM_MODULE_PATH})
endif()
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake/cmake-checks-cache/CMakeChecksCache"
                                            "${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules"
                                            "${CMAKE_CURRENT_SOURCE_DIR}/cmake/functions")

include(VarsFromFile)
include(SetCompilerSettings)
include(SetupVulkan)
include(Filter)
include(AppleHelper)
include(SetShaderDependency)
add_compile_definitions(NOMINMAX)

set(DEPENDENCY_MIRROR_FILE "DependencyMirrors.txt" CACHE STRING "Dependency mirror")
VarsFromFile("${DEPENDENCY_MIRROR_FILE}") # Load mirror list (for CICD)

project (OpenVulkano VERSION 1.0 LANGUAGES C CXX)

SetOptimisationSettings()

# ------------------------- CMAKE OPTIONS -------------------------
option(TRACY_ENABLE "Enable Tracy Profiler" OFF)
option(ENABLE_ASSIMP "If assimp should be used" ON)
option(ENABLE_CURL "If curl should be used" ON)
option(ENABLE_KTX "If ktx images should be supported" ON)
option(ENABLE_TEST "Enable testing" ON)
option(ENABLE_EXAMPLE "Enable examples" ON)
option(ENABLE_MSDF "Enable msdf library" ON)
option(ENABLE_SHADERC "Enable runtime shader compiler" OFF)
# -----------------------------------------------------------------

if (IOS)
    set(DEPLOYMENT_TARGET "14.0")
    set_property(GLOBAL PROPERTY XCODE_ATTRIBUTE_IPHONEOS_DEPLOYMENT_TARGET ${DEPLOYMENT_TARGET})
    set(CMAKE_OSX_DEPLOYMENT_TARGET ${DEPLOYMENT_TARGET})
    set(MACOSX_DEPLOYMENT_TARGET ${DEPLOYMENT_TARGET})
endif ()

# First generate 3rdParty Libraries
add_subdirectory(3rdParty)

# Then generate the OpenVulkano Library
add_subdirectory(openVulkanoCpp)
LinkTinyUSDZ(openVulkanoCpp)

if(ENABLE_TEST AND NOT IOS)
    enable_testing()
    add_subdirectory(tests)
endif()

# Finally generate the tests and examples
if(ENABLE_EXAMPLE)
	add_subdirectory(examples)
	set_property(DIRECTORY ${CMAKE_SOURCE_DIR} PROPERTY VS_STARTUP_PROJECT OpenVulkano_Examples)
endif()
