find_package(Git QUIET)
# Only update submodules if inside a git repo
if (GIT_FOUND AND EXISTS "${PROJECT_SOURCE_DIR}/.git")
    # Update submodules as needed
    option(PRISMAL_GIT_SUBMODULE "Check submodules during build" ON)
    if (PRISMAL_GIT_SUBMODULE)
        message(STATUS "Submodule update")
        execute_process(COMMAND ${GIT_EXECUTABLE} submodule update --init --recursive
                WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
                RESULT_VARIABLE GIT_SUBMOD_RESULT)
        if (NOT GIT_SUBMOD_RESULT EQUAL "0")
            message(FATAL_ERROR "git submodule update --init failed with ${GIT_SUBMOD_RESULT}, please checkout submodules")
        endif ()
    endif ()
endif ()

if (NOT EXISTS "${PROJECT_SOURCE_DIR}/Vendor/fmt/CMakeLists.txt")
    message(FATAL_ERROR "The submodules were not downloaded! PRISMAL_GIT_SUBMODULE was turned off or failed. Please update submodules and try again.")
endif ()
if (NOT EXISTS "${PROJECT_SOURCE_DIR}/Vendor/date/CMakeLists.txt")
    message(FATAL_ERROR "The submodules were not downloaded! PRISMAL_GIT_SUBMODULE was turned off or failed. Please update submodules and try again.")
endif ()
if (NOT EXISTS "${PROJECT_SOURCE_DIR}/Vendor/range-v3/CMakeLists.txt")
    message(FATAL_ERROR "The submodules were not downloaded! PRISMAL_GIT_SUBMODULE was turned off or failed. Please update submodules and try again.")
endif ()
if (NOT EXISTS "${PROJECT_SOURCE_DIR}/Vendor/glm/CMakeLists.txt")
    message(FATAL_ERROR "The submodules were not downloaded! PRISMAL_GIT_SUBMODULE was turned off or failed. Please update submodules and try again.")
endif ()
if (NOT EXISTS "${PROJECT_SOURCE_DIR}/Vendor/SDL/CMakeLists.txt")
    message(FATAL_ERROR "The submodules were not downloaded! PRISMAL_GIT_SUBMODULE was turned off or failed. Please update submodules and try again.")
endif ()
if (NOT EXISTS "${PROJECT_SOURCE_DIR}/Vendor/refl-cpp/CMakeLists.txt")
    message(FATAL_ERROR "The submodules were not downloaded! PRISMAL_GIT_SUBMODULE was turned off or failed. Please update submodules and try again.")
endif ()
if (NOT EXISTS "${PROJECT_SOURCE_DIR}/Vendor/imgui/imgui.h")
    message(FATAL_ERROR "The submodules were not downloaded! PRISMAL_GIT_SUBMODULE was turned off or failed. Please update submodules and try again.")
endif ()
if (NOT EXISTS "${PROJECT_SOURCE_DIR}/Vendor/msgpack-c/CMakeLists.txt")
    message(FATAL_ERROR "The submodules were not downloaded! PRISMAL_GIT_SUBMODULE was turned off or failed. Please update submodules and try again.")
endif ()


if (PR_GRAPHICS_API STREQUAL "VK")
    if (NOT EXISTS "${PROJECT_SOURCE_DIR}/Vendor/VulkanMemoryAllocator/include/vk_mem_alloc.h")
        message(FATAL_ERROR "The submodules were not downloaded! PRISMAL_GIT_SUBMODULE was turned off or failed. Please update submodules and try again.")
    endif ()
endif()



