meson: Meson doesn't detect files ending in .C as C++

It seems that meson doesn’t correctly detect files ending in the extension .C (note capital C) as C++ code. According to the Gcc manual, this is an accepted file extension to be processed as C++. I realize that it isn’t a common extension nor is it one I have ever seen outside my current project, but I cannot change the convention in my project at this time. Any chance we could add support for this in meson? I am happy to make the update if you can point me in the right direction.

I can get around this by passing -xc++ but it would be nice if we could support it directly.

This can be demonstrated by running meson init -l cpp and changing the generated file’s extension to .C.

I am running gcc 4.8.5 if that matters and meson off 07f1175c. Thanks again.

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Reactions: 1
  • Comments: 35 (33 by maintainers)

Most upvoted comments

Honestly, treating .c files as rust sources (or whatever other madness this is meant to support) is going to come back to bite us. I’ve worked on a project written in cmake that did something like (using meson psudo code because my cmake skills are weak)

f= files('a.m', 'b.m', 'c.m', language : 'c')
exectuable('foo', f, c_args : '-ObjC')

We shouldn’t be enabling this kind of madness. If we’re serious about cross platform we shouldn’t support patterns that don’t work on some platforms. The fact that on a fat32 file system FOO.c and foo.C are the same. .c should be C, .cpp should be C++.

Maybe a new kwarg for build targets to specify the language mapping on a per target basis?

Something like:

executable(..., language_mapping: {
  'c':   ['c'],
  'cpp': ['cpp', 'cxx', 'C']
})

One simple solution I can think of is to add a language: kwarg to the files() function.

+1, it can be generally useful IMHO.