File: apple.py

package info (click to toggle)
meson 1.10.0-1
  • links: PTS
  • area: main
  • in suites: forky, sid
  • size: 24,680 kB
  • sloc: python: 90,528; ansic: 7,377; cpp: 2,434; f90: 482; asm: 218; sh: 143; xml: 109; java: 97; cs: 62; objc: 33; lex: 13; fortran: 12; makefile: 10; yacc: 9; javascript: 6
file content (80 lines) | stat: -rw-r--r-- 2,652 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# SPDX-License-Identifier: Apache-2.0
# Copyright © 2024-2025 Intel Corporation

"""Provides mixins for Apple compilers."""

from __future__ import annotations
import typing as T

from ...mesonlib import MesonException

if T.TYPE_CHECKING:
    from ..._typing import ImmutableListProtocol
    from ...envconfig import MachineInfo
    from ..compilers import Compiler
else:
    # This is a bit clever, for mypy we pretend that these mixins descend from
    # Compiler, so we get all of the methods and attributes defined for us, but
    # for runtime we make them descend from object (which all classes normally
    # do). This gives up DRYer type checking, with no runtime impact
    Compiler = object


class AppleCompilerMixin(Compiler):

    """Handle differences between Vanilla Clang and the Clang shipped with XCode."""

    __BASE_OMP_FLAGS: ImmutableListProtocol[str] = ['-Xpreprocessor', '-fopenmp']

    if T.TYPE_CHECKING:
        # Older versions of mypy can't figure this out
        info: MachineInfo

    def openmp_flags(self) -> T.List[str]:
        """Flags required to compile with OpenMP on Apple.

        The Apple Clang Compiler doesn't have builtin support for OpenMP, it
        must be provided separately. As such, we need to add the -Xpreprocessor
        argument so that an external OpenMP can be found.

        :return: A list of arguments
        """
        if self.info.cpu_family.startswith('x86'):
            root = '/usr/local'
        else:
            root = '/opt/homebrew'
        return self.__BASE_OMP_FLAGS + [f'-I{root}/opt/libomp/include']

    def openmp_link_flags(self) -> T.List[str]:
        if self.info.cpu_family.startswith('x86'):
            root = '/usr/local'
        else:
            root = '/opt/homebrew'

        link = self.find_library('omp', [f'{root}/opt/libomp/lib'])
        if not link:
            raise MesonException("Couldn't find libomp")
        return self.__BASE_OMP_FLAGS + link

    def get_prelink_args(self, prelink_name: str, obj_list: T.List[str]) -> T.Tuple[T.List[str], T.List[str]]:
        # The objects are prelinked through the compiler, which injects -lSystem
        return [prelink_name], ['-nostdlib', '-r', '-o', prelink_name] + obj_list


class AppleCStdsMixin(Compiler):

    """Provide version overrides for the Apple Compilers."""

    _C17_VERSION = '>=10.0.0'
    _C18_VERSION = '>=11.0.0'
    _C2X_VERSION = '>=11.0.3'
    _C23_VERSION = '>=17.0.0'
    _C2Y_VERSION = '>=17.0.0'


class AppleCPPStdsMixin(Compiler):

    """Provide version overrides for the Apple C++ Compilers."""

    _CPP23_VERSION = '>=13.0.0'
    _CPP26_VERSION = '>=16.0.0'