diff --git a/template.py b/template.py index 2985a70..f4eeba5 100644 --- a/template.py +++ b/template.py @@ -35,10 +35,14 @@ # INSERT FLAGS HERE ] +def DirectoryOfThisScript(): + return os.path.dirname( os.path.abspath( __file__ ) ) + # 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 +# compile_commands.json file to use that instead of 'flags'. By default it is +# set to the directory of this script. See here for more details: +# http://clang.llvm.org/docs/JSONCompilationDatabase.html # # You can get CMake to generate this file for you by adding: # set( CMAKE_EXPORT_COMPILE_COMMANDS 1 ) @@ -46,19 +50,17 @@ # # 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 = '' +compilation_database_folder = DirectoryOfThisScript() -if os.path.exists( compilation_database_folder ): +if os.path.exists( compilation_database_folder ) and \ + os.path.exists( os.path.join( compilation_database_folder, 'CMakeLists.txt' ) ) and \ + os.path.exists( os.path.join( compilation_database_folder, 'compile_commands.json' ) ): database = ycm_core.CompilationDatabase( compilation_database_folder ) else: database = None SOURCE_EXTENSIONS = [ '.C', '.cpp', '.cxx', '.cc', '.c', '.m', '.mm' ] -def DirectoryOfThisScript(): - return os.path.dirname( os.path.abspath( __file__ ) ) - - def MakeRelativePathsInFlagsAbsolute( flags, working_directory ): if not working_directory: return list( flags )