diff options
Diffstat (limited to 'ycm_extra_conf.py')
-rw-r--r-- | ycm_extra_conf.py | 145 |
1 files changed, 145 insertions, 0 deletions
diff --git a/ycm_extra_conf.py b/ycm_extra_conf.py new file mode 100644 index 0000000..c4cc609 --- /dev/null +++ b/ycm_extra_conf.py | |||
@@ -0,0 +1,145 @@ | |||
1 | # Generated by YCM Generator at 2015-09-05 13:02:32.549813 | ||
2 | |||
3 | # This file is NOT licensed under the GPLv3, which is the license for the rest | ||
4 | # of YouCompleteMe. | ||
5 | # | ||
6 | # Here's the license text for this file: | ||
7 | # | ||
8 | # This is free and unencumbered software released into the public domain. | ||
9 | # | ||
10 | # Anyone is free to copy, modify, publish, use, compile, sell, or | ||
11 | # distribute this software, either in source code form or as a compiled | ||
12 | # binary, for any purpose, commercial or non-commercial, and by any | ||
13 | # means. | ||
14 | # | ||
15 | # In jurisdictions that recognize copyright laws, the author or authors | ||
16 | # of this software dedicate any and all copyright interest in the | ||
17 | # software to the public domain. We make this dedication for the benefit | ||
18 | # of the public at large and to the detriment of our heirs and | ||
19 | # successors. We intend this dedication to be an overt act of | ||
20 | # relinquishment in perpetuity of all present and future rights to this | ||
21 | # software under copyright law. | ||
22 | # | ||
23 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
24 | # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
25 | # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. | ||
26 | # IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR | ||
27 | # OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, | ||
28 | # ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR | ||
29 | # OTHER DEALINGS IN THE SOFTWARE. | ||
30 | # | ||
31 | # For more information, please refer to <http://unlicense.org/> | ||
32 | |||
33 | import os | ||
34 | import ycm_core | ||
35 | |||
36 | flags = [ | ||
37 | '-x', | ||
38 | 'c', | ||
39 | '-D_GNU_SOURCE', | ||
40 | '-I./', | ||
41 | '-I/usr/include', | ||
42 | '-I/usr/local/include', | ||
43 | '-Wall', | ||
44 | '-I', '../submodules/', | ||
45 | '-I', 'lib/', | ||
46 | '-I', 'submodules/qdecoder/src/', | ||
47 | ] | ||
48 | |||
49 | |||
50 | # Set this to the absolute path to the folder (NOT the file!) containing the | ||
51 | # compile_commands.json file to use that instead of 'flags'. See here for | ||
52 | # more details: http://clang.llvm.org/docs/JSONCompilationDatabase.html | ||
53 | # | ||
54 | # You can get CMake to generate this file for you by adding: | ||
55 | # set( CMAKE_EXPORT_COMPILE_COMMANDS 1 ) | ||
56 | # to your CMakeLists.txt file. | ||
57 | # | ||
58 | # Most projects will NOT need to set this to anything; you can just change the | ||
59 | # 'flags' list of compilation flags. Notice that YCM itself uses that approach. | ||
60 | compilation_database_folder = '' | ||
61 | |||
62 | if os.path.exists( compilation_database_folder ): | ||
63 | database = ycm_core.CompilationDatabase( compilation_database_folder ) | ||
64 | else: | ||
65 | database = None | ||
66 | |||
67 | SOURCE_EXTENSIONS = [ '.cpp', '.cxx', '.cc', '.c', '.m', '.mm' ] | ||
68 | |||
69 | def DirectoryOfThisScript(): | ||
70 | return os.path.dirname( os.path.abspath( __file__ ) ) | ||
71 | |||
72 | |||
73 | def MakeRelativePathsInFlagsAbsolute( flags, working_directory ): | ||
74 | if not working_directory: | ||
75 | return list( flags ) | ||
76 | new_flags = [] | ||
77 | make_next_absolute = False | ||
78 | path_flags = [ '-isystem', '-I', '-iquote', '--sysroot=' ] | ||
79 | for flag in flags: | ||
80 | new_flag = flag | ||
81 | |||
82 | if make_next_absolute: | ||
83 | make_next_absolute = False | ||
84 | if not flag.startswith( '/' ): | ||
85 | new_flag = os.path.join( working_directory, flag ) | ||
86 | |||
87 | for path_flag in path_flags: | ||
88 | if flag == path_flag: | ||
89 | make_next_absolute = True | ||
90 | break | ||
91 | |||
92 | if flag.startswith( path_flag ): | ||
93 | path = flag[ len( path_flag ): ] | ||
94 | new_flag = path_flag + os.path.join( working_directory, path ) | ||
95 | break | ||
96 | |||
97 | if new_flag: | ||
98 | new_flags.append( new_flag ) | ||
99 | return new_flags | ||
100 | |||
101 | |||
102 | def IsHeaderFile( filename ): | ||
103 | extension = os.path.splitext( filename )[ 1 ] | ||
104 | return extension in [ '.h', '.hxx', '.hpp', '.hh' ] | ||
105 | |||
106 | |||
107 | def GetCompilationInfoForFile( filename ): | ||
108 | # The compilation_commands.json file generated by CMake does not have entries | ||
109 | # for header files. So we do our best by asking the db for flags for a | ||
110 | # corresponding source file, if any. If one exists, the flags for that file | ||
111 | # should be good enough. | ||
112 | if IsHeaderFile( filename ): | ||
113 | basename = os.path.splitext( filename )[ 0 ] | ||
114 | for extension in SOURCE_EXTENSIONS: | ||
115 | replacement_file = basename + extension | ||
116 | if os.path.exists( replacement_file ): | ||
117 | compilation_info = database.GetCompilationInfoForFile( | ||
118 | replacement_file ) | ||
119 | if compilation_info.compiler_flags_: | ||
120 | return compilation_info | ||
121 | return None | ||
122 | return database.GetCompilationInfoForFile( filename ) | ||
123 | |||
124 | |||
125 | def FlagsForFile( filename, **kwargs ): | ||
126 | if database: | ||
127 | # Bear in mind that compilation_info.compiler_flags_ does NOT return a | ||
128 | # python list, but a "list-like" StringVec object | ||
129 | compilation_info = GetCompilationInfoForFile( filename ) | ||
130 | if not compilation_info: | ||
131 | return None | ||
132 | |||
133 | final_flags = MakeRelativePathsInFlagsAbsolute( | ||
134 | compilation_info.compiler_flags_, | ||
135 | compilation_info.compiler_working_dir_ ) | ||
136 | |||
137 | else: | ||
138 | relative_to = DirectoryOfThisScript() | ||
139 | final_flags = MakeRelativePathsInFlagsAbsolute( flags, relative_to ) | ||
140 | |||
141 | return { | ||
142 | 'flags': final_flags, | ||
143 | 'do_cache': True | ||
144 | } | ||
145 | |||