From e1ffae0580259343be7665c6b2f014fe71b8c05c Mon Sep 17 00:00:00 2001 From: Daniel Stone Date: Wed, 12 Apr 2017 16:00:48 +0100 Subject: 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) --- docs/markdown/snippets/get-supported-arguments.md | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 docs/markdown/snippets/get-supported-arguments.md (limited to 'docs/markdown/snippets') 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) -- cgit v1.1