]> git.rmz.io Git - dotfiles.git/blob - vim/ycm_extra_conf.py
vim: add global ycm_extra_conf
[dotfiles.git] / vim / ycm_extra_conf.py
1 import os
2 import shlex
3 import subprocess
4 import ycm_core
5
6 # These are the compilation flags that will be used in case there's no
7 # compilation database set (by default, one is not set).
8 # CHANGE THIS LIST OF FLAGS. YES, THIS IS THE DROID YOU HAVE BEEN LOOKING FOR.
9 flags = [
10 '-Wall',
11 # '-Wextra',
12 # '-Wshadow',
13 # '-Werror',
14 # '-Wc++98-compat',
15 # '-Wno-long-long',
16 # '-Wno-variadic-macros',
17 # '-fexceptions',
18 # '-DNDEBUG',
19 '-std=c++11',
20 '-stdlib=libc++',
21 '-x', 'c++',
22 '-I', '.',
23 '-I', './include',
24 '-isystem', '/usr/include/c++/4.9.0',
25 '-isystem', '/usr/include/c++/4.9.0/x86_64-unknown-linux-gnu',
26 '-isystem', '/usr/include/c++/4.9.0/backward',
27 '-isystem', '/usr/lib/clang/3.4.1/include'
28 ]
29
30 # This function makes it easy to pull in additional flags from rospack
31 def rospack():
32 cmd = ['rospack', 'cflags-only-I']
33 try:
34 out = subprocess.Popen(cmd, shell=False, stdout=subprocess.PIPE).stdout
35 except:
36 return []
37 line = out.readline()[:-1].split(" ")
38 includes = []
39 for include in line:
40 if include.startswith(os.path.expanduser('~')):
41 includes += ['-I', include]
42 else:
43 includes += ['-isystem', include]
44 return filter(lambda a: a != ' ', includes)
45
46 flags += rospack()
47
48 def DirectoryOfThisScript():
49 return os.path.dirname( os.path.abspath( __file__ ) )
50
51 def MakeRelativePathsInFlagsAbsolute( flags, working_directory ):
52 if not working_directory:
53 return list( flags )
54 new_flags = []
55 make_next_absolute = False
56 path_flags = [ '-isystem', '-I', '-iquote', '--sysroot=' ]
57 for flag in flags:
58 new_flag = flag
59
60 if make_next_absolute:
61 make_next_absolute = False
62 if not flag.startswith( '/' ):
63 new_flag = os.path.join( working_directory, flag )
64
65 for path_flag in path_flags:
66 if flag == path_flag:
67 make_next_absolute = True
68 break
69
70 if flag.startswith( path_flag ):
71 path = flag[ len( path_flag ): ]
72 new_flag = path_flag + os.path.join( working_directory, path )
73 break
74
75 if new_flag:
76 new_flags.append( new_flag )
77 return new_flags
78
79 def FlagsForFile( filename, **kwargs ):
80 relative_to = DirectoryOfThisScript()
81 final_flags = MakeRelativePathsInFlagsAbsolute( flags, relative_to )
82
83 return {
84 'flags': final_flags,
85 'do_cache': True
86 }