Repository: mesonbuild/meson

Issue:
Cross compile with cmake module and -std=c++1y flag
When I cross compile a cmake project with the cmake module I get the following error when this project uses the `-std=c++1y` flag:

```
ERROR: Value "c++1y" for combo option is not one of the choices. Possible choices are: "none", "c++98", "c++03", "c++11", "c++14", "c++17", "c++1z", "c++2a", "gnu++03", "gnu++11", "gnu++14", "gnu++17", "gnu++1z", "gnu++2a".
```

and this is the output from `meson-log.txt`:

```
Compiler accepts -std=gnu++17: YES
Running compile:
Working directory:  /usr/project/build/meson-private/tmp3ljav2du
Command line:  /usr/bin/x86_64-w64-mingw32.static-g++ /usr/project/build/meson-private/tmp3ljav2du/testfile.cpp -o /usr/project/build/meson-private/tmp3ljav2du/output.obj -pipe -c -O0 -fpermissive --print-search-dirs 

Code:
 
Compiler stdout:
 install: /usr/lib/gcc/x86_64-w64-mingw32.static/9.3.0/
programs: =/usr/libexec/gcc/x86_64-w64-mingw32.static/9.3.0/:/usr/libexec/gcc/x86_64-w64-mingw32.static/9.3.0/:/usr/libexec/gcc/x86_64-w64-mingw32.static/:/usr/lib/gcc/x86_64-w64-mingw32.static/9.3.0/:/usr/lib/gcc/x86_64-w64-mingw32.static/:/usr/lib/gcc/x86_64-w64-mingw32.static/9.3.0/../../../../x86_64-w64-mingw32.static/bin/x86_64-w64-mingw32.static/9.3.0/:/usr/lib/gcc/x86_64-w64-mingw32.static/9.3.0/../../../../x86_64-w64-mingw32.static/bin/
libraries: =/usr/lib/gcc/x86_64-w64-mingw32.static/9.3.0/:/usr/lib/gcc/x86_64-w64-mingw32.static/9.3.0/../../../../x86_64-w64-mingw32.static/lib/x86_64-w64-mingw32.static/9.3.0/:/usr/lib/gcc/x86_64-w64-mingw32.static/9.3.0/../../../../x86_64-w64-mingw32.static/lib/../lib/:/usr/x86_64-w64-mingw32.static/mingw/lib/x86_64-w64-mingw32.static/9.3.0/:/usr/x86_64-w64-mingw32.static/mingw/lib/../lib/:/usr/lib/gcc/x86_64-w64-mingw32.static/9.3.0/../../../../x86_64-w64-mingw32.static/lib/:/usr/x86_64-w64-mingw32.static/mingw/lib/

Compiler stderr:
 

ERROR: Value "c++1y" for combo option is not one of the choices. Possible choices are: "none", "c++98", "c++03", "c++11", "c++14", "c++17", "c++1z", "c++2a", "gnu++03", "gnu++11", "gnu++14", "gnu++17", "gnu++1z", "gnu++2a".
```



Discussion:

Resolving patch:
diff --git a/mesonbuild/cmake/interpreter.py b/mesonbuild/cmake/interpreter.py
--- a/mesonbuild/cmake/interpreter.py
+++ b/mesonbuild/cmake/interpreter.py
@@ -289,7 +289,15 @@ def postprocess(self, output_target_map: OutputTargetMap, root_src_dir: str, sub
             for j in self.compile_opts[i]:
                 m = ConverterTarget.std_regex.match(j)
                 if m:
-                    self.override_options += ['{}_std={}'.format(i, m.group(2))]
+                    std = m.group(2)
+                    if std not in self._all_lang_stds(i):
+                        mlog.warning(
+                            'Unknown {}_std "{}" -> Ingoring. Try setting the project'
+                            'level {}_std if build errors occur.'.format(i, std),
+                            once=True
+                        )
+                        continue
+                    self.override_options += ['{}_std={}'.format(i, std)]
                 elif j in ['-fPIC', '-fpic', '-fPIE', '-fpie']:
                     self.pie = True
                 elif j in blacklist_compiler_flags:
@@ -539,6 +547,13 @@ def _all_source_suffixes(self) -> T.List[str]:
             suffixes += [x for x in exts]
         return suffixes
 
+    @lru_cache(maxsize=None)
+    def _all_lang_stds(self, lang: str) -> T.List[str]:
+        lang_opts = self.env.coredata.compiler_options.build.get(lang, None)
+        if not lang_opts or 'std' not in lang_opts:
+            return []
+        return lang_opts['std'].choices
+
     def process_inter_target_dependencies(self):
         # Move the dependencies from all transfer_dependencies_from to the target
         to_process = list(self.depends)


Test patch: