.ycm_extra_conf.py
Go to the documentation of this file.
00001 # This file is NOT licensed under the GPLv3, which is the license for the rest
00002 # of YouCompleteMe.
00003 #
00004 # Here's the license text for this file:
00005 #
00006 # This is free and unencumbered software released into the public domain.
00007 #
00008 # Anyone is free to copy, modify, publish, use, compile, sell, or
00009 # distribute this software, either in source code form or as a compiled
00010 # binary, for any purpose, commercial or non-commercial, and by any
00011 # means.
00012 #
00013 # In jurisdictions that recognize copyright laws, the author or authors
00014 # of this software dedicate any and all copyright interest in the
00015 # software to the public domain. We make this dedication for the benefit
00016 # of the public at large and to the detriment of our heirs and
00017 # successors. We intend this dedication to be an overt act of
00018 # relinquishment in perpetuity of all present and future rights to this
00019 # software under copyright law.
00020 #
00021 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
00022 # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00023 # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
00024 # IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
00025 # OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
00026 # ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
00027 # OTHER DEALINGS IN THE SOFTWARE.
00028 #
00029 # For more information, please refer to <http://unlicense.org/>
00030 
00031 import os
00032 import ycm_core
00033 
00034 # These are the compilation flags that will be used in case there's no
00035 # compilation database set (by default, one is not set).
00036 # CHANGE THIS LIST OF FLAGS. YES, THIS IS THE DROID YOU HAVE BEEN LOOKING FOR.
00037 flags = [
00038 '-Wall',
00039 '-Wextra',
00040 '-Werror',
00041 '-Wno-long-long',
00042 '-Wno-variadic-macros',
00043 '-fexceptions',
00044 '-DNDEBUG',
00045 # You 100% do NOT need -DUSE_CLANG_COMPLETER in your flags; only the YCM
00046 # source code needs it.
00047 '-DUSE_CLANG_COMPLETER',
00048 # THIS IS IMPORTANT! Without a "-std=<something>" flag, clang won't know which
00049 # language to use when compiling headers. So it will guess. Badly. So C++
00050 # headers will be compiled as C headers. You don't want that so ALWAYS specify
00051 # a "-std=<something>".
00052 # For a C project, you would set this to something like 'c99' instead of
00053 # 'c++11'.
00054 '-std=c++11',
00055 # ...and the same thing goes for the magic -x option which specifies the
00056 # language that the files to be compiled are written in. This is mostly
00057 # relevant for c++ headers.
00058 # For a C project, you would set this to 'c' instead of 'c++'.
00059 '-x',
00060 'c++',
00061 '-isystem', '../BoostParts',
00062 '-isystem', '/System/Library/Frameworks/Python.framework/Headers',
00063 '-isystem', '../llvm/include',
00064 '-isystem', '../llvm/tools/clang/include',
00065 '-I', '.',
00066 '-I', './ClangCompleter',
00067 '-isystem', './tests/gmock/gtest',
00068 '-isystem', './tests/gmock/gtest/include',
00069 '-isystem', './tests/gmock',
00070 '-isystem', './tests/gmock/include',
00071 '-I', '/usr/local/include',
00072 '-I', 'include',
00073 '-I', '/usr/lib/gcc/x86_64-linux-gnu/4.9/include',
00074 '-I', '/usr/include/x86_64-linux-gnu',
00075 '-I', '/usr/include'
00076 
00077 ]
00078 
00079 
00080 # Set this to the absolute path to the folder (NOT the file!) containing the
00081 # compile_commands.json file to use that instead of 'flags'. See here for
00082 # more details: http://clang.llvm.org/docs/JSONCompilationDatabase.html
00083 #
00084 # You can get CMake to generate this file for you by adding:
00085 #   set( CMAKE_EXPORT_COMPILE_COMMANDS 1 )
00086 # to your CMakeLists.txt file.
00087 #
00088 # Most projects will NOT need to set this to anything; you can just change the
00089 # 'flags' list of compilation flags. Notice that YCM itself uses that approach.
00090 compilation_database_folder = ''
00091 
00092 if os.path.exists( compilation_database_folder ):
00093   database = ycm_core.CompilationDatabase( compilation_database_folder )
00094 else:
00095   database = None
00096 
00097 SOURCE_EXTENSIONS = [ '.cpp', '.cxx', '.cc', '.c', '.m', '.mm' ]
00098 
00099 def DirectoryOfThisScript():
00100   return os.path.dirname( os.path.abspath( __file__ ) )
00101 
00102 
00103 def MakeRelativePathsInFlagsAbsolute( flags, working_directory ):
00104   if not working_directory:
00105     return list( flags )
00106   new_flags = []
00107   make_next_absolute = False
00108   path_flags = [ '-isystem', '-I', '-iquote', '--sysroot=' ]
00109   for flag in flags:
00110     new_flag = flag
00111 
00112     if make_next_absolute:
00113       make_next_absolute = False
00114       if not flag.startswith( '/' ):
00115         new_flag = os.path.join( working_directory, flag )
00116 
00117     for path_flag in path_flags:
00118       if flag == path_flag:
00119         make_next_absolute = True
00120         break
00121 
00122       if flag.startswith( path_flag ):
00123         path = flag[ len( path_flag ): ]
00124         new_flag = path_flag + os.path.join( working_directory, path )
00125         break
00126 
00127     if new_flag:
00128       new_flags.append( new_flag )
00129   return new_flags
00130 
00131 
00132 def IsHeaderFile( filename ):
00133   extension = os.path.splitext( filename )[ 1 ]
00134   return extension in [ '.h', '.hxx', '.hpp', '.hh' ]
00135 
00136 
00137 def GetCompilationInfoForFile( filename ):
00138   # The compilation_commands.json file generated by CMake does not have entries
00139   # for header files. So we do our best by asking the db for flags for a
00140   # corresponding source file, if any. If one exists, the flags for that file
00141   # should be good enough.
00142   if IsHeaderFile( filename ):
00143     basename = os.path.splitext( filename )[ 0 ]
00144     for extension in SOURCE_EXTENSIONS:
00145       replacement_file = basename + extension
00146       if os.path.exists( replacement_file ):
00147         compilation_info = database.GetCompilationInfoForFile(
00148           replacement_file )
00149         if compilation_info.compiler_flags_:
00150           return compilation_info
00151     return None
00152   return database.GetCompilationInfoForFile( filename )
00153 
00154 
00155 def FlagsForFile( filename, **kwargs ):
00156   if database:
00157     # Bear in mind that compilation_info.compiler_flags_ does NOT return a
00158     # python list, but a "list-like" StringVec object
00159     compilation_info = GetCompilationInfoForFile( filename )
00160     if not compilation_info:
00161       return None
00162 
00163     final_flags = MakeRelativePathsInFlagsAbsolute(
00164       compilation_info.compiler_flags_,
00165       compilation_info.compiler_working_dir_ )
00166 
00167   else:
00168     relative_to = DirectoryOfThisScript()
00169     final_flags = MakeRelativePathsInFlagsAbsolute( flags, relative_to )
00170 
00171   return {
00172     'flags': final_flags,
00173     'do_cache': True
00174   }


straf_recovery
Author(s):
autogenerated on Sat Jun 8 2019 20:37:23