function(SetShaderDependency TARGET SHADER_SRC_FOLDER SHADER_OUTPUT_FOLDER)
    if (NOT EXISTS ${SHADER_OUTPUT_FOLDER})
        file(MAKE_DIRECTORY ${SHADER_OUTPUT_FOLDER})
    endif ()

    file(GLOB SHADER_SRC_FILES ${SHADER_SRC_FOLDER}/*)
    list(FILTER SHADER_SRC_FILES EXCLUDE REGEX ".*\\.(hpp|cpp)$")
    foreach(SHADER_FILE ${SHADER_SRC_FILES})
        get_filename_component(FILENAME ${SHADER_FILE} NAME_WLE)
        if (NOT ${FILENAME} IN_LIST PROCESSED_FILES)
            list(APPEND PROCESSED_FILES ${FILENAME})
            list(APPEND OUTPUT_HEADERS ${SHADER_OUTPUT_FOLDER}/${FILENAME}.h)
            list(APPEND OUTPUT_SOURCES ${SHADER_OUTPUT_FOLDER}/${FILENAME}.c)
        endif()
    endforeach()
    set(SHADER_EXPECTED_OUTPUT ${OUTPUT_HEADERS} ${OUTPUT_SOURCES})

    add_custom_command(OUTPUT ${SHADER_EXPECTED_OUTPUT}
                        COMMAND ${CMAKE_COMMAND} -P ${CMAKE_BINARY_DIR}/TryCompileShaders.cmake
                        DEPENDS ${SHADER_SRC_FILES}
                        COMMENT "Recompiling shaders")
    add_custom_target(RecompileShaders ALL
                        DEPENDS ${SHADER_EXPECTED_OUTPUT})
    add_dependencies(${TARGET} RecompileShaders)
endfunction(SetShaderDependency)