| 1 |
# SPDX-License-Identifier: Apache-2.0 |
| 2 |
# Copyright 2012-2017 The Meson development team |
| 3 |
|
| 4 |
from __future__ import annotations |
| 5 |
|
| 6 |
import textwrap |
| 7 |
import typing as T |
| 8 |
import functools |
| 9 |
import os |
| 10 |
|
| 11 |
from .. import options |
| 12 |
from .. import mesonlib |
| 13 |
from .compilers import ( |
| 14 |
clike_debug_args, |
| 15 |
Compiler, |
| 16 |
CompileCheckMode, |
| 17 |
ManyInOneLinkerOptionStyle, |
| 18 |
) |
| 19 |
from .mixins.clike import CLikeCompiler |
| 20 |
from .mixins.gnu import GnuCompiler, gnu_optimization_args |
| 21 |
from .mixins.intel import IntelGnuLikeCompiler, IntelLLVMLikeCompiler, IntelVisualStudioLikeCompiler |
| 22 |
from .mixins.clang import ClangCompiler |
| 23 |
from .mixins.elbrus import ElbrusCompiler |
| 24 |
from .mixins.pgi import PGICompiler |
| 25 |
|
| 26 |
from mesonbuild.mesonlib import ( |
| 27 |
version_compare, MesonException, |
| 28 |
LibType, |
| 29 |
) |
| 30 |
|
| 31 |
if T.TYPE_CHECKING: |
| 32 |
from ..options import MutableKeyedOptionDictType |
| 33 |
from ..dependencies import Dependency |
| 34 |
from ..environment import Environment |
| 35 |
from ..linkers.linkers import DynamicLinker |
| 36 |
from ..mesonlib import MachineChoice |
| 37 |
from ..build import BuildTarget |
| 38 |
|
| 39 |
|
| 40 |
class FortranCompiler(CLikeCompiler, Compiler): |
| 41 |
|
| 42 |
language = 'fortran' |
| 43 |
|
| 44 |
def __init__(self, exelist: T.List[str], version: str, for_machine: MachineChoice, |
| 45 |
env: Environment, linker: T.Optional['DynamicLinker'] = None, |
| 46 |
full_version: T.Optional[str] = None): |
| 47 |
Compiler.__init__(self, [], exelist, version, for_machine, env, |
| 48 |
full_version=full_version, linker=linker) |
| 49 |
CLikeCompiler.__init__(self) |
| 50 |
|
| 51 |
def has_function(self, funcname: str, prefix: str, *, |
| 52 |
extra_args: T.Optional[T.List[str]] = None, |
| 53 |
dependencies: T.Optional[T.List['Dependency']] = None) -> T.Tuple[bool, bool]: |
| 54 |
raise MesonException('Fortran does not have "has_function" capability.\n' |
| 55 |
'It is better to test if a Fortran capability is working like:\n\n' |
| 56 |
"meson.get_compiler('fortran').links('block; end block; end program')\n\n" |
| 57 |
'that example is to see if the compiler has Fortran 2008 Block element.') |
| 58 |
|
| 59 |
def _get_basic_compiler_args(self, mode: CompileCheckMode) -> T.Tuple[T.List[str], T.List[str]]: |
| 60 |
cargs = self.get_external_compile_args() |
| 61 |
largs = self.get_external_link_args() |
| 62 |
return cargs, largs |
| 63 |
|
| 64 |
def _sanity_check_source_code(self) -> str: |
| 65 |
return textwrap.dedent(''' |
| 66 |
PROGRAM MAIN |
| 67 |
PRINT *, "Fortran compilation is working." |
| 68 |
END |
| 69 |
''') |
| 70 |
|
| 71 |
def get_optimization_args(self, optimization_level: str) -> T.List[str]: |
| 72 |
return gnu_optimization_args[optimization_level] |
| 73 |
|
| 74 |
def get_debug_args(self, is_debug: bool) -> T.List[str]: |
| 75 |
return clike_debug_args[is_debug] |
| 76 |
|
| 77 |
def get_preprocess_only_args(self) -> T.List[str]: |
| 78 |
return ['-cpp'] + super().get_preprocess_only_args() |
| 79 |
|
| 80 |
def get_module_incdir_args(self) -> T.Tuple[str, ...]: |
| 81 |
return ('-I', ) |
| 82 |
|
| 83 |
def get_module_outdir_args(self, path: str) -> T.List[str]: |
| 84 |
return ['-module', path] |
| 85 |
|
| 86 |
def compute_parameters_with_absolute_paths(self, parameter_list: T.List[str], |
| 87 |
build_dir: str) -> T.List[str]: |
| 88 |
for idx, i in enumerate(parameter_list): |
| 89 |
if i[:2] == '-I' or i[:2] == '-L': |
| 90 |
parameter_list[idx] = i[:2] + os.path.normpath(os.path.join(build_dir, i[2:])) |
| 91 |
|
| 92 |
return parameter_list |
| 93 |
|
| 94 |
def module_name_to_filename(self, module_name: str) -> str: |
| 95 |
if '_' in module_name: # submodule |
| 96 |
s = module_name.lower() |
| 97 |
if self.id in {'gcc', 'intel', 'intel-cl'}: |
| 98 |
filename = s.replace('_', '@') + '.smod' |
| 99 |
elif self.id in {'pgi', 'flang'}: |
| 100 |
filename = s.replace('_', '-') + '.mod' |
| 101 |
else: |
| 102 |
filename = s + '.mod' |
| 103 |
else: # module |
| 104 |
filename = module_name.lower() + '.mod' |
| 105 |
|
| 106 |
return filename |
| 107 |
|
| 108 |
def find_library(self, libname: str, extra_dirs: T.List[str], libtype: LibType = LibType.PREFER_SHARED, |
| 109 |
lib_prefix_warning: bool = True, ignore_system_dirs: bool = False, |
| 110 |
skip_link_check: bool = False) -> T.Optional[T.List[str]]: |
| 111 |
code = 'stop; end program' |
| 112 |
return self._find_library_impl(libname, extra_dirs, code, libtype, lib_prefix_warning, ignore_system_dirs, skip_link_check) |
| 113 |
|
| 114 |
def has_multi_arguments(self, args: T.List[str]) -> T.Tuple[bool, bool]: |
| 115 |
return self._has_multi_arguments(args, 'stop; end program') |
| 116 |
|
| 117 |
def has_multi_link_arguments(self, args: T.List[str], to_host_args: bool = True) -> T.Tuple[bool, bool]: |
| 118 |
return self._has_multi_link_arguments(args, 'stop; end program') |
| 119 |
|
| 120 |
def get_options(self) -> 'MutableKeyedOptionDictType': |
| 121 |
opts = super().get_options() |
| 122 |
|
| 123 |
key = self.form_compileropt_key('std') |
| 124 |
opts[key] = options.UserComboOption( |
| 125 |
self.make_option_name(key), |
| 126 |
'Fortran language standard to use', |
| 127 |
'none', |
| 128 |
choices=['none']) |
| 129 |
|
| 130 |
return opts |
| 131 |
|
| 132 |
def _compile_int(self, expression: str, prefix: str, |
| 133 |
extra_args: T.Union[None, T.List[str], T.Callable[[CompileCheckMode], T.List[str]]], |
| 134 |
dependencies: T.Optional[T.List['Dependency']]) -> bool: |
| 135 |
# Use a trick for emulating a static assert |
| 136 |
# Taken from https://github.com/j3-fortran/fortran_proposals/issues/70 |
| 137 |
t = f'''program test |
| 138 |
{prefix} |
| 139 |
real(merge(kind(1.),-1,({expression}))), parameter :: fail = 1. |
| 140 |
end program test''' |
| 141 |
return self.compiles(t, extra_args=extra_args, dependencies=dependencies)[0] |
| 142 |
|
| 143 |
def _cross_compute_int(self, expression: str, low: T.Optional[int], high: T.Optional[int], |
| 144 |
guess: T.Optional[int], prefix: str, |
| 145 |
extra_args: T.Union[None, T.List[str], T.Callable[[CompileCheckMode], T.List[str]]] = None, |
| 146 |
dependencies: T.Optional[T.List['Dependency']] = None) -> int: |
| 147 |
# This only difference between this implementation and that of CLikeCompiler |
| 148 |
# is a change in logical conjunction operator (.and. instead of &&) |
| 149 |
|
| 150 |
# Try user's guess first |
| 151 |
if isinstance(guess, int): |
| 152 |
if self._compile_int(f'{expression} == {guess}', prefix, extra_args, dependencies): |
| 153 |
return guess |
| 154 |
|
| 155 |
# If no bounds are given, compute them in the limit of int32 |
| 156 |
maxint = 0x7fffffff |
| 157 |
minint = -0x80000000 |
| 158 |
if not isinstance(low, int) or not isinstance(high, int): |
| 159 |
if self._compile_int(f'{expression} >= 0', prefix, extra_args, dependencies): |
| 160 |
low = cur = 0 |
| 161 |
while self._compile_int(f'{expression} > {cur}', prefix, extra_args, dependencies): |
| 162 |
low = cur + 1 |
| 163 |
if low > maxint: |
| 164 |
raise mesonlib.EnvironmentException('Cross-compile check overflowed') |
| 165 |
cur = min(cur * 2 + 1, maxint) |
| 166 |
high = cur |
| 167 |
else: |
| 168 |
high = cur = -1 |
| 169 |
while self._compile_int(f'{expression} < {cur}', prefix, extra_args, dependencies): |
| 170 |
high = cur - 1 |
| 171 |
if high < minint: |
| 172 |
raise mesonlib.EnvironmentException('Cross-compile check overflowed') |
| 173 |
cur = max(cur * 2, minint) |
| 174 |
low = cur |
| 175 |
else: |
| 176 |
# Sanity check limits given by user |
| 177 |
if high < low: |
| 178 |
raise mesonlib.EnvironmentException('high limit smaller than low limit') |
| 179 |
condition = f'{expression} <= {high} .and. {expression} >= {low}' |
| 180 |
if not self._compile_int(condition, prefix, extra_args, dependencies): |
| 181 |
raise mesonlib.EnvironmentException('Value out of given range') |
| 182 |
|
| 183 |
# Binary search |
| 184 |
while low != high: |
| 185 |
cur = low + int((high - low) / 2) |
| 186 |
if self._compile_int(f'{expression} <= {cur}', prefix, extra_args, dependencies): |
| 187 |
high = cur |
| 188 |
else: |
| 189 |
low = cur + 1 |
| 190 |
|
| 191 |
return low |
| 192 |
|
| 193 |
def compute_int(self, expression: str, low: T.Optional[int], high: T.Optional[int], |
| 194 |
guess: T.Optional[int], prefix: str, *, |
| 195 |
extra_args: T.Union[None, T.List[str], T.Callable[[CompileCheckMode], T.List[str]]], |
| 196 |
dependencies: T.Optional[T.List['Dependency']] = None) -> int: |
| 197 |
if extra_args is None: |
| 198 |
extra_args = [] |
| 199 |
if self.is_cross: |
| 200 |
return self._cross_compute_int(expression, low, high, guess, prefix, extra_args, dependencies) |
| 201 |
t = f'''program test |
| 202 |
{prefix} |
| 203 |
print '(i0)', {expression} |
| 204 |
end program test |
| 205 |
''' |
| 206 |
res = self.run(t, extra_args=extra_args, dependencies=dependencies) |
| 207 |
if not res.compiled: |
| 208 |
return -1 |
| 209 |
if res.returncode != 0: |
| 210 |
raise mesonlib.EnvironmentException('Could not run compute_int test binary.') |
| 211 |
return int(res.stdout) |
| 212 |
|
| 213 |
def _cross_sizeof(self, typename: str, prefix: str, *, |
| 214 |
extra_args: T.Union[None, T.List[str], T.Callable[[CompileCheckMode], T.List[str]]] = None, |
| 215 |
dependencies: T.Optional[T.List['Dependency']] = None) -> int: |
| 216 |
if extra_args is None: |
| 217 |
extra_args = [] |
| 218 |
t = f'''program test |
| 219 |
use iso_c_binding |
| 220 |
{prefix} |
| 221 |
{typename} :: something |
| 222 |
end program test |
| 223 |
''' |
| 224 |
if not self.compiles(t, extra_args=extra_args, |
| 225 |
dependencies=dependencies)[0]: |
| 226 |
return -1 |
| 227 |
return self._cross_compute_int('c_sizeof(x)', None, None, None, prefix + '\nuse iso_c_binding\n' + typename + ' :: x', extra_args, dependencies) |
| 228 |
|
| 229 |
def sizeof(self, typename: str, prefix: str, *, |
| 230 |
extra_args: T.Union[None, T.List[str], T.Callable[[CompileCheckMode], T.List[str]]] = None, |
| 231 |
dependencies: T.Optional[T.List['Dependency']] = None) -> T.Tuple[int, bool]: |
| 232 |
if extra_args is None: |
| 233 |
extra_args = [] |
| 234 |
if self.is_cross: |
| 235 |
r = self._cross_sizeof(typename, prefix, extra_args=extra_args, |
| 236 |
dependencies=dependencies) |
| 237 |
return r, False |
| 238 |
t = f'''program test |
| 239 |
use iso_c_binding |
| 240 |
{prefix} |
| 241 |
{typename} :: x |
| 242 |
print '(i0)', c_sizeof(x) |
| 243 |
end program test |
| 244 |
''' |
| 245 |
res = self.cached_run(t, extra_args=extra_args, |
| 246 |
dependencies=dependencies) |
| 247 |
if not res.compiled: |
| 248 |
return -1, False |
| 249 |
if res.returncode != 0: |
| 250 |
raise mesonlib.EnvironmentException('Could not run sizeof test binary.') |
| 251 |
return int(res.stdout), res.cached |
| 252 |
|
| 253 |
@functools.lru_cache() |
| 254 |
def output_is_64bit(self) -> bool: |
| 255 |
''' |
| 256 |
returns true if the output produced is 64-bit, false if 32-bit |
| 257 |
''' |
| 258 |
return self.sizeof('type(c_ptr)', '')[0] == 8 |
| 259 |
|
| 260 |
|
| 261 |
class GnuFortranCompiler(GnuCompiler, FortranCompiler): |
| 262 |
|
| 263 |
def __init__(self, exelist: T.List[str], version: str, for_machine: MachineChoice, |
| 264 |
env: Environment, |
| 265 |
defines: T.Optional[T.Dict[str, str]] = None, |
| 266 |
linker: T.Optional['DynamicLinker'] = None, |
| 267 |
full_version: T.Optional[str] = None): |
| 268 |
FortranCompiler.__init__(self, exelist, version, for_machine, |
| 269 |
env, linker=linker, full_version=full_version) |
| 270 |
GnuCompiler.__init__(self, defines) |
| 271 |
default_warn_args = ['-Wall'] |
| 272 |
self.warn_args = {'0': [], |
| 273 |
'1': default_warn_args, |
| 274 |
'2': default_warn_args + ['-Wextra'], |
| 275 |
'3': default_warn_args + ['-Wextra', '-Wpedantic', '-fimplicit-none'], |
| 276 |
'everything': default_warn_args + ['-Wextra', '-Wpedantic', '-fimplicit-none']} |
| 277 |
|
| 278 |
def get_options(self) -> 'MutableKeyedOptionDictType': |
| 279 |
opts = super().get_options() |
| 280 |
fortran_stds = ['legacy', 'f95', 'f2003'] |
| 281 |
if version_compare(self.version, '>=4.4.0'): |
| 282 |
fortran_stds += ['f2008'] |
| 283 |
if version_compare(self.version, '>=8.0.0'): |
| 284 |
fortran_stds += ['f2018'] |
| 285 |
self._update_language_stds(opts, fortran_stds) |
| 286 |
return opts |
| 287 |
|
| 288 |
def get_option_std_args(self, target: BuildTarget, subproject: T.Optional[str] = None) -> T.List[str]: |
| 289 |
args: T.List[str] = [] |
| 290 |
std = self.get_compileropt_value('std', target, subproject) |
| 291 |
assert isinstance(std, str) |
| 292 |
if std != 'none': |
| 293 |
args.append('-std=' + std) |
| 294 |
return args |
| 295 |
|
| 296 |
def get_dependency_gen_args(self, outtarget: str, outfile: str) -> T.List[str]: |
| 297 |
# Disabled until this is fixed: |
| 298 |
# https://gcc.gnu.org/bugzilla/show_bug.cgi?id=62162 |
| 299 |
# return ['-cpp', '-MD', '-MQ', outtarget] |
| 300 |
return [] |
| 301 |
|
| 302 |
def get_module_outdir_args(self, path: str) -> T.List[str]: |
| 303 |
return ['-J' + path] |
| 304 |
|
| 305 |
def language_stdlib_only_link_flags(self) -> T.List[str]: |
| 306 |
# We need to apply the search prefix here, as these link arguments may |
| 307 |
# be passed to a different compiler with a different set of default |
| 308 |
# search paths, such as when using Clang for C/C++ and gfortran for |
| 309 |
# fortran, |
| 310 |
search_dirs: T.List[str] = [] |
| 311 |
for d in self.get_compiler_dirs('libraries'): |
| 312 |
search_dirs.append(f'-L{d}') |
| 313 |
return search_dirs + ['-lgfortran', '-lm'] |
| 314 |
|
| 315 |
def has_header(self, hname: str, prefix: str, *, |
| 316 |
extra_args: T.Union[None, T.List[str], T.Callable[['CompileCheckMode'], T.List[str]]] = None, |
| 317 |
dependencies: T.Optional[T.List['Dependency']] = None, |
| 318 |
disable_cache: bool = False) -> T.Tuple[bool, bool]: |
| 319 |
''' |
| 320 |
Derived from mixins/clike.py:has_header, but without C-style usage of |
| 321 |
__has_include which breaks with GCC-Fortran 10: |
| 322 |
https://github.com/mesonbuild/meson/issues/7017 |
| 323 |
''' |
| 324 |
code = f'{prefix}\n#include <{hname}>' |
| 325 |
return self.compiles(code, extra_args=extra_args, |
| 326 |
dependencies=dependencies, mode=CompileCheckMode.PREPROCESS, disable_cache=disable_cache) |
| 327 |
|
| 328 |
|
| 329 |
class ElbrusFortranCompiler(ElbrusCompiler, FortranCompiler): |
| 330 |
def __init__(self, exelist: T.List[str], version: str, for_machine: MachineChoice, |
| 331 |
env: Environment, |
| 332 |
defines: T.Optional[T.Dict[str, str]] = None, |
| 333 |
linker: T.Optional['DynamicLinker'] = None, |
| 334 |
full_version: T.Optional[str] = None): |
| 335 |
FortranCompiler.__init__(self, exelist, version, for_machine, |
| 336 |
env, linker=linker, full_version=full_version) |
| 337 |
ElbrusCompiler.__init__(self) |
| 338 |
|
| 339 |
def get_options(self) -> 'MutableKeyedOptionDictType': |
| 340 |
opts = super().get_options() |
| 341 |
self._update_language_stds(opts, ['f95', 'f2003', 'f2008', 'gnu', 'legacy', 'f2008ts']) |
| 342 |
return opts |
| 343 |
|
| 344 |
def get_module_outdir_args(self, path: str) -> T.List[str]: |
| 345 |
return ['-J' + path] |
| 346 |
|
| 347 |
def language_stdlib_only_link_flags(self) -> T.List[str]: |
| 348 |
# No need to add search paths here, because LCC ships everything |
| 349 |
# (C, C++, Fortran) and always knows where to look for its stuff |
| 350 |
return ['-lgfortran', '-lm'] |
| 351 |
|
| 352 |
|
| 353 |
class G95FortranCompiler(FortranCompiler): |
| 354 |
|
| 355 |
LINKER_OPTION_STYLE = ManyInOneLinkerOptionStyle('-Wl,', ',') |
| 356 |
id = 'g95' |
| 357 |
|
| 358 |
def __init__(self, exelist: T.List[str], version: str, for_machine: MachineChoice, |
| 359 |
env: Environment, linker: T.Optional['DynamicLinker'] = None, |
| 360 |
full_version: T.Optional[str] = None): |
| 361 |
FortranCompiler.__init__(self, exelist, version, for_machine, |
| 362 |
env, linker=linker, full_version=full_version) |
| 363 |
default_warn_args = ['-Wall'] |
| 364 |
self.warn_args = {'0': [], |
| 365 |
'1': default_warn_args, |
| 366 |
'2': default_warn_args + ['-Wextra'], |
| 367 |
'3': default_warn_args + ['-Wextra', '-pedantic'], |
| 368 |
'everything': default_warn_args + ['-Wextra', '-pedantic']} |
| 369 |
|
| 370 |
def get_module_outdir_args(self, path: str) -> T.List[str]: |
| 371 |
return ['-fmod=' + path] |
| 372 |
|
| 373 |
|
| 374 |
class SunFortranCompiler(FortranCompiler): |
| 375 |
|
| 376 |
LINKER_OPTION_STYLE = ManyInOneLinkerOptionStyle('-Wl,', ',') |
| 377 |
id = 'sun' |
| 378 |
|
| 379 |
def get_dependency_gen_args(self, outtarget: str, outfile: str) -> T.List[str]: |
| 380 |
return ['-fpp'] |
| 381 |
|
| 382 |
def get_always_args(self) -> T.List[str]: |
| 383 |
return [] |
| 384 |
|
| 385 |
def get_warn_args(self, level: str) -> T.List[str]: |
| 386 |
return [] |
| 387 |
|
| 388 |
def get_module_incdir_args(self) -> T.Tuple[str, ...]: |
| 389 |
return ('-M', ) |
| 390 |
|
| 391 |
def get_module_outdir_args(self, path: str) -> T.List[str]: |
| 392 |
return ['-moddir=' + path] |
| 393 |
|
| 394 |
def openmp_flags(self) -> T.List[str]: |
| 395 |
return ['-xopenmp'] |
| 396 |
|
| 397 |
|
| 398 |
class IntelFortranCompiler(IntelGnuLikeCompiler, FortranCompiler): |
| 399 |
|
| 400 |
id = 'intel' |
| 401 |
|
| 402 |
def __init__(self, exelist: T.List[str], version: str, for_machine: MachineChoice, |
| 403 |
env: Environment, linker: T.Optional['DynamicLinker'] = None, |
| 404 |
full_version: T.Optional[str] = None): |
| 405 |
FortranCompiler.__init__(self, exelist, version, for_machine, |
| 406 |
env, linker=linker, full_version=full_version) |
| 407 |
# FIXME: Add support for OS X and Windows in detect_fortran_compiler so |
| 408 |
# we are sent the type of compiler |
| 409 |
IntelGnuLikeCompiler.__init__(self) |
| 410 |
self.file_suffixes = ('f90', 'f', 'for', 'ftn', 'fpp', ) |
| 411 |
default_warn_args = ['-warn', 'general', '-warn', 'truncated_source'] |
| 412 |
self.warn_args = {'0': [], |
| 413 |
'1': default_warn_args, |
| 414 |
'2': default_warn_args + ['-warn', 'unused'], |
| 415 |
'3': ['-warn', 'all'], |
| 416 |
'everything': ['-warn', 'all']} |
| 417 |
|
| 418 |
def get_options(self) -> 'MutableKeyedOptionDictType': |
| 419 |
opts = super().get_options() |
| 420 |
self._update_language_stds(opts, ['none', 'legacy', 'f95', 'f2003', 'f2008', 'f2018']) |
| 421 |
return opts |
| 422 |
|
| 423 |
def get_option_std_args(self, target: BuildTarget, subproject: T.Optional[str] = None) -> T.List[str]: |
| 424 |
args: T.List[str] = [] |
| 425 |
std = self.get_compileropt_value('std', target, subproject) |
| 426 |
stds = {'legacy': 'none', 'f95': 'f95', 'f2003': 'f03', 'f2008': 'f08', 'f2018': 'f18'} |
| 427 |
assert isinstance(std, str) |
| 428 |
if std != 'none': |
| 429 |
args.append('-stand=' + stds[std]) |
| 430 |
return args |
| 431 |
|
| 432 |
def get_preprocess_only_args(self) -> T.List[str]: |
| 433 |
return ['-cpp', '-EP'] |
| 434 |
|
| 435 |
def get_werror_args(self) -> T.List[str]: |
| 436 |
return ['-warn', 'errors'] |
| 437 |
|
| 438 |
def language_stdlib_only_link_flags(self) -> T.List[str]: |
| 439 |
# TODO: needs default search path added |
| 440 |
return ['-lifcore', '-limf'] |
| 441 |
|
| 442 |
def get_dependency_gen_args(self, outtarget: str, outfile: str) -> T.List[str]: |
| 443 |
return ['-gen-dep=' + outtarget, '-gen-depformat=make'] |
| 444 |
|
| 445 |
|
| 446 |
class IntelLLVMFortranCompiler(IntelLLVMLikeCompiler, IntelFortranCompiler): |
| 447 |
|
| 448 |
id = 'intel-llvm' |
| 449 |
|
| 450 |
def get_preprocess_only_args(self) -> T.List[str]: |
| 451 |
return ['-preprocess-only'] |
| 452 |
|
| 453 |
def get_dependency_gen_args(self, outtarget: str, outfile: str) -> T.List[str]: |
| 454 |
return [] |
| 455 |
|
| 456 |
class IntelClFortranCompiler(IntelVisualStudioLikeCompiler, FortranCompiler): |
| 457 |
|
| 458 |
always_args = ['/nologo'] |
| 459 |
|
| 460 |
def __init__(self, exelist: T.List[str], version: str, for_machine: MachineChoice, |
| 461 |
env: Environment, target: str, |
| 462 |
linker: T.Optional['DynamicLinker'] = None, |
| 463 |
full_version: T.Optional[str] = None): |
| 464 |
FortranCompiler.__init__(self, exelist, version, for_machine, |
| 465 |
env, linker=linker, full_version=full_version) |
| 466 |
IntelVisualStudioLikeCompiler.__init__(self, target) |
| 467 |
self.file_suffixes = ('f90', 'f', 'for', 'ftn', 'fpp', ) |
| 468 |
|
| 469 |
default_warn_args = ['/warn:general', '/warn:truncated_source'] |
| 470 |
self.warn_args = {'0': [], |
| 471 |
'1': default_warn_args, |
| 472 |
'2': default_warn_args + ['/warn:unused'], |
| 473 |
'3': ['/warn:all'], |
| 474 |
'everything': ['/warn:all']} |
| 475 |
|
| 476 |
def get_options(self) -> 'MutableKeyedOptionDictType': |
| 477 |
opts = super().get_options() |
| 478 |
self._update_language_stds(opts, ['none', 'legacy', 'f95', 'f2003', 'f2008', 'f2018']) |
| 479 |
return opts |
| 480 |
|
| 481 |
def get_option_std_args(self, target: BuildTarget, subproject: T.Optional[str] = None) -> T.List[str]: |
| 482 |
args: T.List[str] = [] |
| 483 |
std = self.get_compileropt_value('std', target, subproject) |
| 484 |
stds = {'legacy': 'none', 'f95': 'f95', 'f2003': 'f03', 'f2008': 'f08', 'f2018': 'f18'} |
| 485 |
assert isinstance(std, str) |
| 486 |
if std != 'none': |
| 487 |
args.append('/stand:' + stds[std]) |
| 488 |
return args |
| 489 |
|
| 490 |
def get_werror_args(self) -> T.List[str]: |
| 491 |
return ['/warn:errors'] |
| 492 |
|
| 493 |
def get_module_outdir_args(self, path: str) -> T.List[str]: |
| 494 |
return ['/module:' + path] |
| 495 |
|
| 496 |
|
| 497 |
class IntelLLVMClFortranCompiler(IntelClFortranCompiler): |
| 498 |
|
| 499 |
id = 'intel-llvm-cl' |
| 500 |
|
| 501 |
class PathScaleFortranCompiler(FortranCompiler): |
| 502 |
|
| 503 |
id = 'pathscale' |
| 504 |
|
| 505 |
def __init__(self, exelist: T.List[str], version: str, for_machine: MachineChoice, |
| 506 |
env: Environment, linker: T.Optional['DynamicLinker'] = None, |
| 507 |
full_version: T.Optional[str] = None): |
| 508 |
FortranCompiler.__init__(self, exelist, version, for_machine, |
| 509 |
env, linker=linker, full_version=full_version) |
| 510 |
default_warn_args = ['-fullwarn'] |
| 511 |
self.warn_args = {'0': [], |
| 512 |
'1': default_warn_args, |
| 513 |
'2': default_warn_args, |
| 514 |
'3': default_warn_args, |
| 515 |
'everything': default_warn_args} |
| 516 |
|
| 517 |
def openmp_flags(self) -> T.List[str]: |
| 518 |
return ['-mp'] |
| 519 |
|
| 520 |
|
| 521 |
class PGIFortranCompiler(PGICompiler, FortranCompiler): |
| 522 |
|
| 523 |
def __init__(self, exelist: T.List[str], version: str, for_machine: MachineChoice, |
| 524 |
env: Environment, linker: T.Optional['DynamicLinker'] = None, |
| 525 |
full_version: T.Optional[str] = None): |
| 526 |
FortranCompiler.__init__(self, exelist, version, for_machine, |
| 527 |
env, linker=linker, full_version=full_version) |
| 528 |
PGICompiler.__init__(self) |
| 529 |
|
| 530 |
default_warn_args = ['-Minform=inform'] |
| 531 |
self.warn_args = {'0': [], |
| 532 |
'1': default_warn_args, |
| 533 |
'2': default_warn_args, |
| 534 |
'3': default_warn_args + ['-Mdclchk'], |
| 535 |
'everything': default_warn_args + ['-Mdclchk']} |
| 536 |
|
| 537 |
def language_stdlib_only_link_flags(self) -> T.List[str]: |
| 538 |
# TODO: needs default search path added |
| 539 |
return ['-lpgf90rtl', '-lpgf90', '-lpgf90_rpm1', '-lpgf902', |
| 540 |
'-lpgf90rtl', '-lpgftnrtl', '-lrt'] |
| 541 |
|
| 542 |
|
| 543 |
class NvidiaHPC_FortranCompiler(PGICompiler, FortranCompiler): |
| 544 |
|
| 545 |
id = 'nvidia_hpc' |
| 546 |
|
| 547 |
def __init__(self, exelist: T.List[str], version: str, for_machine: MachineChoice, |
| 548 |
env: Environment, linker: T.Optional['DynamicLinker'] = None, |
| 549 |
full_version: T.Optional[str] = None): |
| 550 |
FortranCompiler.__init__(self, exelist, version, for_machine, |
| 551 |
env, linker=linker, full_version=full_version) |
| 552 |
PGICompiler.__init__(self) |
| 553 |
|
| 554 |
default_warn_args = ['-Minform=inform'] |
| 555 |
self.warn_args = {'0': [], |
| 556 |
'1': default_warn_args, |
| 557 |
'2': default_warn_args, |
| 558 |
'3': default_warn_args + ['-Mdclchk'], |
| 559 |
'everything': default_warn_args + ['-Mdclchk']} |
| 560 |
|
| 561 |
|
| 562 |
class ClassicFlangFortranCompiler(ClangCompiler, FortranCompiler): |
| 563 |
|
| 564 |
id = 'flang' |
| 565 |
|
| 566 |
def __init__(self, exelist: T.List[str], version: str, for_machine: MachineChoice, |
| 567 |
env: Environment, linker: T.Optional['DynamicLinker'] = None, |
| 568 |
full_version: T.Optional[str] = None): |
| 569 |
FortranCompiler.__init__(self, exelist, version, for_machine, |
| 570 |
env, linker=linker, full_version=full_version) |
| 571 |
ClangCompiler.__init__(self, {}) |
| 572 |
default_warn_args = ['-Minform=inform'] |
| 573 |
self.warn_args = {'0': [], |
| 574 |
'1': default_warn_args, |
| 575 |
'2': default_warn_args, |
| 576 |
'3': default_warn_args, |
| 577 |
'everything': default_warn_args} |
| 578 |
|
| 579 |
def language_stdlib_only_link_flags(self) -> T.List[str]: |
| 580 |
# We need to apply the search prefix here, as these link arguments may |
| 581 |
# be passed to a different compiler with a different set of default |
| 582 |
# search paths, such as when using Clang for C/C++ and gfortran for |
| 583 |
# fortran, |
| 584 |
# XXX: Untested.... |
| 585 |
search_dirs: T.List[str] = [] |
| 586 |
for d in self.get_compiler_dirs('libraries'): |
| 587 |
search_dirs.append(f'-L{d}') |
| 588 |
return search_dirs + ['-lflang', '-lpgmath'] |
| 589 |
|
| 590 |
|
| 591 |
class ArmLtdFlangFortranCompiler(ClassicFlangFortranCompiler): |
| 592 |
|
| 593 |
id = 'armltdflang' |
| 594 |
|
| 595 |
|
| 596 |
class LlvmFlangFortranCompiler(ClangCompiler, FortranCompiler): |
| 597 |
|
| 598 |
id = 'llvm-flang' |
| 599 |
|
| 600 |
def __init__(self, exelist: T.List[str], version: str, for_machine: MachineChoice, |
| 601 |
env: Environment, linker: T.Optional['DynamicLinker'] = None, |
| 602 |
full_version: T.Optional[str] = None): |
| 603 |
FortranCompiler.__init__(self, exelist, version, for_machine, |
| 604 |
env, linker=linker, full_version=full_version) |
| 605 |
ClangCompiler.__init__(self, {}) |
| 606 |
default_warn_args = ['-Wall'] |
| 607 |
self.warn_args = {'0': [], |
| 608 |
'1': default_warn_args, |
| 609 |
'2': default_warn_args, |
| 610 |
'3': default_warn_args, |
| 611 |
'everything': default_warn_args} |
| 612 |
|
| 613 |
def get_colorout_args(self, colortype: str) -> T.List[str]: |
| 614 |
# not yet supported, see https://github.com/llvm/llvm-project/issues/89888 |
| 615 |
return [] |
| 616 |
|
| 617 |
def get_dependency_gen_args(self, outtarget: str, outfile: str) -> T.List[str]: |
| 618 |
# not yet supported, see https://github.com/llvm/llvm-project/issues/89888 |
| 619 |
return [] |
| 620 |
|
| 621 |
def get_module_outdir_args(self, path: str) -> T.List[str]: |
| 622 |
# different syntax from classic flang (which supported `-module`), see |
| 623 |
# https://github.com/llvm/llvm-project/issues/66969 |
| 624 |
return ['-module-dir', path] |
| 625 |
|
| 626 |
def gnu_symbol_visibility_args(self, vistype: str) -> T.List[str]: |
| 627 |
# flang doesn't support symbol visibility flag yet, see |
| 628 |
# https://github.com/llvm/llvm-project/issues/92459 |
| 629 |
return [] |
| 630 |
|
| 631 |
def language_stdlib_only_link_flags(self) -> T.List[str]: |
| 632 |
# matching setup from ClassicFlangFortranCompiler |
| 633 |
search_dirs: T.List[str] = [] |
| 634 |
for d in self.get_compiler_dirs('libraries'): |
| 635 |
search_dirs.append(f'-L{d}') |
| 636 |
# does not automatically link to Fortran_main anymore after |
| 637 |
# https://github.com/llvm/llvm-project/commit/9d6837d595719904720e5ff68ec1f1a2665bdc2f |
| 638 |
# note that this changed again in flang 19 with |
| 639 |
# https://github.com/llvm/llvm-project/commit/8d5386669ed63548daf1bee415596582d6d78d7d; |
| 640 |
# it seems flang 18 doesn't work if something accidentally includes a program unit, see |
| 641 |
# https://github.com/llvm/llvm-project/issues/92496 |
| 642 |
# Only link FortranRuntime and FortranDecimal for flang < 19, see |
| 643 |
# https://github.com/scipy/scipy/issues/21562#issuecomment-2942938509 |
| 644 |
if version_compare(self.version, '<19'): |
| 645 |
search_dirs += ['-lFortranRuntime', '-lFortranDecimal'] |
| 646 |
return search_dirs |
| 647 |
|
| 648 |
|
| 649 |
class Open64FortranCompiler(FortranCompiler): |
| 650 |
|
| 651 |
id = 'open64' |
| 652 |
|
| 653 |
def __init__(self, exelist: T.List[str], version: str, for_machine: MachineChoice, |
| 654 |
env: Environment, linker: T.Optional['DynamicLinker'] = None, |
| 655 |
full_version: T.Optional[str] = None): |
| 656 |
FortranCompiler.__init__(self, exelist, version, for_machine, |
| 657 |
env, linker=linker, full_version=full_version) |
| 658 |
default_warn_args = ['-fullwarn'] |
| 659 |
self.warn_args = {'0': [], |
| 660 |
'1': default_warn_args, |
| 661 |
'2': default_warn_args, |
| 662 |
'3': default_warn_args, |
| 663 |
'everything': default_warn_args} |
| 664 |
|
| 665 |
def openmp_flags(self) -> T.List[str]: |
| 666 |
return ['-mp'] |
| 667 |
|
| 668 |
|
| 669 |
class NAGFortranCompiler(FortranCompiler): |
| 670 |
|
| 671 |
id = 'nagfor' |
| 672 |
|
| 673 |
def __init__(self, exelist: T.List[str], version: str, for_machine: MachineChoice, |
| 674 |
env: Environment, linker: T.Optional['DynamicLinker'] = None, |
| 675 |
full_version: T.Optional[str] = None): |
| 676 |
FortranCompiler.__init__(self, exelist, version, for_machine, |
| 677 |
env, linker=linker, full_version=full_version) |
| 678 |
# Warnings are on by default; -w disables (by category): |
| 679 |
self.warn_args = { |
| 680 |
'0': ['-w=all'], |
| 681 |
'1': [], |
| 682 |
'2': [], |
| 683 |
'3': [], |
| 684 |
'everything': [], |
| 685 |
} |
| 686 |
|
| 687 |
def get_always_args(self) -> T.List[str]: |
| 688 |
return self.get_nagfor_quiet(self.version) |
| 689 |
|
| 690 |
def get_module_outdir_args(self, path: str) -> T.List[str]: |
| 691 |
return ['-mdir', path] |
| 692 |
|
| 693 |
@staticmethod |
| 694 |
def get_nagfor_quiet(version: str) -> T.List[str]: |
| 695 |
return ['-quiet'] if version_compare(version, '>=7100') else [] |
| 696 |
|
| 697 |
def get_pic_args(self) -> T.List[str]: |
| 698 |
return ['-PIC'] |
| 699 |
|
| 700 |
def get_preprocess_only_args(self) -> T.List[str]: |
| 701 |
return ['-fpp'] |
| 702 |
|
| 703 |
def get_std_exe_link_args(self) -> T.List[str]: |
| 704 |
return self.get_always_args() |
| 705 |
|
| 706 |
def openmp_flags(self) -> T.List[str]: |
| 707 |
return ['-openmp'] |