Skip to content

Commit 6b515c4

Browse files
mensindajpakkane
authored andcommitted
cmake: fix missing languages from CMake (fixes mesonbuild#8132)
1 parent 67ee65f commit 6b515c4

File tree

9 files changed

+80
-8
lines changed

9 files changed

+80
-8
lines changed

cross/linux-mingw-w64-32bit.txt

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
[binaries]
22
c = '/usr/bin/i686-w64-mingw32-gcc'
33
cpp = '/usr/bin/i686-w64-mingw32-g++'
4+
objc = '/usr/bin/i686-w64-mingw32-gcc'
45
ar = '/usr/bin/i686-w64-mingw32-ar'
56
strip = '/usr/bin/i686-w64-mingw32-strip'
67
pkgconfig = '/usr/bin/i686-w64-mingw32-pkg-config'

cross/linux-mingw-w64-64bit.txt

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
[binaries]
22
c = '/usr/bin/x86_64-w64-mingw32-gcc'
33
cpp = '/usr/bin/x86_64-w64-mingw32-g++'
4+
objc = '/usr/bin/x86_64-w64-mingw32-gcc'
45
ar = '/usr/bin/x86_64-w64-mingw32-ar'
56
strip = '/usr/bin/x86_64-w64-mingw32-strip'
67
pkgconfig = '/usr/bin/x86_64-w64-mingw32-pkg-config'

mesonbuild/cmake/interpreter.py

+29-8
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ def __init__(self, target: CMakeTarget, env: 'Environment', for_machine: Machine
231231
if target.install_paths:
232232
self.install_dir = target.install_paths[0]
233233

234-
self.languages = [] # type: T.List[str]
234+
self.languages = set() # type: T.Set[str]
235235
self.sources = [] # type: T.List[Path]
236236
self.generated = [] # type: T.List[Path]
237237
self.generated_ctgt = [] # type: T.List[CustomTargetReference]
@@ -250,19 +250,40 @@ def __init__(self, target: CMakeTarget, env: 'Environment', for_machine: Machine
250250
self.name = _sanitize_cmake_name(self.name)
251251

252252
self.generated_raw = [] # type: T.List[Path]
253+
253254
for i in target.files:
254-
# Determine the meson language
255+
languages = set() # type: T.Set[str]
256+
src_suffixes = set() # type: T.Set[str]
257+
258+
# Insert suffixes
259+
for j in i.sources:
260+
if not j.suffix:
261+
continue
262+
src_suffixes.add(j.suffix[1:])
263+
264+
# Determine the meson language(s)
265+
# Extract the default language from the explicit CMake field
255266
lang_cmake_to_meson = {val.lower(): key for key, val in language_map.items()}
256-
lang = lang_cmake_to_meson.get(i.language.lower(), 'c')
257-
if lang not in self.languages:
258-
self.languages += [lang]
259-
if lang not in self.compile_opts:
260-
self.compile_opts[lang] = []
267+
languages.add(lang_cmake_to_meson.get(i.language.lower(), 'c'))
268+
269+
# Determine missing languages from the source suffixes
270+
for sfx in src_suffixes:
271+
for key, val in lang_suffixes.items():
272+
if sfx in val:
273+
languages.add(key)
274+
break
275+
276+
# Register the new languages and initialize the compile opts array
277+
for lang in languages:
278+
self.languages.add(lang)
279+
if lang not in self.compile_opts:
280+
self.compile_opts[lang] = []
261281

262282
# Add arguments, but avoid duplicates
263283
args = i.flags
264284
args += ['-D{}'.format(x) for x in i.defines]
265-
self.compile_opts[lang] += [x for x in args if x not in self.compile_opts[lang]]
285+
for lang in languages:
286+
self.compile_opts[lang] += [x for x in args if x not in self.compile_opts[lang]]
266287

267288
# Handle include directories
268289
self.includes += [x.path for x in i.includes if x.path not in self.includes and not x.isSystem]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#include <cmTest.h>
2+
3+
int main(void) {
4+
return doStuff();
5+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
project('CMake mix', ['c', 'cpp'])
2+
3+
if not add_languages('objc', required : false)
4+
error('MESON_SKIP_TEST: No ObjC compiler')
5+
endif
6+
7+
cm = import('cmake')
8+
9+
sub_pro = cm.subproject('cmTest')
10+
sub_dep = sub_pro.dependency('cmTest', include_type: 'system')
11+
12+
exe1 = executable('exe1', ['main.c'], dependencies: [sub_dep])
13+
test('test1', exe1)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
cmake_minimum_required(VERSION 3.5)
2+
3+
project(cmTest)
4+
5+
include_directories(${CMAKE_CURRENT_BINARY_DIR})
6+
7+
add_library(cmTest STATIC cmTest.c cmTest.m)
8+
target_compile_definitions(cmTest PUBLIC SOME_MAGIC_DEFINE=42)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#include "cmTest.h"
2+
#include <stdio.h>
3+
4+
#if SOME_MAGIC_DEFINE != 42
5+
#error "SOME_MAGIC_DEFINE != 42"
6+
#endif
7+
8+
int foo(int x);
9+
10+
int doStuff(void) {
11+
printf("Hello World\n");
12+
return foo(42);
13+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#pragma once
2+
3+
int doStuff(void);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#if SOME_MAGIC_DEFINE != 42
2+
#error "SOME_MAGIC_DEFINE != 42"
3+
#endif
4+
5+
int foo(int x) {
6+
return 42 - x;
7+
}

0 commit comments

Comments
 (0)