Merge pull request #7609 from dcbaker/submit/2020-08/cmake-fix-apple-clang

Fix mapping of apple compilers in cmake
pull/7634/head
Jussi Pakkanen 4 years ago committed by GitHub
commit a9f33d96c6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 25
      mesonbuild/cmake/executor.py
  2. 4
      mesonbuild/compilers/__init__.py
  3. 5
      mesonbuild/compilers/objc.py
  4. 6
      mesonbuild/compilers/objcpp.py
  5. 9
      mesonbuild/environment.py

@ -29,13 +29,18 @@ from .. import mlog, mesonlib
from ..mesonlib import PerMachine, Popen_safe, version_compare, MachineChoice from ..mesonlib import PerMachine, Popen_safe, version_compare, MachineChoice
from ..environment import Environment from ..environment import Environment
from ..envconfig import get_env_var from ..envconfig import get_env_var
from ..compilers import (
AppleClangCCompiler, AppleClangCPPCompiler, AppleClangObjCCompiler,
AppleClangObjCPPCompiler
)
if T.TYPE_CHECKING: if T.TYPE_CHECKING:
from ..dependencies.base import ExternalProgram from ..dependencies.base import ExternalProgram
from ..compilers import Compiler
TYPE_result = T.Tuple[int, T.Optional[str], T.Optional[str]] TYPE_result = T.Tuple[int, T.Optional[str], T.Optional[str]]
MESON_TO_CMAKE_MAPPING = { _MESON_TO_CMAKE_MAPPING = {
'arm': 'ARMCC', 'arm': 'ARMCC',
'armclang': 'ARMClang', 'armclang': 'ARMClang',
'clang': 'Clang', 'clang': 'Clang',
@ -51,13 +56,21 @@ MESON_TO_CMAKE_MAPPING = {
'sun': 'SunPro', 'sun': 'SunPro',
} }
def meson_compiler_to_cmake_id(cobj): def meson_compiler_to_cmake_id(cobj: 'Compiler') -> str:
# cland and apple clang both map to 'clang' in meson, so we need to look at """Translate meson compiler's into CMAKE compiler ID's.
# the linker that's being used
if cobj.linker.get_id() == 'ld64': Most of these can be handled by a simple table lookup, with a few
exceptions.
Clang and Apple's Clang are both identified as "clang" by meson. To make
things more complicated gcc and vanilla clang both use Apple's ld64 on
macOS. The only way to know for sure is to do an isinstance() check.
"""
if isinstance(cobj, (AppleClangCCompiler, AppleClangCPPCompiler,
AppleClangObjCCompiler, AppleClangObjCPPCompiler)):
return 'AppleClang' return 'AppleClang'
# If no mapping, try GNU and hope that the build files don't care # If no mapping, try GNU and hope that the build files don't care
return MESON_TO_CMAKE_MAPPING.get(cobj.get_id(), 'GNU') return _MESON_TO_CMAKE_MAPPING.get(cobj.get_id(), 'GNU')
class CMakeExecutor: class CMakeExecutor:

@ -36,6 +36,8 @@ __all__ = [
'AppleClangCCompiler', 'AppleClangCCompiler',
'AppleClangCPPCompiler', 'AppleClangCPPCompiler',
'AppleClangObjCCompiler',
'AppleClangObjCPPCompiler',
'ArmCCompiler', 'ArmCCompiler',
'ArmCPPCompiler', 'ArmCPPCompiler',
'ArmclangCCompiler', 'ArmclangCCompiler',
@ -189,11 +191,13 @@ from .fortran import (
from .java import JavaCompiler from .java import JavaCompiler
from .objc import ( from .objc import (
ObjCCompiler, ObjCCompiler,
AppleClangObjCCompiler,
ClangObjCCompiler, ClangObjCCompiler,
GnuObjCCompiler, GnuObjCCompiler,
) )
from .objcpp import ( from .objcpp import (
ObjCPPCompiler, ObjCPPCompiler,
AppleClangObjCPPCompiler,
ClangObjCPPCompiler, ClangObjCPPCompiler,
GnuObjCPPCompiler, GnuObjCPPCompiler,
) )

@ -92,3 +92,8 @@ class ClangObjCCompiler(ClangCompiler, ObjCCompiler):
'1': default_warn_args, '1': default_warn_args,
'2': default_warn_args + ['-Wextra'], '2': default_warn_args + ['-Wextra'],
'3': default_warn_args + ['-Wextra', '-Wpedantic']} '3': default_warn_args + ['-Wextra', '-Wpedantic']}
class AppleClangObjCCompiler(ClangObjCCompiler):
"""Handle the differences between Apple's clang and vanilla clang."""

@ -90,3 +90,9 @@ class ClangObjCPPCompiler(ClangCompiler, ObjCPPCompiler):
'1': default_warn_args, '1': default_warn_args,
'2': default_warn_args + ['-Wextra'], '2': default_warn_args + ['-Wextra'],
'3': default_warn_args + ['-Wextra', '-Wpedantic']} '3': default_warn_args + ['-Wextra', '-Wpedantic']}
class AppleClangObjCPPCompiler(ClangObjCPPCompiler):
"""Handle the differences between Apple's clang and vanilla clang."""

@ -76,6 +76,8 @@ from .compilers import (
ArmclangCPPCompiler, ArmclangCPPCompiler,
AppleClangCCompiler, AppleClangCCompiler,
AppleClangCPPCompiler, AppleClangCPPCompiler,
AppleClangObjCCompiler,
AppleClangObjCPPCompiler,
ClangCCompiler, ClangCCompiler,
ClangCPPCompiler, ClangCPPCompiler,
ClangObjCCompiler, ClangObjCCompiler,
@ -1527,7 +1529,7 @@ class Environment:
def detect_objcpp_compiler(self, for_machine: MachineInfo) -> 'Compiler': def detect_objcpp_compiler(self, for_machine: MachineInfo) -> 'Compiler':
return self._detect_objc_or_objcpp_compiler(for_machine, False) return self._detect_objc_or_objcpp_compiler(for_machine, False)
def _detect_objc_or_objcpp_compiler(self, for_machine: MachineInfo, objc: bool) -> 'Compiler': def _detect_objc_or_objcpp_compiler(self, for_machine: MachineChoice, objc: bool) -> 'Compiler':
popen_exceptions = {} popen_exceptions = {}
compilers, ccache, exe_wrap = self._get_compilers('objc' if objc else 'objcpp', for_machine) compilers, ccache, exe_wrap = self._get_compilers('objc' if objc else 'objcpp', for_machine)
is_cross = self.is_cross_build(for_machine) is_cross = self.is_cross_build(for_machine)
@ -1556,7 +1558,10 @@ class Environment:
exe_wrap, defines, linker=linker) exe_wrap, defines, linker=linker)
if 'clang' in out: if 'clang' in out:
linker = None linker = None
comp = ClangObjCCompiler if objc else ClangObjCPPCompiler if 'Apple' in out:
comp = AppleClangObjCCompiler if objc else AppleClangObjCPPCompiler
else:
comp = ClangObjCCompiler if objc else ClangObjCPPCompiler
if 'windows' in out or self.machines[for_machine].is_windows(): if 'windows' in out or self.machines[for_machine].is_windows():
# If we're in a MINGW context this actually will use a gnu style ld # If we're in a MINGW context this actually will use a gnu style ld
try: try:

Loading…
Cancel
Save