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