diff --git a/template.py b/template.py index 2985a70..d9cb772 100644 --- a/template.py +++ b/template.py @@ -30,12 +30,28 @@ import os import ycm_core +import re +import subprocess + flags = [ # INSERT FLAGS HERE ] +def LoadSystemIncludes(): + regex = re.compile(ur'(?:\#include \<...\> search starts here\:)(?P.*?)(?:End of search list)', re.DOTALL); + process = subprocess.Popen(['clang', '-v', '-E', '-x', 'c++', '-'], stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE); + process_out, process_err = process.communicate(''); + output = process_out + process_err; + includes = []; + for p in re.search(regex, output).group('list').split('\n'): + p = p.strip(); + if len(p) > 0 and p.find('(framework directory)') < 0: + includes.append('-isystem'); + includes.append(p); + return includes; + # 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 @@ -54,6 +70,8 @@ database = None SOURCE_EXTENSIONS = [ '.C', '.cpp', '.cxx', '.cc', '.c', '.m', '.mm' ] +systemIncludes = LoadSystemIncludes(); +flags = flags + systemIncludes; def DirectoryOfThisScript(): return os.path.dirname( os.path.abspath( __file__ ) ) @@ -121,7 +139,7 @@ def FlagsForFile( filename, **kwargs ): final_flags = MakeRelativePathsInFlagsAbsolute( compilation_info.compiler_flags_, - compilation_info.compiler_working_dir_ ) + compilation_info.compiler_working_dir_ ) + systemIncludes else: relative_to = DirectoryOfThisScript()