.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 '-fexceptions',
00042 # THIS IS IMPORTANT! Without a "-std=<something>" flag, clang won't know which
00043 # language to use when compiling headers. So it will guess. Badly. So C++
00044 # headers will be compiled as C headers. You don't want that so ALWAYS specify
00045 # a "-std=<something>".
00046 # For a C project, you would set this to something like 'c99' instead of
00047 # 'c++11'.
00048 '-std=c++03',
00049 # ...and the same thing goes for the magic -x option which specifies the
00050 # language that the files to be compiled are written in. This is mostly
00051 # relevant for c++ headers.
00052 # For a C project, you would set this to 'c' instead of 'c++'.
00053 '-x',
00054 'c++',
00055 '-isystem', "/opt/ros/%s/include" % os.environ.get('ROS_DISTRO', 'indigo'),
00056 '-isystem', '/usr/include/Poco',
00057 '-isystem', '/usr/include',
00058 '-I', '.',
00059 '-I', './include',
00060 '-I', '../devel/include',
00061 # ROS flags
00062 '-DROSCONSOLE_BACKEND_LOG4CXX',
00063 #'-DROS_PACKAGE_NAME="mavros"',
00064 ]
00065 
00066 # Set this to the absolute path to the folder (NOT the file!) containing the
00067 # compile_commands.json file to use that instead of 'flags'. See here for
00068 # more details: http://clang.llvm.org/docs/JSONCompilationDatabase.html
00069 #
00070 # You can get CMake to generate this file for you by adding:
00071 #   set( CMAKE_EXPORT_COMPILE_COMMANDS 1 )
00072 # to your CMakeLists.txt file.
00073 #
00074 # Most projects will NOT need to set this to anything; you can just change the
00075 # 'flags' list of compilation flags. Notice that YCM itself uses that approach.
00076 compilation_database_folder = ''
00077 
00078 if os.path.exists( compilation_database_folder ):
00079   database = ycm_core.CompilationDatabase( compilation_database_folder )
00080 else:
00081   database = None
00082 
00083 SOURCE_EXTENSIONS = [ '.cpp', '.cxx', '.cc', '.c', '.m', '.mm' ]
00084 
00085 def DirectoryOfThisScript():
00086   return os.path.dirname( os.path.abspath( __file__ ) )
00087 
00088 
00089 def MakeRelativePathsInFlagsAbsolute( flags, working_directory ):
00090   if not working_directory:
00091     return list( flags )
00092   new_flags = []
00093   make_next_absolute = False
00094   path_flags = [ '-isystem', '-I', '-iquote', '--sysroot=' ]
00095   for flag in flags:
00096     new_flag = flag
00097 
00098     if make_next_absolute:
00099       make_next_absolute = False
00100       if not flag.startswith( '/' ):
00101         new_flag = os.path.join( working_directory, flag )
00102 
00103     for path_flag in path_flags:
00104       if flag == path_flag:
00105         make_next_absolute = True
00106         break
00107 
00108       if flag.startswith( path_flag ):
00109         path = flag[ len( path_flag ): ]
00110         new_flag = path_flag + os.path.join( working_directory, path )
00111         break
00112 
00113     if new_flag:
00114       new_flags.append( new_flag )
00115   return new_flags
00116 
00117 
00118 def IsHeaderFile( filename ):
00119   extension = os.path.splitext( filename )[ 1 ]
00120   return extension in [ '.h', '.hxx', '.hpp', '.hh' ]
00121 
00122 
00123 def GetCompilationInfoForFile( filename ):
00124   # The compilation_commands.json file generated by CMake does not have entries
00125   # for header files. So we do our best by asking the db for flags for a
00126   # corresponding source file, if any. If one exists, the flags for that file
00127   # should be good enough.
00128   if IsHeaderFile( filename ):
00129     basename = os.path.splitext( filename )[ 0 ]
00130     for extension in SOURCE_EXTENSIONS:
00131       replacement_file = basename + extension
00132       if os.path.exists( replacement_file ):
00133         compilation_info = database.GetCompilationInfoForFile(
00134           replacement_file )
00135         if compilation_info.compiler_flags_:
00136           return compilation_info
00137     return None
00138   return database.GetCompilationInfoForFile( filename )
00139 
00140 
00141 def FlagsForFile( filename, **kwargs ):
00142   if database:
00143     # Bear in mind that compilation_info.compiler_flags_ does NOT return a
00144     # python list, but a "list-like" StringVec object
00145     compilation_info = GetCompilationInfoForFile( filename )
00146     if not compilation_info:
00147       return None
00148 
00149     final_flags = MakeRelativePathsInFlagsAbsolute(
00150       compilation_info.compiler_flags_,
00151       compilation_info.compiler_working_dir_ )
00152   else:
00153     relative_to = DirectoryOfThisScript()
00154     final_flags = MakeRelativePathsInFlagsAbsolute( flags, relative_to )
00155 
00156   return {
00157     'flags': final_flags,
00158     'do_cache': True
00159   }


ntpd_driver
Author(s): Vladimir Ermakov
autogenerated on Thu Jun 6 2019 21:47:01