# 加载 datoviz的依赖库
include(${CMAKE_CURRENT_LIST_DIR}/cmake/export.cmake)
set(Renderive_render_3D_dependencies render_3D::pthreads4w render_3D::cglm)
if (RENDERIVE_BUILD_TESTS)
    list(APPEND Renderive_render_3D_dependencies global::GTest)
endif ()
rcl_add_dependency_action_targets(Renderive_render_3D_env ${Renderive_render_3D_dependencies})
set_target_properties(Renderive_render_3D_env PROPERTIES FOLDER Renderive_render_3D)
library_is_installed_with_rely(Renderive_render_3D_dependencies_installed ${Renderive_render_3D_dependencies})
if (NOT Renderive_render_3D_dependencies_installed)
    rcl_log_append(${CMAKE_CURRENT_LIST_LINE} "[FATAL_ERROR] Renderive_render_3D dependencies are not installed. Build Renderive_render_3D_env first")
    return()
endif ()
rcl_load_dependency_environment(${Renderive_render_3D_dependencies})
# 官网下载安装 https://vulkan.lunarg.com/sdk/home
set(ENV{VULKAN_SDK} "C:/VulkanSDK/1.4.357.0")
find_package(Vulkan REQUIRED)
message(STATUS "${B}Vulkan_VERSION=${Vulkan_VERSION}${E}")
find_package(PThreads4W REQUIRED)
find_package(cglm CONFIG REQUIRED)
if (RENDERIVE_BUILD_TESTS)
    find_package(GTest CONFIG REQUIRED)
endif ()
if (NOT TARGET Renderive_Kernel)
    rcl_log_append(${CMAKE_CURRENT_LIST_LINE} "[FATAL_ERROR] Renderive_render_3D requires Renderive_Kernel")
    return()
endif ()
set(Renderive_render_3D_source_dir "${CMAKE_CURRENT_LIST_DIR}")
append_glob_source(Renderive_render_3D_sources "${Renderive_render_3D_source_dir}")
list(FILTER Renderive_render_3D_sources EXCLUDE REGEX "/tests/")
add_library(Renderive_render_3D STATIC ${Renderive_render_3D_sources})
target_include_directories(Renderive_render_3D PUBLIC
        "$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}>"
)
target_compile_features(Renderive_render_3D PUBLIC cxx_std_20)
if (MSVC)
    target_compile_options(Renderive_render_3D PRIVATE /utf-8)
endif ()
if (RENDERIVE_BUILD_TESTS)
    set(Renderive_render_3D_test_dir "${CMAKE_CURRENT_LIST_DIR}/tests")
    append_glob_source(Renderive_render_3D_test_sources "${Renderive_render_3D_test_dir}")
    foreach (Renderive_render_3D_test_source IN LISTS Renderive_render_3D_test_sources)
        if (NOT Renderive_render_3D_test_source MATCHES "\\.(c|cc|cpp|cxx)$")
            continue()
        endif ()
        file(RELATIVE_PATH Renderive_render_3D_test_name "${Renderive_render_3D_test_dir}" "${Renderive_render_3D_test_source}")
        string(MD5 Renderive_render_3D_test_hash "${Renderive_render_3D_test_name}")
        string(SUBSTRING "${Renderive_render_3D_test_hash}" 0 8 Renderive_render_3D_test_hash)
        get_filename_component(Renderive_render_3D_test_name "${Renderive_render_3D_test_source}" NAME_WE)
        string(MAKE_C_IDENTIFIER "${Renderive_render_3D_test_name}" Renderive_render_3D_test_name)
        set(Renderive_render_3D_test_target "Renderive_render_3D_${Renderive_render_3D_test_name}_${Renderive_render_3D_test_hash}")
        add_executable("${Renderive_render_3D_test_target}" "${Renderive_render_3D_test_source}")
        target_link_libraries("${Renderive_render_3D_test_target}" PRIVATE Renderive_render_3D GTest::gtest_main)
        add_test(NAME "${Renderive_render_3D_test_target}" COMMAND "${Renderive_render_3D_test_target}")
    endforeach ()
endif ()
