Repository: mesonbuild/meson

Issue:
[UWP] Could not determine vs dep dependency prefix string
**Describe the bug**
thorvg fails to configure with: 
`ERROR: Could not determine vs dep dependency prefix string. output: b"Microsoft (R) C/C++ Optimizing Compiler Version 19.34.31937 for x64\r\nCopyright (C) Microsoft Corporation.  All rights reserved.\r\n\r\ncl : Command line error D8048 : cannot compile C file 'incdetect.c' with the /ZW option\r\n" b''`

cross file:
[meson-x64-uwp-dbg.log](https://github.com/mesonbuild/meson/files/10368128/meson-x64-uwp-dbg.log)
(due to #11143 all flags are passed via the compiler)
configure log:
[config-x64-uwp-dbg-out.log](https://github.com/mesonbuild/meson/files/10368132/config-x64-uwp-dbg-out.log)
meson log:
[config-x64-uwp-dbg-meson-log.txt.log](https://github.com/mesonbuild/meson/files/10368133/config-x64-uwp-dbg-meson-log.txt.log)

pixman for example works fine with the cross file so what is going on here?


Discussion:
Ok what is going on here is that meson is using the wrong compiler flags to compile a `.c` file. It uses cxx instead of c .....
To give more detail. The project thorvg is defined as a cpp project so meson uses the cpp flags for the detection but MSVC sees the `*.c` ending of the file and compiles it as a C file which won't work with the `/ZW` flag. As such meson should add `/TC` or `/TP` flag to inform MSVC how the file should be compiled or change the file ending according to the language it actually checks. 

Resolving patch:
diff --git a/mesonbuild/backend/ninjabackend.py b/mesonbuild/backend/ninjabackend.py
--- a/mesonbuild/backend/ninjabackend.py
+++ b/mesonbuild/backend/ninjabackend.py
@@ -512,8 +512,8 @@ def detect_vs_dep_prefix(self, tempfilename):
         for compiler in self.environment.coredata.compilers.host.values():
             # Have to detect the dependency format
 
-            # IFort on windows is MSVC like, but doesn't have /showincludes
-            if compiler.language == 'fortran':
+            # IFort / masm on windows is MSVC like, but doesn't have /showincludes
+            if compiler.language in {'fortran', 'masm'}:
                 continue
             if compiler.id == 'pgi' and mesonlib.is_windows():
                 # for the purpose of this function, PGI doesn't act enough like MSVC
@@ -523,8 +523,9 @@ def detect_vs_dep_prefix(self, tempfilename):
         else:
             # None of our compilers are MSVC, we're done.
             return open(tempfilename, 'a', encoding='utf-8')
+        filebase = 'incdetect.' + compilers.lang_suffixes[compiler.language][0]
         filename = os.path.join(self.environment.get_scratch_dir(),
-                                'incdetect.c')
+                                filebase)
         with open(filename, 'w', encoding='utf-8') as f:
             f.write(dedent('''\
                 #include<stdio.h>
@@ -536,7 +537,7 @@ def detect_vs_dep_prefix(self, tempfilename):
         # Python strings leads to failure. We _must_ do this detection
         # in raw byte mode and write the result in raw bytes.
         pc = subprocess.Popen(compiler.get_exelist() +
-                              ['/showIncludes', '/c', 'incdetect.c'],
+                              ['/showIncludes', '/c', filebase],
                               cwd=self.environment.get_scratch_dir(),
                               stdout=subprocess.PIPE, stderr=subprocess.PIPE)
         (stdout, stderr) = pc.communicate()


Test patch: