aboutsummaryrefslogtreecommitdiff
path: root/mesonbuild/mesonlib.py
diff options
context:
space:
mode:
authorJussi Pakkanen <jpakkane@gmail.com>2016-06-01 20:25:14 +0300
committerJussi Pakkanen <jpakkane@gmail.com>2016-06-01 20:25:14 +0300
commit177e286b3c761f461ac55ede934b941384b4bb97 (patch)
tree367e49025a633bb7f5f212769ca3ee5c57cf4510 /mesonbuild/mesonlib.py
parent0482635c1293ecc1148da8236f6b77cd4f21e130 (diff)
downloadmeson-177e286b3c761f461ac55ede934b941384b4bb97.zip
meson-177e286b3c761f461ac55ede934b941384b4bb97.tar.gz
meson-177e286b3c761f461ac55ede934b941384b4bb97.tar.bz2
Can generate config headers without an input file. Closes #549.
Diffstat (limited to 'mesonbuild/mesonlib.py')
-rw-r--r--mesonbuild/mesonlib.py21
1 files changed, 21 insertions, 0 deletions
diff --git a/mesonbuild/mesonlib.py b/mesonbuild/mesonlib.py
index fe831bd..584b3b2 100644
--- a/mesonbuild/mesonlib.py
+++ b/mesonbuild/mesonlib.py
@@ -267,6 +267,27 @@ def do_conf_file(src, dst, confdata):
shutil.copymode(src, dst_tmp)
replace_if_different(dst, dst_tmp)
+def dump_conf_header(ofilename, cdata):
+ with open(ofilename, 'w') as ofile:
+ ofile.write('''/*
+ * Autogenerated by the Meson build system.
+ * Do not edit, your changes will be lost.
+ */
+
+#pragma once
+
+''')
+ for k in sorted(cdata.keys()):
+ v = cdata.get(k)
+ if isinstance(v, bool):
+ if v:
+ ofile.write('#define %s\n\n' % k)
+ else:
+ ofile.write('#undef %s\n\n' % k)
+ elif isinstance(v, (int, str)):
+ ofile.write('#define %s %s\n\n' % (k, v))
+ else:
+ raise MesonException('Unknown data type in configuration file entry: ' + k)
def replace_if_different(dst, dst_tmp):
# If contents are identical, don't touch the file to prevent