#
# project: mirage
#
cmake_minimum_required(VERSION 3.21)
project(mirage)

set(CMAKE_CXX_STANDARD 26)

if (MSVC)
    # MSVC编译器设置C++标准
    add_compile_options(/std:c++latest)
    # 设置utf-8编码
    add_compile_options(/utf-8)
endif ()
if (WIN32)
    # 定义Windows版本宏
    add_definitions(-DWIN32_LEAN_AND_MEAN)
    add_definitions(-DUNICODE -D_UNICODE)
endif ()


set(MIRAGE_USE_HDR OFF CACHE BOOL "Enable HDR format")
set(MIRAGE_HDR_FORMAT "SG_PIXELFORMAT_RGBA16F" CACHE STRING "Enable HDR format")
set(MIRAGE_PIXEL_FORMAT "SG_PIXELFORMAT_RGBA8" CACHE STRING "Pixel format")

if (MIRAGE_USE_HDR)
    add_definitions(-DMIRAGE_USE_HDR)
endif ()
add_definitions(-DMIRAGE_HDR_FORMAT=${MIRAGE_HDR_FORMAT} -DMIRAGE_PIXEL_FORMAT=${MIRAGE_PIXEL_FORMAT})

set(MSDFGEN_USE_SKIA OFF CACHE BOOL "Use Skia for MSDFGen" FORCE)
set(MSDFGEN_USE_VCPKG OFF CACHE BOOL "Use VCPKG for MSDFGen" FORCE)
set(MSDFGEN_USE_OPENMP ON CACHE BOOL "Use OpenMP for MSDFGen" FORCE)
set(MSDFGEN_BUILD_STANDALONE ON CACHE BOOL "Build MSDFGen standalone" FORCE)

# 配置输出目录
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(MIRAGE_ROOT_DIR ${CMAKE_CURRENT_SOURCE_DIR})

include(cmake/retrieve_files.cmake)
include(cmake/detect_os.cmake)
include(cmake/config_macos.cmake)
include(cmake/compile_shaders.cmake)

# 如果是Debug模式, 添加宏定义
if (CMAKE_BUILD_TYPE STREQUAL "Debug")
    add_definitions(-DDEBUG=1)
else ()
    add_definitions(-DDEBUG=0)
endif ()

add_subdirectory(third_party/msdfgen)
add_subdirectory(src)

set(BUILD_EXAMPLE FALSE CACHE BOOL "Build example")
if (BUILD_EXAMPLE)
    add_subdirectory(example)
endif ()
