| 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 get_cpp_permissive_args(self) -> T.List[str]: |
| 54 |
return ['-fpermissive'] |
| 55 |
|
| 56 |
def openmp_flags(self) -> T.List[str]: |
| 57 |
return ['-mp'] |
| 58 |
|
| 59 |
def get_preprocess_only_args(self) -> T.List[str]: |
| 60 |
return ['-E', '-P', '-o', '-'] |
| 61 |
|
| 62 |
def get_preprocess_to_file_args(self) -> T.List[str]: |
| 63 |
return ['-E', '-P'] |
| 64 |
|
| 65 |
def get_optimization_args(self, optimization_level: str) -> T.List[str]: |
| 66 |
return clike_optimization_args[optimization_level] |
| 67 |
|
| 68 |
def get_debug_args(self, is_debug: bool) -> T.List[str]: |
| 69 |
return clike_debug_args[is_debug] |
| 70 |
|
| 71 |
def compute_parameters_with_absolute_paths(self, parameter_list: T.List[str], build_dir: str) -> T.List[str]: |
| 72 |
for idx, i in enumerate(parameter_list): |
| 73 |
if i[:2] == '-I' or i[:2] == '-L': |
| 74 |
parameter_list[idx] = i[:2] + os.path.normpath(os.path.join(build_dir, i[2:])) |
| 75 |
return parameter_list |
| 76 |
|
| 77 |
def get_always_args(self) -> T.List[str]: |
| 78 |
return [] |
| 79 |
|
| 80 |
def get_pch_suffix(self) -> str: |
| 81 |
# PGI defaults to .pch suffix for PCH on Linux and Windows with --pch option |
| 82 |
return 'pch' |
| 83 |
|
| 84 |
def get_pch_use_args(self, pch_dir: str, header: str) -> T.List[str]: |
| 85 |
# PGI supports PCH for C++ only. |
| 86 |
hdr = Path(pch_dir).resolve().parent / header |
| 87 |
if self.language == 'cpp': |
| 88 |
return ['--pch', |
| 89 |
'--pch_dir', str(hdr.parent), |
| 90 |
f'-I{hdr.parent}'] |
| 91 |
else: |
| 92 |
return [] |
| 93 |
|
| 94 |
def thread_flags(self) -> T.List[str]: |
| 95 |
# PGI cannot accept -pthread, it's already threaded |
| 96 |
return [] |