nmeadump: refactoring of cli parameter port speed.
[marnav.git] / .ycm_extra_conf.py
blobb2a16b051c55be94ab0026688114a10daf6d7dc8
1 import ycm_core
2 import glob
3 import os
5 flags = [
6 '-Wall',
7 '-Wextra',
8 '-Werror'
9 '-pedantic',
10 '-std=c++11',
11 '-I.',
12 '-Isrc',
13 '-isystem', '/usr/include',
14 '-isystem', '/usr/local/include',
17 def DirectoryOfThisScript():
18 return os.path.dirname(os.path.abspath(__file__))
20 compilation_database_folder = DirectoryOfThisScript() + '/build'
22 if os.path.exists( compilation_database_folder ):
23 database = ycm_core.CompilationDatabase( compilation_database_folder )
24 else:
25 database = None
27 SOURCE_EXTENSIONS = [ '.cpp', '.cxx', '.cc', '.c', '.m', '.mm' ]
29 def DirectoryOfThisScript():
30 return os.path.dirname( os.path.abspath( __file__ ) )
32 def MakeRelativePathsInFlagsAbsolute( flags, working_directory ):
33 if not working_directory:
34 return list( flags )
35 new_flags = []
36 make_next_absolute = False
37 path_flags = [ '-isystem', '-I', '-iquote', '--sysroot=' ]
38 for flag in flags:
39 new_flag = flag
41 if make_next_absolute:
42 make_next_absolute = False
43 if not flag.startswith( '/' ):
44 new_flag = os.path.join( working_directory, flag )
46 for path_flag in path_flags:
47 if flag == path_flag:
48 make_next_absolute = True
49 break
51 if flag.startswith( path_flag ):
52 path = flag[ len( path_flag ): ]
53 new_flag = path_flag + os.path.join( working_directory, path )
54 break
56 if new_flag:
57 new_flags.append( new_flag )
58 return new_flags
61 def IsHeaderFile( filename ):
62 extension = os.path.splitext( filename )[ 1 ]
63 return extension in [ '.h', '.hxx', '.hpp', '.hh' ]
66 def GetCompilationInfoForFile( filename ):
67 # The compilation_commands.json file generated by CMake does not have entries
68 # for header files. So we do our best by asking the db for flags for a
69 # corresponding source file, if any. If one exists, the flags for that file
70 # should be good enough.
71 if IsHeaderFile( filename ):
72 basename = os.path.splitext( filename )[ 0 ]
73 for extension in SOURCE_EXTENSIONS:
74 replacement_file = basename + extension
75 if os.path.exists( replacement_file ):
76 compilation_info = database.GetCompilationInfoForFile(
77 replacement_file )
78 if compilation_info.compiler_flags_:
79 return compilation_info
80 return None
81 return database.GetCompilationInfoForFile( filename )
84 def FlagsForFile( filename, **kwargs ):
85 if database:
86 # Bear in mind that compilation_info.compiler_flags_ does NOT return a
87 # python list, but a "list-like" StringVec object
88 compilation_info = GetCompilationInfoForFile( filename )
89 if not compilation_info:
90 return None
92 final_flags = MakeRelativePathsInFlagsAbsolute(
93 compilation_info.compiler_flags_,
94 compilation_info.compiler_working_dir_ )
96 # NOTE: This is just for YouCompleteMe; it's highly likely that your project
97 # does NOT need to remove the stdlib flag. DO NOT USE THIS IN YOUR
98 # ycm_extra_conf IF YOU'RE NOT 100% SURE YOU NEED IT.
99 try:
100 final_flags.remove( '-stdlib=libc++' )
101 except ValueError:
102 pass
103 else:
104 relative_to = DirectoryOfThisScript()
105 final_flags = MakeRelativePathsInFlagsAbsolute( flags, relative_to )
107 return {
108 'flags': final_flags,
109 'do_cache': True