Debian Codegraph @

mesonbuild/compilers/mixins/pgi.py

raw
1 # SPDX-License-Identifier: Apache-2.0
2 # Copyright 2019 The meson development team
3
4 from __future__ import annotations
5
6 """Abstractions for the PGI family of compilers."""
7
8 import typing as T
9 import os
10 from pathlib import Path
11
12 from ..compilers import clike_debug_args, clike_optimization_args
13 from ...options import OptionKey
14
15 if T.TYPE_CHECKING:
16 from ...compilers.compilers import Compiler
17 else:
18 # This is a bit clever, for mypy we pretend that these mixins descend from
19 # Compiler, so we get all of the methods and attributes defined for us, but
20 # for runtime we make them descend from object (which all classes normally
21 # do). This gives up DRYer type checking, with no runtime impact
22 Compiler = object
23
24
25 class PGICompiler(Compiler):
26
27 id = 'pgi'
28
29 def __init__(self) -> None:
30 self.base_options = {OptionKey('b_pch')}
31
32 default_warn_args = ['-Minform=inform']
33 self.warn_args: T.Dict[str, T.List[str]] = {
34 '0': [],
35 '1': default_warn_args,
36 '2': default_warn_args,
37 '3': default_warn_args,
38 'everything': default_warn_args
39 }
40
41 def get_module_incdir_args(self) -> T.Tuple[str]:
42 return ('-module', )
43
44 def gen_import_library_args(self, implibname: str) -> T.List[str]:
45 return []
46
47 def get_pic_args(self) -> T.List[str]:
48 # PGI -fPIC is Linux only.
49 if self.info.is_linux():
50 return ['-fPIC']
51 return []
52
53 def openmp_flags(self) -> T.List[str]:
54 return ['-mp']
55
56 def get_preprocess_only_args(self) -> T.List[str]:
57 return ['-E', '-P', '-o', '-']
58
59 def get_preprocess_to_file_args(self) -> T.List[str]:
60 return ['-E', '-P']
61
62 def get_optimization_args(self, optimization_level: str) -> T.List[str]:
63 return clike_optimization_args[optimization_level]
64
65 def get_debug_args(self, is_debug: bool) -> T.List[str]:
66 return clike_debug_args[is_debug]
67
68 def compute_parameters_with_absolute_paths(self, parameter_list: T.List[str], build_dir: str) -> T.List[str]:
69 for idx, i in enumerate(parameter_list):
70 if i[:2] == '-I' or i[:2] == '-L':
71 parameter_list[idx] = i[:2] + os.path.normpath(os.path.join(build_dir, i[2:]))
72 return parameter_list
73
74 def get_always_args(self) -> T.List[str]:
75 return []
76
77 def get_pch_suffix(self) -> str:
78 # PGI defaults to .pch suffix for PCH on Linux and Windows with --pch option
79 return 'pch'
80
81 def get_pch_use_args(self, pch_dir: str, header: str) -> T.List[str]:
82 # PGI supports PCH for C++ only.
83 hdr = Path(pch_dir).resolve().parent / header
84 if self.language == 'cpp':
85 return ['--pch',
86 '--pch_dir', str(hdr.parent),
87 f'-I{hdr.parent}']
88 else:
89 return []
90
91 def thread_flags(self) -> T.List[str]:
92 # PGI cannot accept -pthread, it's already threaded
93 return []