How to recursively add include folders?

638 views
Skip to first unread message

Ronnie Zheng

unread,
Feb 12, 2015, 10:02:47 PM2/12/15
to ycm-...@googlegroups.com
Hi all,

When setup large C++ project in vi with YCM, if the headers files are in various sub-folders of the root folder, is there a way to add all of them to the include path of clang with one single -I statement in .ycm_extra_conf.py? Otherwise it is impossible to add them one bye one...

e.g. -I/home/xxx/topdir/** will be expended to all subdir in the topdir .

Regards
Ronnie.

Denis Zaletaev

unread,
Mar 1, 2015, 12:52:14 PM3/1/15
to ycm-...@googlegroups.com
In .ycm_extra_conf.py you define a function FlagsForFile, which returns an object with a 'flags' field. You can use some python code to populate is, have you considered this option?

Matan Rubin

unread,
Jun 28, 2015, 1:02:42 PM6/28/15
to ycm-...@googlegroups.com
Hi Ronnie,
I use the following in my .ycm_extra_conf.py, right after the flags section:

def find_git_root():
    pipe = subprocess.Popen(['git', 'rev-parse', '--show-toplevel'],
                            stdout=subprocess.PIPE)
    repo_dir = pipe.communicate()[0].rstrip().decode('utf-8')
    return repo_dir


def gen_recursive_include_path(dir):
    subdirs = [x[0] for x in os.walk(dir) if "CMake" not in x[0]]
    include_path = []
    for x in subdirs:
        include_path.extend(['-I', x])
    return include_path

flags = flags + gen_recursive_include_path(find_git_root() + '/src')
flags = flags + gen_recursive_include_path(find_git_root() + '/build/src')


It automatically adds all subdirs in the project to the include path.
Matan
Reply all
Reply to author
Forward
0 new messages