1 # This file is NOT licensed under the GPLv3, which is the license for the rest
4 # Here's the license text for this file:
6 # This is free and unencumbered software released into the public domain.
8 # Anyone is free to copy, modify, publish, use, compile, sell, or
9 # distribute this software, either in source code form or as a compiled
10 # binary, for any purpose, commercial or non-commercial, and by any
13 # In jurisdictions that recognize copyright laws, the author or authors
14 # of this software dedicate any and all copyright interest in the
15 # software to the public domain. We make this dedication for the benefit
16 # of the public at large and to the detriment of our heirs and
17 # successors. We intend this dedication to be an overt act of
18 # relinquishment in perpetuity of all present and future rights to this
19 # software under copyright law.
21 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
22 # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
23 # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
24 # IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
25 # OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
26 # ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
27 # OTHER DEALINGS IN THE SOFTWARE.
29 # For more information, please refer to <http://unlicense.org/>
40 '-DCONFIG_H_IS_FROM_SAMBA=1',
41 '-DSTATIC_replace_MODULES=NULL',
42 '-DSTATIC_replace_MODULES_PROTO=extern',
44 '-D_POSIX_PTHREAD_SEMANTICS',
47 '-D_XOPEN_SOURCE_EXTENDED=1',
48 '-DAD_DC_BUILD_IS_ENABLED=1',
50 '-I/usr/local/include',
63 '-Ibin/default/include',
64 '-Ibin/default/include/public',
66 '-Ibin/default/lib/replace',
67 '-Ibin/default/source3',
68 '-Ibin/default/source3/include',
69 '-Ibin/default/source3/lib',
70 '-Ibin/default/source4',
71 '-Ibin/default/source4/include',
72 '-Ibin/default/source4/lib',
76 '-Wdeclaration-after-statement',
78 '-Werror-implicit-function-declaration',
80 '-Werror=declaration-after-statement',
82 '-Werror=format-security',
83 '-Werror=pointer-arith',
84 '-Werror=return-type',
85 '-Werror=strict-prototypes',
86 '-Werror=uninitialized',
87 '-Werror=write-strings',
90 '-Wmissing-prototypes',
91 '-Wno-error=deprecated-declarations',
92 '-Wno-error=tautological-compare',
97 '-Wstrict-prototypes',
103 # Set this to the absolute path to the folder (NOT the file!) containing the
104 # compile_commands.json file to use that instead of 'flags'. See here for
105 # more details: http://clang.llvm.org/docs/JSONCompilationDatabase.html
107 # You can get CMake to generate this file for you by adding:
108 # set( CMAKE_EXPORT_COMPILE_COMMANDS 1 )
109 # to your CMakeLists.txt file.
111 # Most projects will NOT need to set this to anything; you can just change the
112 # 'flags' list of compilation flags. Notice that YCM itself uses that approach.
113 compilation_database_folder
= ''
115 if os
.path
.exists( compilation_database_folder
):
116 database
= ycm_core
.CompilationDatabase( compilation_database_folder
)
120 SOURCE_EXTENSIONS
= [ '.C', '.cpp', '.cxx', '.cc', '.c', '.m', '.mm' ]
122 def DirectoryOfThisScript():
123 return os
.path
.dirname( os
.path
.abspath( __file__
) )
126 def MakeRelativePathsInFlagsAbsolute( flags
, working_directory
):
127 if not working_directory
:
130 make_next_absolute
= False
131 path_flags
= [ '-isystem', '-I', '-iquote', '--sysroot=' ]
135 if make_next_absolute
:
136 make_next_absolute
= False
137 if not flag
.startswith( '/' ):
138 new_flag
= os
.path
.join( working_directory
, flag
)
140 for path_flag
in path_flags
:
141 if flag
== path_flag
:
142 make_next_absolute
= True
145 if flag
.startswith( path_flag
):
146 path
= flag
[ len( path_flag
): ]
147 new_flag
= path_flag
+ os
.path
.join( working_directory
, path
)
151 new_flags
.append( new_flag
)
155 def IsHeaderFile( filename
):
156 extension
= os
.path
.splitext( filename
)[ 1 ]
157 return extension
in [ '.H', '.h', '.hxx', '.hpp', '.hh' ]
160 def GetCompilationInfoForFile( filename
):
161 # The compilation_commands.json file generated by CMake does not have entries
162 # for header files. So we do our best by asking the db for flags for a
163 # corresponding source file, if any. If one exists, the flags for that file
164 # should be good enough.
165 if IsHeaderFile( filename
):
166 basename
= os
.path
.splitext( filename
)[ 0 ]
167 for extension
in SOURCE_EXTENSIONS
:
168 replacement_file
= basename
+ extension
169 if os
.path
.exists( replacement_file
):
170 compilation_info
= database
.GetCompilationInfoForFile(
172 if compilation_info
.compiler_flags_
:
173 return compilation_info
175 return database
.GetCompilationInfoForFile( filename
)
178 def FlagsForFile( filename
, **kwargs
):
180 # Bear in mind that compilation_info.compiler_flags_ does NOT return a
181 # python list, but a "list-like" StringVec object
182 compilation_info
= GetCompilationInfoForFile( filename
)
183 if not compilation_info
:
186 final_flags
= MakeRelativePathsInFlagsAbsolute(
187 compilation_info
.compiler_flags_
,
188 compilation_info
.compiler_working_dir_
)
190 relative_to
= DirectoryOfThisScript()
191 final_flags
= MakeRelativePathsInFlagsAbsolute( flags
, relative_to
)
194 'flags': final_flags
,