From f58bd2ae11429ee7aa911de631faece718fbfe14 Mon Sep 17 00:00:00 2001 From: Dylan Baker Date: Thu, 29 Jun 2023 09:05:50 -0700 Subject: [PATCH] compilers/cpp: use a Mixin to share the stdlib flags between clang++ and g++ Which will make subsequent work easier --- mesonbuild/compilers/cpp.py | 33 +++++++++++++++------------------ 1 file changed, 15 insertions(+), 18 deletions(-) diff --git a/mesonbuild/compilers/cpp.py b/mesonbuild/compilers/cpp.py index 6eaa6c87e..bec452916 100644 --- a/mesonbuild/compilers/cpp.py +++ b/mesonbuild/compilers/cpp.py @@ -183,7 +183,20 @@ class CPPCompiler(CLikeCompiler, Compiler): return opts -class ClangCPPCompiler(ClangCompiler, CPPCompiler): +class _StdCPPLibMixin(CompilerMixinBase): + + """Detect whether to use libc++ or libstdc++.""" + + def language_stdlib_only_link_flags(self, env: 'Environment') -> T.List[str]: + # We need to apply the search prefix here, as these link arguments may + # be passed to a different compiler with a different set of default + # search paths, such as when using Clang for C/C++ and gfortran for + # fortran, + search_dirs = [f'-L{d}' for d in self.get_compiler_dirs(env, 'libraries')] + return search_dirs + ['-lstdc++'] + + +class ClangCPPCompiler(_StdCPPLibMixin, ClangCompiler, CPPCompiler): def __init__(self, ccache: T.List[str], exelist: T.List[str], version: str, for_machine: MachineChoice, is_cross: bool, info: 'MachineInfo', exe_wrapper: T.Optional['ExternalProgram'] = None, linker: T.Optional['DynamicLinker'] = None, @@ -249,14 +262,6 @@ class ClangCPPCompiler(ClangCompiler, CPPCompiler): return libs return [] - def language_stdlib_only_link_flags(self, env: 'Environment') -> T.List[str]: - # We need to apply the search prefix here, as these link arguments may - # be passed to a different compiler with a different set of default - # search paths, such as when using Clang for C/C++ and gfortran for - # fortran, - search_dirs = [f'-L{d}' for d in self.get_compiler_dirs(env, 'libraries')] - return search_dirs + ['-lstdc++'] - class ArmLtdClangCPPCompiler(ClangCPPCompiler): @@ -349,7 +354,7 @@ class ArmclangCPPCompiler(ArmclangCompiler, CPPCompiler): return [] -class GnuCPPCompiler(GnuCompiler, CPPCompiler): +class GnuCPPCompiler(_StdCPPLibMixin, GnuCompiler, CPPCompiler): def __init__(self, ccache: T.List[str], exelist: T.List[str], version: str, for_machine: MachineChoice, is_cross: bool, info: 'MachineInfo', exe_wrapper: T.Optional['ExternalProgram'] = None, linker: T.Optional['DynamicLinker'] = None, @@ -430,14 +435,6 @@ class GnuCPPCompiler(GnuCompiler, CPPCompiler): def get_pch_use_args(self, pch_dir: str, header: str) -> T.List[str]: return ['-fpch-preprocess', '-include', os.path.basename(header)] - def language_stdlib_only_link_flags(self, env: 'Environment') -> T.List[str]: - # We need to apply the search prefix here, as these link arguments may - # be passed to a different compiler with a different set of default - # search paths, such as when using Clang for C/C++ and gfortran for - # fortran, - search_dirs = [f'-L{d}' for d in self.get_compiler_dirs(env, 'libraries')] - return search_dirs + ['-lstdc++'] - class PGICPPCompiler(PGICompiler, CPPCompiler): def __init__(self, ccache: T.List[str], exelist: T.List[str], version: str, for_machine: MachineChoice, is_cross: bool,