title: Handling Meson build options with multiple buildtypes
body: <p>Having read the Meson site pages (which are generally high quality), <strong>I'm still unsure about the intended best practice to handle different options for different buildtypes.</strong></p>
  
  <p>So to specify a debug build:</p>
  
  <pre><code>meson [srcdir] --buildtype=debug
  </code></pre>
  
  <p>Or to specify a release build:</p>
  
  <pre><code>meson [srcdir] --buildtype=release
  </code></pre>
  
  <p>However, if I want to add <code>b_sanitize=address</code> (or other arbitrary complex set of arguments) only for debug builds and <code>b_ndebug=true</code> only for release builds, I would do:</p>
  
  <pre><code>meson [srcdir] --buildtype=debug -Db_sanitize=address ...
  meson [srcdir] --buildtype=release -Db_ndebug=true ...
  </code></pre>
  
  <p>However, it's more of a pain to add a bunch of custom arguments on the command line, and to me it seems neater to put that in the meson.build file.
  So I know I can set some built in options thusly:</p>
  
  <pre><code>project('myproject', ['cpp'],
          default_options : ['cpp_std=c++14',
                             'b_ndebug=true'])
  </code></pre>
  
  <p>But they are unconditionally set.</p>
  
  <p>So a condition would look something like this:</p>
  
  <pre><code>if get_option('buildtype').startswith('release')
      add_project_arguments('-DNDEBUG', language : ['cpp'])
  endif
  </code></pre>
  
  <p>Which is one way to do it, however, it would seem the <code>b_ndebug=true</code> way would be preferred to <code>add_project_arguments('-DNDEBUG')</code>, because it is portable.</p>
  
  <p><strong>How would the portable-style build options be conditionally set within the Meson script?</strong></p>
  
  <p>Additionally, <code>b_sanitize=address</code> is set without any test whether the compiler supports it. I would prefer for it to check first if it is supported (because the library might be missing, for example):</p>
  
  <pre><code>if meson.get_compiler('cpp').has_link_argument('-fsanitize=address')
      add_project_arguments('-fsanitize=address', language : ['cpp'])
      add_project_link_arguments('-fsanitize=address', language : ['cpp'])
  endif
  </code></pre>
  
  <p><strong>Is it possible to have the built-in portable-style build options (such as <code>b_sanitize</code>) have a check if they are supported?</strong></p>