.C files are now treated as C++ code

pull/8782/head
Volker-Weissmann 4 years ago committed by GitHub
parent a6e9b54b1d
commit 4ca9a16288
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 6
      mesonbuild/compilers/compilers.py
  2. 10
      mesonbuild/mesonlib/universal.py
  3. 6
      test cases/common/2 cpp/cpp.C
  4. 7
      test cases/common/2 cpp/meson.build

@ -51,7 +51,7 @@ lib_suffixes = ('a', 'lib', 'dll', 'dll.a', 'dylib', 'so') # type: T.Tuple[str,
# This means we can't include .h headers here since they could be C, C++, ObjC, etc.
lang_suffixes = {
'c': ('c',),
'cpp': ('cpp', 'cc', 'cxx', 'c++', 'hh', 'hpp', 'ipp', 'hxx', 'ino', 'ixx'),
'cpp': ('cpp', 'cc', 'cxx', 'c++', 'hh', 'hpp', 'ipp', 'hxx', 'ino', 'ixx', 'C'),
'cuda': ('cu',),
# f90, f95, f03, f08 are for free-form fortran ('f90' recommended)
# f, for, ftn, fpp are for fixed-form fortran ('f' or 'for' recommended)
@ -510,7 +510,9 @@ class Compiler(metaclass=abc.ABCMeta):
def can_compile(self, src: 'mesonlib.FileOrString') -> bool:
if isinstance(src, mesonlib.File):
src = src.fname
suffix = os.path.splitext(src)[1].lower()
suffix = os.path.splitext(src)[1]
if suffix != '.C':
suffix = suffix.lower()
return bool(suffix) and suffix[1:] in self.can_compile_suffixes
def get_id(self) -> str:

@ -350,10 +350,12 @@ class FileMode:
return perms
dot_C_dot_H_warning = """You are using .C or .H files in your project. This is deprecated.
Currently, Meson treats this as C code, but this
might change in the future, breaking your build.
You code also might be already broken on gcc and clang.
See https://github.com/mesonbuild/meson/pull/8239 for the discussions."""
Currently, Meson treats this as C++ code, but they
used to be treated as C code.
Note that the situation is a bit more complex if you are using the
Visual Studio compiler, as it treats .C files as C code, unless you add
the /TP compiler flag, but this is unreliable.
See https://github.com/mesonbuild/meson/pull/8747 for the discussions."""
class File:
def __init__(self, is_built: bool, subdir: str, fname: str):
if fname.endswith(".C") or fname.endswith(".H"):

@ -0,0 +1,6 @@
#include<iostream>
int main(void) {
std::cout << "C++ seems to be working." << std::endl;
return 0;
}

@ -32,3 +32,10 @@ else
endif
assert(exe_disabled, 'Executable was not disabled.')
if cpp.get_id() == 'msvc'
exe = executable('cppprog', 'cpp.C', cpp_args : '/TP')
else
exe = executable('cppprog', 'cpp.C')
endif
test('cpptest', exe)

Loading…
Cancel
Save