2013-04-26 18:25:19 -04:00
|
|
|
# This file is NOT licensed under the GPLv3, which is the license for the rest
|
|
|
|
# of YouCompleteMe.
|
|
|
|
#
|
|
|
|
# Here's the license text for this file:
|
|
|
|
#
|
|
|
|
# This is free and unencumbered software released into the public domain.
|
|
|
|
#
|
|
|
|
# Anyone is free to copy, modify, publish, use, compile, sell, or
|
|
|
|
# distribute this software, either in source code form or as a compiled
|
|
|
|
# binary, for any purpose, commercial or non-commercial, and by any
|
|
|
|
# means.
|
|
|
|
#
|
|
|
|
# In jurisdictions that recognize copyright laws, the author or authors
|
|
|
|
# of this software dedicate any and all copyright interest in the
|
|
|
|
# software to the public domain. We make this dedication for the benefit
|
|
|
|
# of the public at large and to the detriment of our heirs and
|
|
|
|
# successors. We intend this dedication to be an overt act of
|
|
|
|
# relinquishment in perpetuity of all present and future rights to this
|
|
|
|
# software under copyright law.
|
|
|
|
#
|
|
|
|
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
|
|
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
|
|
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
|
|
# IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
|
|
|
|
# OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
|
|
|
# ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
|
|
|
# OTHER DEALINGS IN THE SOFTWARE.
|
|
|
|
#
|
|
|
|
# For more information, please refer to <http://unlicense.org/>
|
|
|
|
|
2012-08-01 23:50:35 -04:00
|
|
|
import os
|
2013-01-19 21:53:30 -05:00
|
|
|
import ycm_core
|
2012-08-01 23:50:35 -04:00
|
|
|
|
2013-01-19 21:53:30 -05:00
|
|
|
# These are the compilation flags that will be used in case there's no
|
2013-03-20 21:31:49 -04:00
|
|
|
# compilation database set (by default, one is not set).
|
|
|
|
# CHANGE THIS LIST OF FLAGS. YES, THIS IS THE DROID YOU HAVE BEEN LOOKING FOR.
|
2012-08-01 23:50:35 -04:00
|
|
|
flags = [
|
|
|
|
'-Wall',
|
|
|
|
'-Wextra',
|
|
|
|
'-Werror',
|
|
|
|
'-Wc++98-compat',
|
|
|
|
'-Wno-long-long',
|
|
|
|
'-Wno-variadic-macros',
|
2012-08-11 22:46:22 -04:00
|
|
|
'-fexceptions',
|
2012-08-01 23:50:35 -04:00
|
|
|
'-DNDEBUG',
|
2013-10-26 19:22:43 -04:00
|
|
|
# You 100% do NOT need -DUSE_CLANG_COMPLETER in your flags; only the YCM
|
|
|
|
# source code needs it.
|
2013-01-23 20:23:51 -05:00
|
|
|
'-DUSE_CLANG_COMPLETER',
|
2012-08-05 15:55:03 -04:00
|
|
|
# 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
|
2013-01-23 00:05:32 -05:00
|
|
|
# a "-std=<something>".
|
|
|
|
# For a C project, you would set this to something like 'c99' instead of
|
|
|
|
# 'c++11'.
|
2012-08-05 15:55:03 -04:00
|
|
|
'-std=c++11',
|
2012-08-11 22:46:22 -04:00
|
|
|
# ...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.
|
2013-01-23 00:05:32 -05:00
|
|
|
# For a C project, you would set this to 'c' instead of 'c++'.
|
2012-08-11 22:46:22 -04:00
|
|
|
'-x',
|
|
|
|
'c++',
|
2012-08-01 23:50:35 -04:00
|
|
|
'-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',
|
|
|
|
'.',
|
2013-02-10 22:41:03 -05:00
|
|
|
'-I',
|
|
|
|
'./ClangCompleter',
|
2012-08-01 23:50:35 -04:00
|
|
|
'-isystem',
|
|
|
|
'./tests/gmock/gtest',
|
|
|
|
'-isystem',
|
|
|
|
'./tests/gmock/gtest/include',
|
|
|
|
'-isystem',
|
|
|
|
'./tests/gmock',
|
|
|
|
'-isystem',
|
|
|
|
'./tests/gmock/include'
|
|
|
|
]
|
|
|
|
|
2013-03-20 21:31:49 -04:00
|
|
|
# Set this to the absolute path to the folder (NOT the file!) containing the
|
|
|
|
# compile_commands.json file to use that instead of 'flags'. See here for
|
|
|
|
# more details: http://clang.llvm.org/docs/JSONCompilationDatabase.html
|
|
|
|
#
|
|
|
|
# Most projects will NOT need to set this to anything; you can just change the
|
|
|
|
# 'flags' list of compilation flags. Notice that YCM itself uses that approach.
|
|
|
|
compilation_database_folder = ''
|
|
|
|
|
2013-01-19 21:53:30 -05:00
|
|
|
if compilation_database_folder:
|
|
|
|
database = ycm_core.CompilationDatabase( compilation_database_folder )
|
|
|
|
else:
|
|
|
|
database = None
|
|
|
|
|
|
|
|
|
2012-08-01 23:50:35 -04:00
|
|
|
def DirectoryOfThisScript():
|
|
|
|
return os.path.dirname( os.path.abspath( __file__ ) )
|
|
|
|
|
|
|
|
|
2013-01-22 19:30:49 -05:00
|
|
|
def MakeRelativePathsInFlagsAbsolute( flags, working_directory ):
|
|
|
|
if not working_directory:
|
2013-05-29 22:05:02 -04:00
|
|
|
return list( flags )
|
2013-01-22 19:30:49 -05:00
|
|
|
new_flags = []
|
|
|
|
make_next_absolute = False
|
|
|
|
path_flags = [ '-isystem', '-I', '-iquote', '--sysroot=' ]
|
|
|
|
for flag in flags:
|
2013-01-30 00:40:42 -05:00
|
|
|
new_flag = flag
|
2012-08-01 23:50:35 -04:00
|
|
|
|
2013-01-22 19:30:49 -05:00
|
|
|
if make_next_absolute:
|
|
|
|
make_next_absolute = False
|
|
|
|
if not flag.startswith( '/' ):
|
2013-01-30 00:40:42 -05:00
|
|
|
new_flag = os.path.join( working_directory, flag )
|
2013-01-22 19:30:49 -05:00
|
|
|
|
|
|
|
for path_flag in path_flags:
|
|
|
|
if flag == path_flag:
|
|
|
|
make_next_absolute = True
|
|
|
|
break
|
|
|
|
|
|
|
|
if flag.startswith( path_flag ):
|
|
|
|
path = flag[ len( path_flag ): ]
|
2013-01-30 00:40:42 -05:00
|
|
|
new_flag = path_flag + os.path.join( working_directory, path )
|
2013-01-22 19:30:49 -05:00
|
|
|
break
|
|
|
|
|
2013-01-30 00:40:42 -05:00
|
|
|
if new_flag:
|
|
|
|
new_flags.append( new_flag )
|
2013-01-22 19:30:49 -05:00
|
|
|
return new_flags
|
2012-08-01 23:50:35 -04:00
|
|
|
|
|
|
|
|
2013-10-26 19:22:43 -04:00
|
|
|
def FlagsForFile( filename, **kwargs ):
|
2013-01-19 21:53:30 -05:00
|
|
|
if database:
|
2013-01-24 22:18:09 -05:00
|
|
|
# Bear in mind that compilation_info.compiler_flags_ does NOT return a
|
|
|
|
# python list, but a "list-like" StringVec object
|
2013-01-23 20:23:51 -05:00
|
|
|
compilation_info = database.GetCompilationInfoForFile( filename )
|
2013-05-19 13:48:23 -04:00
|
|
|
final_flags = MakeRelativePathsInFlagsAbsolute(
|
|
|
|
compilation_info.compiler_flags_,
|
|
|
|
compilation_info.compiler_working_dir_ )
|
2013-01-19 21:53:30 -05:00
|
|
|
|
|
|
|
# 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
|
2013-01-24 12:59:21 -05:00
|
|
|
# ycm_extra_conf IF YOU'RE NOT 100% YOU NEED IT.
|
2013-01-19 21:53:30 -05:00
|
|
|
try:
|
|
|
|
final_flags.remove( '-stdlib=libc++' )
|
|
|
|
except ValueError:
|
|
|
|
pass
|
|
|
|
else:
|
2013-01-22 19:30:49 -05:00
|
|
|
relative_to = DirectoryOfThisScript()
|
|
|
|
final_flags = MakeRelativePathsInFlagsAbsolute( flags, relative_to )
|
2013-01-19 21:53:30 -05:00
|
|
|
|
2012-08-03 13:26:11 -04:00
|
|
|
return {
|
2013-01-19 21:53:30 -05:00
|
|
|
'flags': final_flags,
|
2012-08-03 13:26:11 -04:00
|
|
|
'do_cache': True
|
|
|
|
}
|