aboutsummaryrefslogtreecommitdiff
path: root/docs/markdown/snippets/get-supported-arguments.md
diff options
context:
space:
mode:
authorDaniel Stone <daniels@collabora.com>2017-04-12 16:00:48 +0100
committerDaniel Stone <daniels@collabora.com>2017-08-31 20:24:20 +0100
commite1ffae0580259343be7665c6b2f014fe71b8c05c (patch)
tree24462ab941900841b2d1e320e2c02fbef0dd992e /docs/markdown/snippets/get-supported-arguments.md
parent7fb1973caca249e284ba6bec7e7a7b2439f9721f (diff)
downloadmeson-e1ffae0580259343be7665c6b2f014fe71b8c05c.zip
meson-e1ffae0580259343be7665c6b2f014fe71b8c05c.tar.gz
meson-e1ffae0580259343be7665c6b2f014fe71b8c05c.tar.bz2
Add Compiler.get_supported_arguments()
Add a helper for the common pattern of: args_to_use = [] foreach arg : candidate_args if cc.has_argument(arg) args_to_use += arg endif endforeach Replaced with: args_to_use = cc.get_supported_arguments(candidate_args)
Diffstat (limited to 'docs/markdown/snippets/get-supported-arguments.md')
-rw-r--r--docs/markdown/snippets/get-supported-arguments.md23
1 files changed, 23 insertions, 0 deletions
diff --git a/docs/markdown/snippets/get-supported-arguments.md b/docs/markdown/snippets/get-supported-arguments.md
new file mode 100644
index 0000000..c0cc9bf
--- /dev/null
+++ b/docs/markdown/snippets/get-supported-arguments.md
@@ -0,0 +1,23 @@
+# Easier handling of supported compiler arguments
+
+A common pattern for handling multiple desired compiler arguments, was to
+test their presence and add them to an array one-by-one, e.g.:
+
+ warning_flags_maybe = [
+ '-Wsomething',
+ '-Wanother-thing',
+ '-Wno-the-other-thing',
+ ]
+ warning_flags = []
+ foreach flag : warning_flags_maybe
+ if cc.has_argument(flag)
+ warning_flags += flag
+ endif
+ endforeach
+ cc.add_project_argument(warning_flags)
+
+A helper has been added for the foreach/has_argument pattern, so you can
+now simply do:
+
+ warning_flags = [ ... ]
+ flags = cc.get_supported_flags(warning_flags)