Advertisement
Guest User

Untitled

a guest
Jan 23rd, 2017
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.40 KB | None | 0 0
  1. #Partially stolen from https://bitbucket.org/mblum/libgp/src/2537ea7329ef/.ycm_extra_conf.py
  2. import os
  3. import ycm_core
  4.  
  5. # These are the compilation flags that will be used in case there's no
  6. # compilation database set (by default, one is not set).
  7. # CHANGE THIS LIST OF FLAGS. YES, THIS IS THE DROID YOU HAVE BEEN LOOKING FOR.
  8. flags = [
  9.     '-Wall',
  10.     '-Wextra',
  11.     '-Werror',
  12.     '-Wno-long-long',
  13.     '-Wno-variadic-macros',
  14.     '-fexceptions',
  15.     # THIS IS IMPORTANT! Without a "-std=<something>" flag, clang won't know which
  16.     # language to use when compiling headers. So it will guess. Badly. So C++
  17.     # headers will be compiled as C headers. You don't want that so ALWAYS specify
  18.     # a "-std=<something>".
  19.     # For a C project, you would set this to something like 'c99' instead of
  20.     # 'c++11'.
  21.     '--std=c++11',
  22.     # ...and the same thing goes for the magic -x option which specifies the
  23.     # language that the files to be compiled are written in. This is mostly
  24.     # relevant for c++ headers.
  25.     # For a C project, you would set this to 'c' instead of 'c++'.
  26.     '-x', 'c++',
  27.     # This path will only work on OS X, but extra paths that don't exist are not
  28.     # harmful
  29.     '-isystem', '/System/Library/Frameworks/Python.framework/Headers',
  30.     '-isystem', '/usr/local/include',
  31.     '-isystem', '/usr/local/include/eigen3',
  32.     '-I', 'include'
  33.     '-I.'
  34. ]
  35.  
  36. # Set this to the absolute path to the folder (NOT the file!) containing the
  37. # compile_commands.json file to use that instead of 'flags'. See here for
  38. # more details: http://clang.llvm.org/docs/JSONCompilationDatabase.html
  39. #
  40. # Most projects will NOT need to set this to anything; you can just change the
  41. # 'flags' list of compilation flags. Notice that YCM itself uses that approach.
  42. compilation_database_folder = ''
  43.  
  44. if os.path.exists( compilation_database_folder ):
  45.   database = ycm_core.CompilationDatabase( compilation_database_folder )
  46. else:
  47.   database = None
  48.  
  49.  
  50. def DirectoryOfThisScript():
  51.   return os.path.dirname( os.path.abspath( __file__ ) )
  52.  
  53.  
  54. def MakeRelativePathsInFlagsAbsolute( flags, working_directory ):
  55.   if not working_directory:
  56.     return list( flags )
  57.   new_flags = []
  58.   make_next_absolute = False
  59.   path_flags = [ '-isystem', '-I', '-iquote', '--sysroot=' ]
  60.   for flag in flags:
  61.     new_flag = flag
  62.  
  63.     if make_next_absolute:
  64.       make_next_absolute = False
  65.       if not flag.startswith( '/' ):
  66.         new_flag = os.path.join( working_directory, flag )
  67.  
  68.     for path_flag in path_flags:
  69.       if flag == path_flag:
  70.         make_next_absolute = True
  71.         break
  72.  
  73.       if flag.startswith( path_flag ):
  74.         path = flag[ len( path_flag ): ]
  75.         new_flag = path_flag + os.path.join( working_directory, path )
  76.         break
  77.  
  78.     if new_flag:
  79.       new_flags.append( new_flag )
  80.   return new_flags
  81.  
  82.  
  83. def FlagsForFile( filename ):
  84.   if database:
  85.     # Bear in mind that compilation_info.compiler_flags_ does NOT return a
  86.     # python list, but a "list-like" StringVec object
  87.     compilation_info = database.GetCompilationInfoForFile( filename )
  88.     final_flags = MakeRelativePathsInFlagsAbsolute(
  89.       compilation_info.compiler_flags_,
  90.       compilation_info.compiler_working_dir_ )
  91.   else:
  92.     relative_to = DirectoryOfThisScript()
  93.     final_flags = MakeRelativePathsInFlagsAbsolute( flags, relative_to )
  94.  
  95.   return {
  96.     'flags': final_flags,
  97.     'do_cache': True
  98.   }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement