#!/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')