diff options
author | Dylan Baker <dylan@pnwbakers.com> | 2023-06-29 09:05:50 -0700 |
---|---|---|
committer | Dylan Baker <dylan@pnwbakers.com> | 2023-06-29 11:57:10 -0700 |
commit | f58bd2ae11429ee7aa911de631faece718fbfe14 (patch) | |
tree | 9b3d8c29aaa5825b35b4abc6f198d468e979ac9c | |
parent | a4b597a7b7b8c9d2129fbd93a985021c7d6742d6 (diff) | |
download | meson-f58bd2ae11429ee7aa911de631faece718fbfe14.zip meson-f58bd2ae11429ee7aa911de631faece718fbfe14.tar.gz meson-f58bd2ae11429ee7aa911de631faece718fbfe14.tar.bz2 |
compilers/cpp: use a Mixin to share the stdlib flags between clang++ and g++
Which will make subsequent work easier
-rw-r--r-- | mesonbuild/compilers/cpp.py | 33 |
1 files changed, 15 insertions, 18 deletions
diff --git a/mesonbuild/compilers/cpp.py b/mesonbuild/compilers/cpp.py index 6eaa6c8..bec4529 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, |