diff options
| author | Paolo Bonzini <pbonzini@redhat.com> | 2025-04-02 14:20:44 +0200 |
|---|---|---|
| committer | Jussi Pakkanen <jpakkane@gmail.com> | 2025-04-04 12:46:55 +0300 |
| commit | ff0c758b2a8015f7e7ca6fc627c29ef7bb4771b3 (patch) | |
| tree | 49de8a9f3a3d17d4f26a7c61e984027243834092 /mesonbuild/compilers/cpp.py | |
| parent | 47984f813450bcbcd102ed45d579011deb4572c1 (diff) | |
| download | meson-ff0c758b2a8015f7e7ca6fc627c29ef7bb4771b3.tar.gz | |
compilers: move -std options to get_option_std_args, special-casing CUDA
Move building the -std option to the new get_option_std_args method,
special casing CUDA to never include the option from the host compiler.
This fixes again #8523, which was broken by the option refactoring
(unsurprisingly, since the fix was ripped out unceremoniously without
a replacement).
Fixes: #14365
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Diffstat (limited to 'mesonbuild/compilers/cpp.py')
| -rw-r--r-- | mesonbuild/compilers/cpp.py | 91 |
1 files changed, 54 insertions, 37 deletions
diff --git a/mesonbuild/compilers/cpp.py b/mesonbuild/compilers/cpp.py index 3768556e6..b85751d05 100644 --- a/mesonbuild/compilers/cpp.py +++ b/mesonbuild/compilers/cpp.py @@ -268,17 +268,13 @@ class ClangCPPCompiler(_StdCPPLibMixin, ClangCPPStds, ClangCompiler, CPPCompiler def get_option_compile_args(self, target: 'BuildTarget', env: 'Environment', subproject: T.Optional[str] = None) -> T.List[str]: args: T.List[str] = [] - std = self.get_compileropt_value('std', env, target, subproject) rtti = self.get_compileropt_value('rtti', env, target, subproject) debugstl = self.get_compileropt_value('debugstl', env, target, subproject) eh = self.get_compileropt_value('eh', env, target, subproject) - assert isinstance(std, str) assert isinstance(rtti, bool) assert isinstance(eh, str) assert isinstance(debugstl, bool) - if std != 'none': - args.append(self._find_best_cpp_std(std)) non_msvc_eh_options(eh, args) @@ -296,6 +292,14 @@ class ClangCPPCompiler(_StdCPPLibMixin, ClangCPPStds, ClangCompiler, CPPCompiler return args + def get_option_std_args(self, target: BuildTarget, env: Environment, subproject: T.Optional[str] = None) -> T.List[str]: + args: T.List[str] = [] + std = self.get_compileropt_value('std', env, target, subproject) + assert isinstance(std, str) + if std != 'none': + args.append(self._find_best_cpp_std(std)) + return args + def get_option_link_args(self, target: 'BuildTarget', env: 'Environment', subproject: T.Optional[str] = None) -> T.List[str]: if self.info.is_windows() or self.info.is_cygwin(): # without a typedict mypy can't understand this. @@ -368,7 +372,7 @@ class EmscriptenCPPCompiler(EmscriptenMixin, ClangCPPCompiler): info, linker=linker, defines=defines, full_version=full_version) - def get_option_compile_args(self, target: 'BuildTarget', env: 'Environment', subproject: T.Optional[str] = None) -> T.List[str]: + def get_option_std_args(self, target: BuildTarget, env: Environment, subproject: T.Optional[str] = None) -> T.List[str]: args: T.List[str] = [] std = self.get_compileropt_value('std', env, target, subproject) assert isinstance(std, str) @@ -412,7 +416,7 @@ class ArmclangCPPCompiler(ArmclangCompiler, CPPCompiler): std_opt.set_versions(['c++98', 'c++03', 'c++11', 'c++14', 'c++17'], gnu=True) return opts - def get_option_compile_args(self, target: 'BuildTarget', env: 'Environment', subproject: T.Optional[str] = None) -> T.List[str]: + def get_option_std_args(self, target: BuildTarget, env: Environment, subproject: T.Optional[str] = None) -> T.List[str]: args: T.List[str] = [] std = self.get_compileropt_value('std', env, target, subproject) assert isinstance(std, str) @@ -481,19 +485,14 @@ class GnuCPPCompiler(_StdCPPLibMixin, GnuCPPStds, GnuCompiler, CPPCompiler): def get_option_compile_args(self, target: 'BuildTarget', env: 'Environment', subproject: T.Optional[str] = None) -> T.List[str]: args: T.List[str] = [] - std = self.get_compileropt_value('std', env, target, subproject) rtti = self.get_compileropt_value('rtti', env, target, subproject) debugstl = self.get_compileropt_value('debugstl', env, target, subproject) eh = self.get_compileropt_value('eh', env, target, subproject) - assert isinstance(std, str) assert isinstance(rtti, bool) assert isinstance(eh, str) assert isinstance(debugstl, bool) - if std != 'none': - args.append(self._find_best_cpp_std(std)) - non_msvc_eh_options(eh, args) if not rtti: @@ -503,6 +502,14 @@ class GnuCPPCompiler(_StdCPPLibMixin, GnuCPPStds, GnuCompiler, CPPCompiler): args.append('-D_GLIBCXX_DEBUG=1') return args + def get_option_std_args(self, target: BuildTarget, env: Environment, subproject: T.Optional[str] = None) -> T.List[str]: + args: T.List[str] = [] + std = self.get_compileropt_value('std', env, target, subproject) + assert isinstance(std, str) + if std != 'none': + args.append(self._find_best_cpp_std(std)) + return args + def get_option_link_args(self, target: 'BuildTarget', env: 'Environment', subproject: T.Optional[str] = None) -> T.List[str]: if self.info.is_windows() or self.info.is_cygwin(): # without a typedict mypy can't understand this. @@ -634,11 +641,6 @@ class ElbrusCPPCompiler(ElbrusCompiler, CPPCompiler): # Elbrus C++ compiler does not support RTTI, so don't check for it. def get_option_compile_args(self, target: 'BuildTarget', env: 'Environment', subproject: T.Optional[str] = None) -> T.List[str]: args: T.List[str] = [] - std = self.get_compileropt_value('std', env, target, subproject) - assert isinstance(std, str) - if std != 'none': - args.append(self._find_best_cpp_std(std)) - eh = self.get_compileropt_value('eh', env, target, subproject) assert isinstance(eh, str) @@ -650,6 +652,14 @@ class ElbrusCPPCompiler(ElbrusCompiler, CPPCompiler): args.append('-D_GLIBCXX_DEBUG=1') return args + def get_option_std_args(self, target: BuildTarget, env: Environment, subproject: T.Optional[str] = None) -> T.List[str]: + args: T.List[str] = [] + std = self.get_compileropt_value('std', env, target, subproject) + assert isinstance(std, str) + if std != 'none': + args.append(self._find_best_cpp_std(std)) + return args + class IntelCPPCompiler(IntelGnuLikeCompiler, CPPCompiler): def __init__(self, ccache: T.List[str], exelist: T.List[str], version: str, for_machine: MachineChoice, is_cross: bool, @@ -711,22 +721,14 @@ class IntelCPPCompiler(IntelGnuLikeCompiler, CPPCompiler): def get_option_compile_args(self, target: 'BuildTarget', env: 'Environment', subproject: T.Optional[str] = None) -> T.List[str]: args: T.List[str] = [] - std = self.get_compileropt_value('std', env, target, subproject) rtti = self.get_compileropt_value('rtti', env, target, subproject) debugstl = self.get_compileropt_value('debugstl', env, target, subproject) eh = self.get_compileropt_value('eh', env, target, subproject) - assert isinstance(std, str) assert isinstance(rtti, bool) assert isinstance(eh, str) assert isinstance(debugstl, bool) - if std != 'none': - remap_cpp03 = { - 'c++03': 'c++98', - 'gnu++03': 'gnu++98' - } - args.append('-std=' + remap_cpp03.get(std, std)) if eh == 'none': args.append('-fno-exceptions') if rtti: @@ -735,6 +737,19 @@ class IntelCPPCompiler(IntelGnuLikeCompiler, CPPCompiler): args.append('-D_GLIBCXX_DEBUG=1') return args + def get_option_std_args(self, target: BuildTarget, env: Environment, subproject: T.Optional[str] = None) -> T.List[str]: + args: T.List[str] = [] + std = self.get_compileropt_value('std', env, target, subproject) + assert isinstance(std, str) + if std != 'none': + remap_cpp03 = { + 'c++03': 'c++98', + 'gnu++03': 'gnu++98' + } + args.append('-std=' + remap_cpp03.get(std, std)) + + return args + def get_option_link_args(self, target: 'BuildTarget', env: 'Environment', subproject: T.Optional[str] = None) -> T.List[str]: return [] @@ -801,11 +816,9 @@ class VisualStudioLikeCPPCompilerMixin(CompilerMixinBase): def get_option_compile_args(self, target: 'BuildTarget', env: 'Environment', subproject: T.Optional[str] = None) -> T.List[str]: args: T.List[str] = [] - std = self.get_compileropt_value('std', env, target, subproject) eh = self.get_compileropt_value('eh', env, target, subproject) rtti = self.get_compileropt_value('rtti', env, target, subproject) - assert isinstance(std, str) assert isinstance(rtti, bool) assert isinstance(eh, str) @@ -819,14 +832,18 @@ class VisualStudioLikeCPPCompilerMixin(CompilerMixinBase): if not rtti: args.append('/GR-') - permissive, ver = self.VC_VERSION_MAP[std] + return args + + def get_option_std_args(self, target: BuildTarget, env: Environment, subproject: T.Optional[str] = None) -> T.List[str]: + args: T.List[str] = [] + std = self.get_compileropt_value('std', env, target, subproject) + assert isinstance(std, str) + permissive, ver = self.VC_VERSION_MAP[std] if ver is not None: args.append(f'/std:c++{ver}') - if not permissive: args.append('/permissive-') - return args def get_compiler_check_args(self, mode: CompileCheckMode) -> T.List[str]: @@ -840,7 +857,7 @@ class CPP11AsCPP14Mixin(CompilerMixinBase): This is a limitation of Clang and MSVC that ICL doesn't share. """ - def get_option_compile_args(self, target: 'BuildTarget', env: 'Environment', subproject: T.Optional[str] = None) -> T.List[str]: + def get_option_std_args(self, target: BuildTarget, env: Environment, subproject: T.Optional[str] = None) -> T.List[str]: # Note: there is no explicit flag for supporting C++11; we attempt to do the best we can # which means setting the C++ standard version to C++14, in compilers that support it # (i.e., after VS2015U3) @@ -854,7 +871,7 @@ class CPP11AsCPP14Mixin(CompilerMixinBase): mlog.warning(self.id, 'does not support C++11;', 'attempting best effort; setting the standard to C++14', once=True, fatal=False) - original_args = super().get_option_compile_args(target, env, subproject) + original_args = super().get_option_std_args(target, env, subproject) std_mapping = {'/std:c++11': '/std:c++14', '/std:c++14': '/std:vc++14'} processed_args = [std_mapping.get(x, x) for x in original_args] @@ -891,12 +908,12 @@ class VisualStudioCPPCompiler(CPP11AsCPP14Mixin, VisualStudioLikeCPPCompilerMixi cpp_stds.extend(['c++20', 'vc++20']) return self._get_options_impl(super().get_options(), cpp_stds) - def get_option_compile_args(self, target: 'BuildTarget', env: 'Environment', subproject: T.Optional[str] = None) -> T.List[str]: + def get_option_std_args(self, target: BuildTarget, env: Environment, subproject: T.Optional[str] = None) -> T.List[str]: std = self.get_compileropt_value('std', env, target, subproject) if std != 'none' and version_compare(self.version, '<19.00.24210'): mlog.warning('This version of MSVC does not support cpp_std arguments', fatal=False) - args = super().get_option_compile_args(target, env, subproject) + args = super().get_option_std_args(target, env, subproject) if version_compare(self.version, '<19.11'): try: @@ -969,7 +986,7 @@ class ArmCPPCompiler(ArmCompiler, CPPCompiler): std_opt.set_versions(['c++03', 'c++11']) return opts - def get_option_compile_args(self, target: 'BuildTarget', env: 'Environment', subproject: T.Optional[str] = None) -> T.List[str]: + def get_option_std_args(self, target: BuildTarget, env: Environment, subproject: T.Optional[str] = None) -> T.List[str]: args: T.List[str] = [] std = self.get_compileropt_value('std', env, target, subproject) assert isinstance(std, str) @@ -1028,7 +1045,7 @@ class TICPPCompiler(TICompiler, CPPCompiler): std_opt.set_versions(['c++03']) return opts - def get_option_compile_args(self, target: 'BuildTarget', env: 'Environment', subproject: T.Optional[str] = None) -> T.List[str]: + def get_option_std_args(self, target: BuildTarget, env: Environment, subproject: T.Optional[str] = None) -> T.List[str]: args: T.List[str] = [] std = self.get_compileropt_value('std', env, target, subproject) assert isinstance(std, str) @@ -1068,7 +1085,7 @@ class MetrowerksCPPCompilerARM(MetrowerksCompiler, CPPCompiler): self._update_language_stds(opts, []) return opts - def get_option_compile_args(self, target: 'BuildTarget', env: 'Environment', subproject: T.Optional[str] = None) -> T.List[str]: + def get_option_std_args(self, target: BuildTarget, env: Environment, subproject: T.Optional[str] = None) -> T.List[str]: args: T.List[str] = [] std = self.get_compileropt_value('std', env, target, subproject) assert isinstance(std, str) @@ -1096,7 +1113,7 @@ class MetrowerksCPPCompilerEmbeddedPowerPC(MetrowerksCompiler, CPPCompiler): self._update_language_stds(opts, []) return opts - def get_option_compile_args(self, target: 'BuildTarget', env: 'Environment', subproject: T.Optional[str] = None) -> T.List[str]: + def get_option_std_args(self, target: BuildTarget, env: Environment, subproject: T.Optional[str] = None) -> T.List[str]: args: T.List[str] = [] std = self.get_compileropt_value('std', env, target, subproject) assert isinstance(std, str) |
