set(Renderive_Kernel_dependencies global::taskflow)
if(RENDERIVE_BUILD_TESTS)
    list(APPEND Renderive_Kernel_dependencies global::GTest)
endif()
rcl_add_dependency_action_targets(Renderive_Kernel_env ${Renderive_Kernel_dependencies})
set_target_properties(Renderive_Kernel_env PROPERTIES FOLDER Renderive_Kernel)
library_is_installed_with_rely(Renderive_Kernel_dependencies_installed ${Renderive_Kernel_dependencies})
if(NOT Renderive_Kernel_dependencies_installed)
    rcl_log_append("[FATAL_ERROR] Renderive_Kernel dependencies are not installed. Build Renderive_Kernel_env first")
    return()
endif()
rcl_load_dependency_environment(${Renderive_Kernel_dependencies})
find_package(Taskflow CONFIG REQUIRED)
find_package(Threads REQUIRED)
if(RENDERIVE_BUILD_TESTS)
    find_package(GTest CONFIG REQUIRED)
endif()
set(Renderive_Kernel_source_dir "${CMAKE_CURRENT_LIST_DIR}/src")
append_glob_source(Renderive_Kernel_sources "${Renderive_Kernel_source_dir}")
add_library(Renderive_Kernel STATIC ${Renderive_Kernel_sources})
target_include_directories(Renderive_Kernel PUBLIC
    "$<BUILD_INTERFACE:${Renderive_Kernel_source_dir}>"
)
target_compile_features(Renderive_Kernel PUBLIC cxx_std_20)
target_link_libraries(Renderive_Kernel PRIVATE Taskflow::Taskflow Threads::Threads)
if(MSVC)
    target_compile_options(Renderive_Kernel PRIVATE /utf-8)
endif()
if(RENDERIVE_BUILD_TESTS)
    set(Renderive_Kernel_test_dir "${CMAKE_CURRENT_LIST_DIR}/tests")
    append_glob_source(Renderive_Kernel_test_sources "${Renderive_Kernel_test_dir}")
    foreach(Renderive_Kernel_test_source IN LISTS Renderive_Kernel_test_sources)
        if(NOT Renderive_Kernel_test_source MATCHES "\\.(c|cc|cpp|cxx)$")
            continue()
        endif()
        file(RELATIVE_PATH Renderive_Kernel_test_name "${Renderive_Kernel_test_dir}" "${Renderive_Kernel_test_source}")
        string(MD5 Renderive_Kernel_test_hash "${Renderive_Kernel_test_name}")
        string(SUBSTRING "${Renderive_Kernel_test_hash}" 0 8 Renderive_Kernel_test_hash)
        get_filename_component(Renderive_Kernel_test_name "${Renderive_Kernel_test_source}" NAME_WE)
        string(MAKE_C_IDENTIFIER "${Renderive_Kernel_test_name}" Renderive_Kernel_test_name)
        set(Renderive_Kernel_test_target "Renderive_Kernel_${Renderive_Kernel_test_name}_${Renderive_Kernel_test_hash}")
        add_executable("${Renderive_Kernel_test_target}" "${Renderive_Kernel_test_source}")
        target_link_libraries("${Renderive_Kernel_test_target}" PRIVATE Renderive_Kernel GTest::gtest_main)
        add_test(NAME "${Renderive_Kernel_test_target}" COMMAND "${Renderive_Kernel_test_target}")
    endforeach()
endif()
