YouCompleteMe/cpp/ycm/.ycm_clang_options.py
2013-01-19 18:53:30 -08:00

91 lines
2.4 KiB
Python

import os
import ycm_core
from clang_helpers import PrepareClangFlags
# Set this to the absolute path to the folder containing the
# compilation_database.json file to use that instead of 'flags'. See here for
# more details: http://clang.llvm.org/docs/JSONCompilationDatabase.html
compilation_database_folder = ''
# These are the compilation flags that will be used in case there's no
# compilation database set.
flags = [
'-Wall',
'-Wextra',
'-Werror',
'-Wc++98-compat',
'-Wno-long-long',
'-Wno-variadic-macros',
'-fexceptions',
'-DNDEBUG',
# THIS IS IMPORTANT! Without a "-std=<something>" flag, clang won't know which
# language to use when compiling headers. So it will guess. Badly. So C++
# headers will be compiled as C headers. You don't want that so ALWAYS specify
# a "-std=<something>"
'-std=c++11',
# ...and the same thing goes for the magic -x option which specifies the
# language that the files to be compiled are written in. This is mostly
# relevant for c++ headers.
'-x',
'c++',
'-isystem',
'../BoostParts',
'-isystem',
# This path will only work on OS X, but extra paths that don't exist are not
# harmful
'/System/Library/Frameworks/Python.framework/Headers',
'-isystem',
'../llvm/include',
'-isystem',
'../llvm/tools/clang/include',
'-I',
'.',
'-isystem',
'./tests/gmock/gtest',
'-isystem',
'./tests/gmock/gtest/include',
'-isystem',
'./tests/gmock',
'-isystem',
'./tests/gmock/include'
]
if compilation_database_folder:
database = ycm_core.CompilationDatabase( compilation_database_folder )
else:
database = None
def DirectoryOfThisScript():
return os.path.dirname( os.path.abspath( __file__ ) )
def MakeAbsoluteIfRelativePath( path ):
if not path.startswith( '.' ):
return path
full_path = os.path.join( DirectoryOfThisScript(), path )
return os.path.normpath( full_path )
def FlagsForFile( filename ):
if database:
# Bear in mind that database.FlagsForFile does NOT return a python list, but
# a "list-like" StringVec object
final_flags = PrepareClangFlags( database.FlagsForFile( filename ) )
# NOTE: This is just for YouCompleteMe; it's highly likely that your project
# does NOT need to remove the stdlib flag. DO NOT USE THIS IN YOUR
# ycm_clang_options IF YOU'RE NOT 100% YOU NEED IT.
try:
final_flags.remove( '-stdlib=libc++' )
except ValueError:
pass
else:
final_flags = [ MakeAbsoluteIfRelativePath( x ) for x in flags ]
return {
'flags': final_flags,
'do_cache': True
}