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

include(cmake/project_cpp_standard.cmake)
set_cpp_standard(23)

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=1)
else ()
    add_definitions(-DMIRAGE_USE_HDR=0)
endif ()
add_definitions(-DMIRAGE_HDR_FORMAT=${MIRAGE_HDR_FORMAT} -DMIRAGE_PIXEL_FORMAT=${MIRAGE_PIXEL_FORMAT})

# --- 设置项目根目录变量 ---
# **定义项目源代码根目录变量**:
# CMAKE_CURRENT_SOURCE_DIR 在根 CMakeLists.txt 中即为项目源代码的根目录
# 使用 PARENT_SCOPE 使该变量在调用此函数的 CMakeLists.txt 文件中也可用
set(MIRAGE_ROOT_DIR ${CMAKE_CURRENT_SOURCE_DIR})
message(STATUS "mirage 项目根源目录 (MIRAGE_ROOT_DIR) 设置为: ${MIRAGE_ROOT_DIR}")

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

# 配置输出目录
configure_project_defaults()

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

add_subdirectory(src/sokol)
add_subdirectory(src/mirage_config)
add_subdirectory(src/mirage_render)
add_subdirectory(src/mirage_image)
add_subdirectory(src/mirage_core)
add_subdirectory(src/mirage_widget)
add_subdirectory(src/mirage_app)

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