Use helper method in remaining compiler classes.

opthelper
Jussi Pakkanen 6 months ago
parent 9589143aec
commit b3c09ea4f4
  1. 12
      mesonbuild/compilers/cuda.py
  2. 14
      mesonbuild/compilers/cython.py

@ -13,7 +13,7 @@ from .. import options
from .. import mlog
from ..mesonlib import (
EnvironmentException, Popen_safe,
is_windows, LibType, OptionKey, version_compare,
is_windows, LibType, version_compare,
)
from .compilers import Compiler
@ -645,12 +645,12 @@ class CudaCompiler(Compiler):
return self.update_options(
super().get_options(),
self.create_option(options.UserComboOption,
OptionKey('std', machine=self.for_machine, lang=self.language),
self.form_langopt_key('std'),
'C++ language standard to use with CUDA',
cpp_stds,
'none'),
self.create_option(options.UserStringOption,
OptionKey('ccbindir', machine=self.for_machine, lang=self.language),
self.form_langopt_key('ccbindir'),
'CUDA non-default toolchain directory to use (-ccbin)',
''),
)
@ -663,7 +663,7 @@ class CudaCompiler(Compiler):
# We must strip the -std option from the host compiler option set, as NVCC has
# its own -std flag that may not agree with the host compiler's.
host_options = {key: options.get(key, opt) for key, opt in self.host_compiler.get_options().items()}
std_key = OptionKey('std', machine=self.for_machine, lang=self.host_compiler.language)
std_key = self.form_langopt_key('std')
overrides = {std_key: 'none'}
return coredata.OptionsView(host_options, overrides=overrides)
@ -673,7 +673,7 @@ class CudaCompiler(Compiler):
# the combination of CUDA version and MSVC version; the --std= is thus ignored
# and attempting to use it will result in a warning: https://stackoverflow.com/a/51272091/741027
if not is_windows():
key = OptionKey('std', machine=self.for_machine, lang=self.language)
key = self.form_langopt_key('std')
std = options[key]
if std.value != 'none':
args.append('--std=' + std.value)
@ -793,7 +793,7 @@ class CudaCompiler(Compiler):
return self._to_host_flags(super().get_dependency_link_args(dep), _Phase.LINKER)
def get_ccbin_args(self, options: 'KeyedOptionDictType') -> T.List[str]:
key = OptionKey('ccbindir', machine=self.for_machine, lang=self.language)
key = self.form_langopt_key('ccbindir')
ccbindir = options[key].value
if isinstance(ccbindir, str) and ccbindir != '':
return [self._shield_nvcc_list_arg('-ccbin='+ccbindir, False)]

@ -7,7 +7,7 @@ from __future__ import annotations
import typing as T
from .. import options
from ..mesonlib import EnvironmentException, OptionKey, version_compare
from ..mesonlib import EnvironmentException, version_compare
from .compilers import Compiler
if T.TYPE_CHECKING:
@ -70,12 +70,12 @@ class CythonCompiler(Compiler):
return self.update_options(
super().get_options(),
self.create_option(options.UserComboOption,
OptionKey('version', machine=self.for_machine, lang=self.language),
self.form_langopt_key('version'),
'Python version to target',
['2', '3'],
'3'),
self.create_option(options.UserComboOption,
OptionKey('language', machine=self.for_machine, lang=self.language),
self.form_langopt_key('language'),
'Output C or C++ files',
['c', 'cpp'],
'c'),
@ -83,9 +83,11 @@ class CythonCompiler(Compiler):
def get_option_compile_args(self, options: 'KeyedOptionDictType') -> T.List[str]:
args: T.List[str] = []
key = options[OptionKey('version', machine=self.for_machine, lang=self.language)]
args.append(f'-{key.value}')
lang = options[OptionKey('language', machine=self.for_machine, lang=self.language)]
key = self.form_langopt_key('version')
version = options[key]
args.append(f'-{version.value}')
key = self.form_langopt_key('language')
lang = options[key]
if lang.value == 'cpp':
args.append('--cplus')
return args

Loading…
Cancel
Save