1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
|
Description: Search for common out of tree build directories
The default file picks up the database file automatically if it
sits in the project root – but using an out-of-tree build as is
recommended with CMake it will be elsewhere and the user would
need to link it in. The user can still do that e.g. to work around
misdetections, but if none is present, but its a CMake project
we look into common directory name choices for the file and use it
if we find it as that is likely what the user wants.
.
For upstream this is of no interest as they don't want to provide
a generic example and instead expect every user to make explicit
configuration choices for individual projects.
Author: David Kalnischkies <david@kalnischkies.de>
Forwarded: not-needed
--- a/.ycm_extra_conf.py
+++ b/.ycm_extra_conf.py
@@ -68,12 +68,17 @@
#
# You can get CMake to generate this file for you by adding:
# set( CMAKE_EXPORT_COMPILE_COMMANDS 1 )
-# to your CMakeLists.txt file.
+# to your CMakeLists.txt file OR run cmake with
+# -DCMAKE_EXPORT_COMPILE_COMMANDS=ON
#
# 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 = ''
+# common names for subdirectories in which compilation database could be found
+try_compilation_database_folders_fixed = [ 'build.linux', 'build-linux', 'build', ]
+try_compilation_database_folders_arch = [ 'build.', 'build-', ]
+
def IsHeaderFile( filename ):
extension = p.splitext( filename )[ 1 ]
@@ -90,13 +95,35 @@
return filename
+def FindCompileCommandDirectory ( basedirs, variants ):
+ for basedir in basedirs:
+ for variant in variants:
+ if p.exists( basedir + variant + '/compile_commands.json' ):
+ return basedir + variant
+ return ''
+
+
def Settings_CFamily( kwargs ):
# Do NOT import ycm_core at module scope.
import ycm_core
global database
- if database is None and p.exists( compilation_database_folder ):
- database = ycm_core.CompilationDatabase( compilation_database_folder )
+ if database is None:
+ global compilation_database_folder
+ if not compilation_database_folder:
+ if not p.exists( 'compile_commands.json' ) and p.exists( 'CMakeLists.txt' ):
+ try_architectures = []
+ import platform
+ try_architectures.append(platform.machine().lower())
+ import subprocess
+ try_architectures.append(subprocess.run(['dpkg', '--print-architecture'], capture_output=True, text=True).stdout.strip())
+ compilation_database_folder = FindCompileCommandDirectory( try_compilation_database_folders_arch, try_architectures )
+
+ if not compilation_database_folder:
+ compilation_database_folder = FindCompileCommandDirectory( try_compilation_database_folders_fixed, [''])
+
+ if p.exists( compilation_database_folder ):
+ database = ycm_core.CompilationDatabase( compilation_database_folder )
# If the file is a header, try to find the corresponding source file and
# retrieve its flags from the compilation database if using one. This is
|