Skip to content

Commit

Permalink
cmake: fix missing languages from CMake (fixes #8132)
Browse files Browse the repository at this point in the history
  • Loading branch information
mensinda authored and jpakkane committed Jan 4, 2021
1 parent 67ee65f commit 6b515c4
Show file tree
Hide file tree
Showing 9 changed files with 80 additions and 8 deletions.
1 change: 1 addition & 0 deletions cross/linux-mingw-w64-32bit.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
[binaries]
c = '/usr/bin/i686-w64-mingw32-gcc'
cpp = '/usr/bin/i686-w64-mingw32-g++'
objc = '/usr/bin/i686-w64-mingw32-gcc'
ar = '/usr/bin/i686-w64-mingw32-ar'
strip = '/usr/bin/i686-w64-mingw32-strip'
pkgconfig = '/usr/bin/i686-w64-mingw32-pkg-config'
Expand Down
1 change: 1 addition & 0 deletions cross/linux-mingw-w64-64bit.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
[binaries]
c = '/usr/bin/x86_64-w64-mingw32-gcc'
cpp = '/usr/bin/x86_64-w64-mingw32-g++'
objc = '/usr/bin/x86_64-w64-mingw32-gcc'
ar = '/usr/bin/x86_64-w64-mingw32-ar'
strip = '/usr/bin/x86_64-w64-mingw32-strip'
pkgconfig = '/usr/bin/x86_64-w64-mingw32-pkg-config'
Expand Down
37 changes: 29 additions & 8 deletions mesonbuild/cmake/interpreter.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ def __init__(self, target: CMakeTarget, env: 'Environment', for_machine: Machine
if target.install_paths:
self.install_dir = target.install_paths[0]

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

self.generated_raw = [] # type: T.List[Path]

for i in target.files:
# Determine the meson language
languages = set() # type: T.Set[str]
src_suffixes = set() # type: T.Set[str]

# Insert suffixes
for j in i.sources:
if not j.suffix:
continue
src_suffixes.add(j.suffix[1:])

# Determine the meson language(s)
# Extract the default language from the explicit CMake field
lang_cmake_to_meson = {val.lower(): key for key, val in language_map.items()}
lang = lang_cmake_to_meson.get(i.language.lower(), 'c')
if lang not in self.languages:
self.languages += [lang]
if lang not in self.compile_opts:
self.compile_opts[lang] = []
languages.add(lang_cmake_to_meson.get(i.language.lower(), 'c'))

# Determine missing languages from the source suffixes
for sfx in src_suffixes:
for key, val in lang_suffixes.items():
if sfx in val:
languages.add(key)
break

# Register the new languages and initialize the compile opts array
for lang in languages:
self.languages.add(lang)
if lang not in self.compile_opts:
self.compile_opts[lang] = []

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

# Handle include directories
self.includes += [x.path for x in i.includes if x.path not in self.includes and not x.isSystem]
Expand Down
5 changes: 5 additions & 0 deletions test cases/cmake/24 mixing languages/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#include <cmTest.h>

int main(void) {
return doStuff();
}
13 changes: 13 additions & 0 deletions test cases/cmake/24 mixing languages/meson.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
project('CMake mix', ['c', 'cpp'])

if not add_languages('objc', required : false)
error('MESON_SKIP_TEST: No ObjC compiler')
endif

cm = import('cmake')

sub_pro = cm.subproject('cmTest')
sub_dep = sub_pro.dependency('cmTest', include_type: 'system')

exe1 = executable('exe1', ['main.c'], dependencies: [sub_dep])
test('test1', exe1)
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
cmake_minimum_required(VERSION 3.5)

project(cmTest)

include_directories(${CMAKE_CURRENT_BINARY_DIR})

add_library(cmTest STATIC cmTest.c cmTest.m)
target_compile_definitions(cmTest PUBLIC SOME_MAGIC_DEFINE=42)
13 changes: 13 additions & 0 deletions test cases/cmake/24 mixing languages/subprojects/cmTest/cmTest.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#include "cmTest.h"
#include <stdio.h>

#if SOME_MAGIC_DEFINE != 42
#error "SOME_MAGIC_DEFINE != 42"
#endif

int foo(int x);

int doStuff(void) {
printf("Hello World\n");
return foo(42);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#pragma once

int doStuff(void);
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#if SOME_MAGIC_DEFINE != 42
#error "SOME_MAGIC_DEFINE != 42"
#endif

int foo(int x) {
return 42 - x;
}

0 comments on commit 6b515c4

Please sign in to comment.