import re
import logging


def _find_includes_recursive(fname, files=None):
    """Recursive helper function for find_includes()

    Recursively traverse all files included by ``fname``, results
    are accumulated in ``files`` and then returned.
    """

    if files is None:
        files = set()

    if fname in files:
        return files

    files.add(fname)

    l = []
    try:
        with open(fname, 'r') as f:
            for line in f:
                m = re.match(r'#\s*include\s*[<"](.*?)[>"]', line)
                if not m:
                    continue
                inc = m.group(1).replace('/', '\\')
                if not inc.startswith('boost'):
                    continue
                l.append(inc)
        for inc in l:
            _find_includes_recursive(inc, files)
    except FileNotFoundError as e:
        logging.warn("File not found: '%s'", fname)

    return files