aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAqua-sama <aqua@iserlohn-fortress.net>2019-01-03 15:32:11 +0100
committerAqua-sama <aqua@iserlohn-fortress.net>2019-01-03 15:32:11 +0100
commit3c1af94691272b3ae04d72dba29a4f4bd54a8355 (patch)
tree3ab8394f8e090ed0b8d185a733988e55bd1a2335
parentAdd Edit menu (diff)
downloadsmolbote-3c1af94691272b3ae04d72dba29a4f4bd54a8355.tar.xz
Add script to generate QtCreator project files
-rwxr-xr-xtools/gen-qtcreator-config.py65
1 files changed, 65 insertions, 0 deletions
diff --git a/tools/gen-qtcreator-config.py b/tools/gen-qtcreator-config.py
new file mode 100755
index 0000000..3035fdb
--- /dev/null
+++ b/tools/gen-qtcreator-config.py
@@ -0,0 +1,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')