msvc: handle filename extensions for incdetect based on the compiler language

It is possible, albeit possibly inadvisable, for the exact combination
of MSVC and "$CXX has C++ specific flags in it" to occur. When this
happens, and cl.exe is given a filename ending in .c, it complains that
you cannot compile a .c file with that option.

Instead, pick the first filename matching that language and use that as
the temporary filename. This more or less matches what we do in
compiler-time checks. And it's the proper thing to do, rather than
assume that cl.exe, when detected as the current C++ compiler, can
*also* compile C because it's *also* a C compiler.

Fixes #11257
pull/11260/head
Eli Schwartz 2 years ago committed by Xavier Claessens
parent 25e73b6c9e
commit 9f12f6e158
  1. 5
      mesonbuild/backend/ninjabackend.py

@ -523,8 +523,9 @@ class NinjaBackend(backends.Backend):
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 @@ class NinjaBackend(backends.Backend):
# 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()

Loading…
Cancel
Save