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
|
#!/usr/bin/env python3
import argparse
import subprocess
import os
import json
def readable_dir(prospective_dir):
if not os.path.isdir(prospective_dir):
raise Exception("readable_dir:{0} is not a valid path".format(prospective_dir))
if os.access(prospective_dir, os.R_OK):
return prospective_dir
else:
raise Exception("readable_dir:{0} is not a readable dir".format(prospective_dir))
parser = argparse.ArgumentParser(description='Generate QtCreator profject files')
parser.add_argument('--prefix', type=str, default='project', help='Project name prefix')
parser.add_argument('builddir', type=readable_dir, default='.', help='Build directory')
args = parser.parse_args()
# get targets
targets_json = json.loads(subprocess.run(['meson', 'introspect', '--targets', args.builddir], stdout=subprocess.PIPE).stdout.decode('utf8'))
#s = json.dumps(targets_json, indent=4)
#print(s)
targets = []
for target in targets_json:
targets.append(target['id'])
# prefix.files
with open(args.prefix + '.files', 'w') as output:
for target in targets:
files_json = json.loads(subprocess.run(['meson', 'introspect', '--target-files', target, args.builddir], stdout=subprocess.PIPE).stdout.decode('utf8'))
for f in files_json:
output.write(f + '\n')
# includes
incs = set()
defs = set()
deps_json = json.loads(subprocess.run(['meson', 'introspect', '--dependencies', args.builddir], stdout=subprocess.PIPE).stdout.decode('utf8'))
for dep in deps_json:
for arg in dep['compile_args']:
if arg.startswith('-I'):
incs.add(arg)
elif arg.startswith('-D'):
defs.add(arg)
# prefix.includes
with open(args.prefix + '.includes', 'w') as output:
# dependency includes
for include in incs:
output.write(include[2:] + '\n')
# TODO: properly grab autogenerated include locations
for target in targets_json:
output.write(os.path.join(args.builddir, os.path.dirname(target['filename']), target['id']) + '\n')
# prefix.config
with open(args.prefix + '.config', 'w') as output:
for define in defs:
output.write('#define ' + define[2:] + '\n')
|