function(git_update_submodule SUBMODULE_NAME FILE_SHOULD_EXIST)
    string(TOUPPER ${SUBMODULE_NAME} SUBMODULE_NAME_UPPER)
    set(UPDATE_SUBMODULE GIT_UPDATE_SUBMODULE_${SUBMODULE_NAME_UPPER})
    set(SUBMODULE_PATH submodules/${SUBMODULE_NAME})
    set(FILE_SHOULD_EXIST_PATH "${PROJECT_SOURCE_DIR}/${SUBMODULE_PATH}/${FILE_SHOULD_EXIST}")
    if(${CAN_GIT})
        option(${UPDATE_SUBMODULE} "Check ${SUBMODULE_NAME} during build" ON)
        if(${UPDATE_SUBMODULE})
            message(STATUS "${SUBMODULE_NAME}: git submodule update --init --recursive --depth 1 --remote --rebase -- ${SUBMODULE_PATH}")
            execute_process(COMMAND ${GIT_EXECUTABLE} submodule update --init --recursive --depth 1 -- ${SUBMODULE_PATH}
                            WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
                            RESULT_VARIABLE GIT_SUBMOD_RESULT)
            if(NOT GIT_SUBMOD_RESULT EQUAL "0")
                message(FATAL_ERROR "Submodule ${SUBMODULE_NAME} update FAILED with: \"${GIT_SUBMOD_RESULT}\"")
            endif()
        endif()
    endif()
    message(STATUS "${SUBMODULE_NAME}: checking existence of \"${FILE_SHOULD_EXIST_PATH}\"")
    if(NOT EXISTS "${FILE_SHOULD_EXIST_PATH}")
        message(FATAL_ERROR "Submodule \"${SUBMODULE_NAME}\" was not downloaded! ${UPDATE_SUBMODULE} was turned off or failed. Please update submodules and try again.")
    endif()
endfunction()