project(mirage_render)

set(SOURCE_FILES)
retrieve_files(${CMAKE_CURRENT_SOURCE_DIR}/src SOURCE_FILES)

add_library(${PROJECT_NAME} STATIC ${SOURCE_FILES})
target_include_directories(${PROJECT_NAME} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/src)
target_link_libraries(${PROJECT_NAME} PUBLIC mirage_core sokol mirage_image)

option(MIRAGE_SVG_EMOJI "Use svg emoji" ON)
if (MIRAGE_SVG_EMOJI)
    find_package(nanosvg REQUIRED)
    find_package(ZLIB REQUIRED)
    target_link_libraries(${PROJECT_NAME} PUBLIC NanoSVG::nanosvg NanoSVG::nanosvgrast ZLIB::ZLIB)
    target_compile_definitions(${PROJECT_NAME} PUBLIC HAS_NANOSVG)
endif ()

# 设置图像加载器
set(MIRAGE_IMAGE_LOAD_BACKEND "STB_IMAGE" CACHE STRING "选择图像加载器")
set_property(CACHE MIRAGE_IMAGE_LOAD_BACKEND PROPERTY STRINGS "STB_IMAGE" "CUSTOM")
if (MIRAGE_IMAGE_LOAD_BACKEND STREQUAL "STB_IMAGE")
    add_subdirectory(image/stb_image_loader)
    target_link_libraries(${PROJECT_NAME} PUBLIC stb_image_loader)
    target_compile_definitions(${PROJECT_NAME} PUBLIC HAS_STB_IMAGE)
endif ()

# 设置字体后端
set(MIRAGE_FONT_BACKEND "STB_TRUETYPE" CACHE STRING "选择字体后端")
set_property(CACHE MIRAGE_FONT_BACKEND PROPERTY STRINGS "STB_TRUETYPE" "FREETYPE" "CUSTOM")
if (MIRAGE_FONT_BACKEND STREQUAL "STB_TRUETYPE")
    add_subdirectory(font/stb_truetype_font)
    target_link_libraries(${PROJECT_NAME} PUBLIC stb_truetype_font)
    target_compile_definitions(${PROJECT_NAME} PUBLIC HAS_STB_TRUETYPE)
elseif (MIRAGE_FONT_BACKEND STREQUAL "FREETYPE")
    add_subdirectory(font/freetype_font)
    target_link_libraries(${PROJECT_NAME} PUBLIC freetype_font)
    target_compile_definitions(${PROJECT_NAME} PUBLIC HAS_FREETYPE)
endif ()

# 添加编译shader的自定义命令
add_mirage_shader_directory(${CMAKE_CURRENT_SOURCE_DIR}/shaders)
add_shader_dependencies(${PROJECT_NAME})
