function(filter_list output input)
    unset(result)
    foreach(filename ${${input}})
        foreach(pattern ${ARGN})
            if("${filename}" MATCHES "${pattern}")
                list(APPEND result "${filename}")
            endif()
        endforeach()
    endforeach()
    set(${output} ${result} PARENT_SCOPE)
endfunction()

function(split_list haves havenots input)
    filter_list(_haves ${input} ${ARGN})
    set(_havenots ${${input}})
    list(REMOVE_ITEM _havenots ${_haves})
    set(${haves} ${_haves} PARENT_SCOPE)
    set(${havenots} ${_havenots} PARENT_SCOPE)
endfunction()

