-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy path.ycm_extra_conf.py
145 lines (131 loc) · 4.74 KB
/
.ycm_extra_conf.py
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
# Copyright Matus Chochlik.
# Distributed under the Boost Software License, Version 1.0.
# See accompanying file LICENSE_1_0.txt or copy at
# http://www.boost.org/LICENSE_1_0.txt
import os
import sys
import subprocess
#------------------------------------------------------------------------------#
def thisDir():
return os.path.dirname(os.path.abspath(__file__))
#------------------------------------------------------------------------------#
def absPath(path, work_dir = thisDir()):
if not os.path.isabs(path):
path = os.path.join(work_dir, path)
return os.path.realpath(path)
#------------------------------------------------------------------------------#
def makeOptionPathsAbsolute(old_opts, work_dir = thisDir()):
new_opts = list()
make_next_abs = False
path_flags = ['-include', '-isystem', '-I', '-iquote', '--sysroot=']
for opt in old_opts:
new_opt = opt
if make_next_abs:
new_opt = absPath(opt, work_dir)
make_next_abs = False
else:
for path_flag in path_flags:
if opt == path_flag:
make_next_abs = True
break
if opt.startswith(path_flag):
path = opt[len(path_flag):]
new_opt = path_flag + MakePathAbsolute(path, work_dir)
break
new_opts += [new_opt]
return new_opts
#------------------------------------------------------------------------------#
def binaryDir():
try:
with open(os.path.join(thisDir(), "BINARY_DIR"), "rt") as bdf:
return absPath(bdf.read(), thisDir())
except: pass
return os.path.join(thisDir(), "_build")
#------------------------------------------------------------------------------#
compiler_opts = [
'-DEAGINE_YCM',
'-pedantic',
'-Wall',
'-Weverything',
'-Werror',
'-Wno-c++98-compat',
'-Wno-c++98-compat-pedantic',
'-Wno-undef',
'-Wno-global-constructors',
'-Wno-exit-time-destructors',
'-Wno-date-time',
'-Wno-weak-vtables',
'-Wno-padded',
'-Wno-missing-prototypes',
'-Wno-switch-enum',
'-std=c++17',
'-x', 'c++',
]
#------------------------------------------------------------------------------#
def scan_for_system_include_dirs():
try:
clang_args = ['clang++', '-xc++', '-E', '-v', '-']
clang_proc = subprocess.Popen(
clang_args,
stdin=open("/dev/null"),
stdout=subprocess.PIPE,
stderr=subprocess.PIPE
)
unused, output = clang_proc.communicate()
tokens = [t.decode('utf8') for t in output.split()]
result = []
for i in range(1, len(tokens)):
if tokens[i-1].endswith("-isystem"):
if os.path.isdir(tokens[i]):
result.append(tokens[i])
return result
except Exception as err:
print(err)
return [
"/usr/include",
"/usr/local/include"
]
#------------------------------------------------------------------------------#
system_include_dirs = scan_for_system_include_dirs()
#------------------------------------------------------------------------------#
project_include_dirs = [
os.path.join(binaryDir(), "include"),
'include',
'implement',
'third_party/include',
'third_party/asio/asio/include',
'third_party/rapidjson/include',
'source/utils'
]
#------------------------------------------------------------------------------#
def FlagsForFile(filename, ** kwargs):
final_opts = compiler_opts
for path in system_include_dirs:
apath = absPath(path)
if os.path.isdir(apath):
final_opts += ['-isystem', apath]
for path in project_include_dirs:
apath = absPath(path)
if os.path.isdir(apath):
final_opts += ['-I', apath]
path, ext = os.path.splitext(filename)
if ext in [".hpp", ".inl", ".cpp", ".h"]:
final_opts += ['-include', 'include/oglplus/gl.hpp']
final_opts += ['-include', 'include/oalplus/al.hpp']
final_opts += ['-include', 'include/eglplus/egl.hpp']
if ext == ".inl":
def repl(x): return 'include' if name == 'implement' else name
path = os.path.sep.join([repl(name) for name in path.split(os.path.sep)])
inl_header = path + '.hpp'
if os.path.isfile(inl_header):
final_opts += ['-include', inl_header]
return {
'flags': makeOptionPathsAbsolute(final_opts),
'do_cache': True
}
#------------------------------------------------------------------------------#
if __name__ == "__main__":
for arg in sys.argv[1:]:
if os.path.isfile(arg):
print(FlagsForFile(arg))
#------------------------------------------------------------------------------#