From 4ca9a16288f51cce99624a2ef595d879acdc02d8 Mon Sep 17 00:00:00 2001 From: Volker-Weissmann <39418860+Volker-Weissmann@users.noreply.github.com> Date: Wed, 19 May 2021 16:10:22 +0200 Subject: [PATCH] .C files are now treated as C++ code --- mesonbuild/compilers/compilers.py | 6 ++++-- mesonbuild/mesonlib/universal.py | 10 ++++++---- test cases/common/2 cpp/cpp.C | 6 ++++++ test cases/common/2 cpp/meson.build | 7 +++++++ 4 files changed, 23 insertions(+), 6 deletions(-) create mode 100644 test cases/common/2 cpp/cpp.C diff --git a/mesonbuild/compilers/compilers.py b/mesonbuild/compilers/compilers.py index 9b4418b54..231eca75b 100644 --- a/mesonbuild/compilers/compilers.py +++ b/mesonbuild/compilers/compilers.py @@ -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: diff --git a/mesonbuild/mesonlib/universal.py b/mesonbuild/mesonlib/universal.py index ee1152c79..318b365e0 100644 --- a/mesonbuild/mesonlib/universal.py +++ b/mesonbuild/mesonlib/universal.py @@ -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"): diff --git a/test cases/common/2 cpp/cpp.C b/test cases/common/2 cpp/cpp.C new file mode 100644 index 000000000..d3df47689 --- /dev/null +++ b/test cases/common/2 cpp/cpp.C @@ -0,0 +1,6 @@ +#include + +int main(void) { + std::cout << "C++ seems to be working." << std::endl; + return 0; +} diff --git a/test cases/common/2 cpp/meson.build b/test cases/common/2 cpp/meson.build index 47cb7c5e5..8f13d661e 100644 --- a/test cases/common/2 cpp/meson.build +++ b/test cases/common/2 cpp/meson.build @@ -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)