You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

155 lines
5.0 KiB

  1. # This file is NOT licensed under the GPLv3, which is the license for the rest
  2. # of YouCompleteMe.
  3. #
  4. # Here's the license text for this file:
  5. #
  6. # This is free and unencumbered software released into the public domain.
  7. #
  8. # Anyone is free to copy, modify, publish, use, compile, sell, or
  9. # distribute this software, either in source code form or as a compiled
  10. # binary, for any purpose, commercial or non-commercial, and by any
  11. # means.
  12. #
  13. # In jurisdictions that recognize copyright laws, the author or authors
  14. # of this software dedicate any and all copyright interest in the
  15. # software to the public domain. We make this dedication for the benefit
  16. # of the public at large and to the detriment of our heirs and
  17. # successors. We intend this dedication to be an overt act of
  18. # relinquishment in perpetuity of all present and future rights to this
  19. # software under copyright law.
  20. #
  21. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  22. # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  23. # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
  24. # IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
  25. # OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
  26. # ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  27. # OTHER DEALINGS IN THE SOFTWARE.
  28. #
  29. # For more information, please refer to <http://unlicense.org/>
  30. import os
  31. import ycm_core
  32. # These are the compilation flags that will be used in case there's no
  33. # compilation database set (by default, one is not set).
  34. # CHANGE THIS LIST OF FLAGS. YES, THIS IS THE DROID YOU HAVE BEEN LOOKING FOR.
  35. flags = [
  36. '-Wall',
  37. '-Wextra',
  38. '-Werror',
  39. '-Wc++98-compat',
  40. '-Wno-long-long',
  41. '-Wno-variadic-macros',
  42. '-fexceptions',
  43. '-DNDEBUG',
  44. '-DUSE_CLANG_COMPLETER',
  45. # THIS IS IMPORTANT! Without a "-std=<something>" flag, clang won't know which
  46. # language to use when compiling headers. So it will guess. Badly. So C++
  47. # headers will be compiled as C headers. You don't want that so ALWAYS specify
  48. # a "-std=<something>".
  49. # For a C project, you would set this to something like 'c99' instead of
  50. # 'c++11'.
  51. '-std=c99',
  52. # ...and the same thing goes for the magic -x option which specifies the
  53. # language that the files to be compiled are written in. This is mostly
  54. # relevant for c++ headers.
  55. # For a C project, you would set this to 'c' instead of 'c++'.
  56. '-x',
  57. 'c',
  58. '-isystem',
  59. '../BoostParts',
  60. '-isystem',
  61. # This path will only work on OS X, but extra paths that don't exist are not
  62. # harmful
  63. '/System/Library/Frameworks/Python.framework/Headers',
  64. '-isystem',
  65. '../llvm/include',
  66. '-isystem',
  67. '../llvm/tools/clang/include',
  68. '-I',
  69. '.',
  70. '-I',
  71. './ClangCompleter',
  72. '-isystem',
  73. './tests/gmock/gtest',
  74. '-isystem',
  75. './tests/gmock/gtest/include',
  76. '-isystem',
  77. './tests/gmock',
  78. '-isystem',
  79. './tests/gmock/include'
  80. ]
  81. # Set this to the absolute path to the folder (NOT the file!) containing the
  82. # compile_commands.json file to use that instead of 'flags'. See here for
  83. # more details: http://clang.llvm.org/docs/JSONCompilationDatabase.html
  84. #
  85. # Most projects will NOT need to set this to anything; you can just change the
  86. # 'flags' list of compilation flags. Notice that YCM itself uses that approach.
  87. compilation_database_folder = ''
  88. if compilation_database_folder:
  89. database = ycm_core.CompilationDatabase( compilation_database_folder )
  90. else:
  91. database = None
  92. def DirectoryOfThisScript():
  93. return os.path.dirname( os.path.abspath( __file__ ) )
  94. def MakeRelativePathsInFlagsAbsolute( flags, working_directory ):
  95. if not working_directory:
  96. return list( flags )
  97. new_flags = []
  98. make_next_absolute = False
  99. path_flags = [ '-isystem', '-I', '-iquote', '--sysroot=' ]
  100. for flag in flags:
  101. new_flag = flag
  102. if make_next_absolute:
  103. make_next_absolute = False
  104. if not flag.startswith( '/' ):
  105. new_flag = os.path.join( working_directory, flag )
  106. for path_flag in path_flags:
  107. if flag == path_flag:
  108. make_next_absolute = True
  109. break
  110. if flag.startswith( path_flag ):
  111. path = flag[ len( path_flag ): ]
  112. new_flag = path_flag + os.path.join( working_directory, path )
  113. break
  114. if new_flag:
  115. new_flags.append( new_flag )
  116. return new_flags
  117. def FlagsForFile( filename ):
  118. if database:
  119. # Bear in mind that compilation_info.compiler_flags_ does NOT return a
  120. # python list, but a "list-like" StringVec object
  121. compilation_info = database.GetCompilationInfoForFile( filename )
  122. final_flags = MakeRelativePathsInFlagsAbsolute(
  123. compilation_info.compiler_flags_,
  124. compilation_info.compiler_working_dir_ )
  125. # NOTE: This is just for YouCompleteMe; it's highly likely that your project
  126. # does NOT need to remove the stdlib flag. DO NOT USE THIS IN YOUR
  127. # ycm_extra_conf IF YOU'RE NOT 100% YOU NEED IT.
  128. try:
  129. final_flags.remove( '-stdlib=libc++' )
  130. except ValueError:
  131. pass
  132. else:
  133. relative_to = DirectoryOfThisScript()
  134. final_flags = MakeRelativePathsInFlagsAbsolute( flags, relative_to )
  135. return {
  136. 'flags': final_flags,
  137. 'do_cache': True
  138. }