import platform import os DIR_OF_THIS_SCRIPT = os.path.abspath( os.path.dirname( __file__ ) ) SOURCE_EXTENSIONS = [ '.cpp', '.cxx', '.cc', '.c', '.m', '.mm' ] # These are the compilation flags that will be used in case there's no # compilation database set (by default, one is not set). # CHANGE THIS LIST OF FLAGS. YES, THIS IS THE DROID YOU HAVE BEEN LOOKING FOR. flags = [ '-Wall', '-Wextra', '-Werror', '-Wno-long-long', '-Wno-variadic-macros', '-fexceptions', '-DNDEBUG', # THIS IS IMPORTANT! Without the '-x' 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 the '-x' flag. # For a C project, you would set this to 'c' instead of 'c++'. '-x', 'c++', ] # Clang automatically sets the '-std=' flag to 'c++14' for MSVC 2015 or later, # which is required for compiling the standard library, and to 'c++11' for older # versions. if platform.system() != 'Windows': flags.append( '-std=c++14' ) def IsHeaderFile( filename ): extension = os.path.splitext( filename )[ 1 ] return extension in [ '.h', '.hxx', '.hpp', '.hh' ] def FindCorrespondingSourceFile( filename ): if IsHeaderFile( filename ): basename = os.path.splitext( filename )[ 0 ] for extension in SOURCE_EXTENSIONS: replacement_file = basename + extension if os.path.exists( replacement_file ): return replacement_file return filename def Settings( **kwargs ): if kwargs[ 'language' ] == 'cfamily': filename = FindCorrespondingSourceFile( kwargs[ 'filename' ] ) return { 'flags': flags, 'include_paths_relative_to_dir': DIR_OF_THIS_SCRIPT, 'override_filename': filename } return {}