diff options
Diffstat (limited to 'mesonbuild/compilers/compilers.py')
-rw-r--r-- | mesonbuild/compilers/compilers.py | 81 |
1 files changed, 48 insertions, 33 deletions
diff --git a/mesonbuild/compilers/compilers.py b/mesonbuild/compilers/compilers.py index 0de59a4da..c31439cff 100644 --- a/mesonbuild/compilers/compilers.py +++ b/mesonbuild/compilers/compilers.py @@ -23,7 +23,7 @@ from .. import mlog from .. import mesonlib from ..linkers import LinkerEnvVarsMixin from ..mesonlib import ( - EnvironmentException, MachineChoice, MesonException, + EnvironmentException, Language, MachineChoice, MesonException, Popen_safe, split_args ) from ..envconfig import ( @@ -49,52 +49,67 @@ lib_suffixes = ('a', 'lib', 'dll', 'dll.a', 'dylib', 'so') # Mapping of language to suffixes of files that should always be in that language # This means we can't include .h headers here since they could be C, C++, ObjC, etc. lang_suffixes = { - 'c': ('c',), - 'cpp': ('cpp', 'cc', 'cxx', 'c++', 'hh', 'hpp', 'ipp', 'hxx', 'ino'), - 'cuda': ('cu',), + Language.C: ('c',), + Language.CPP: ('cpp', 'cc', 'cxx', 'c++', 'hh', 'hpp', 'ipp', 'hxx', 'ino'), + Language.CUDA: ('cu',), # f90, f95, f03, f08 are for free-form fortran ('f90' recommended) # f, for, ftn, fpp are for fixed-form fortran ('f' or 'for' recommended) - 'fortran': ('f90', 'f95', 'f03', 'f08', 'f', 'for', 'ftn', 'fpp'), - 'd': ('d', 'di'), - 'objc': ('m',), - 'objcpp': ('mm',), - 'rust': ('rs',), - 'vala': ('vala', 'vapi', 'gs'), - 'cs': ('cs',), - 'swift': ('swift',), - 'java': ('java',), + Language.FORTRAN: ('f90', 'f95', 'f03', 'f08', 'f', 'for', 'ftn', 'fpp'), + Language.D: ('d', 'di'), + Language.OBJC: ('m',), + Language.OBJCPP: ('mm',), + Language.RUST: ('rs',), + Language.VALA: ('vala', 'vapi', 'gs'), + Language.CS: ('cs',), + Language.SWIFT: ('swift',), + Language.JAVA: ('java',), } all_languages = lang_suffixes.keys() -cpp_suffixes = lang_suffixes['cpp'] + ('h',) -c_suffixes = lang_suffixes['c'] + ('h',) +cpp_suffixes = lang_suffixes[Language.CPP] + ('h',) +c_suffixes = lang_suffixes[Language.C] + ('h',) # List of languages that by default consume and output libraries following the # C ABI; these can generally be used interchangebly -clib_langs = ('objcpp', 'cpp', 'objc', 'c', 'fortran',) +clib_langs = (Language.OBJCPP, Language.CPP, Language.OBJC, Language.C, Language.FORTRAN,) # List of languages that can be linked with C code directly by the linker # used in build.py:process_compilers() and build.py:get_dynamic_linker() -clink_langs = ('d', 'cuda') + clib_langs +clink_langs = (Language.D, Language.CUDA) + clib_langs clink_suffixes = () -for _l in clink_langs + ('vala',): +for _l in clink_langs + (Language.VALA,): clink_suffixes += lang_suffixes[_l] clink_suffixes += ('h', 'll', 's') all_suffixes = set(itertools.chain(*lang_suffixes.values(), clink_suffixes)) # Languages that should use LDFLAGS arguments when linking. -languages_using_ldflags = {'objcpp', 'cpp', 'objc', 'c', 'fortran', 'd', 'cuda'} +languages_using_ldflags = { + Language.OBJCPP, + Language.CPP, + Language.OBJC, + Language.C, + Language.FORTRAN, + Language.D, + Language.CUDA +} # Languages that should use CPPFLAGS arguments when linking. -languages_using_cppflags = {'c', 'cpp', 'objc', 'objcpp'} +languages_using_cppflags = { + Language.C, + Language.CPP, + Language.OBJC, + Language.OBJCPP, +} soregex = re.compile(r'.*\.so(\.[0-9]+)?(\.[0-9]+)?(\.[0-9]+)?$') # Environment variables that each lang uses. -cflags_mapping = {'c': 'CFLAGS', - 'cpp': 'CXXFLAGS', - 'cuda': 'CUFLAGS', - 'objc': 'OBJCFLAGS', - 'objcpp': 'OBJCXXFLAGS', - 'fortran': 'FFLAGS', - 'd': 'DFLAGS', - 'vala': 'VALAFLAGS', - 'rust': 'RUSTFLAGS'} +cflags_mapping = { + Language.C: 'CFLAGS', + Language.CPP: 'CXXFLAGS', + Language.CUDA: 'CUFLAGS', + Language.OBJC: 'OBJCFLAGS', + Language.OBJCPP: 'OBJCXXFLAGS', + Language.FORTRAN: 'FFLAGS', + Language.D: 'DFLAGS', + Language.VALA: 'VALAFLAGS', + Language.RUST: 'RUSTFLAGS', +} # All these are only for C-linkable languages; see `clink_langs` above. @@ -474,7 +489,7 @@ class Compiler(metaclass=abc.ABCMeta): @classmethod def get_display_language(cls) -> str: - return cls.language.capitalize() + return cls.language.get_display_name() def get_default_suffix(self) -> str: return self.default_suffix @@ -909,7 +924,7 @@ def get_largefile_args(compiler): return [] -def get_args_from_envvars(lang: str, +def get_args_from_envvars(lang: Language, for_machine: MachineChoice, is_cross: bool, use_linker_args: bool) -> T.Tuple[T.List[str], T.List[str]]: @@ -946,7 +961,7 @@ def get_args_from_envvars(lang: str, return compile_flags, link_flags -def get_global_options(lang: str, +def get_global_options(lang: Language, comp: T.Type[Compiler], for_machine: MachineChoice, is_cross: bool, @@ -970,7 +985,7 @@ def get_global_options(lang: str, comp.INVOKES_LINKER) for k, o in opts.items(): - user_k = lang + '_' + k + user_k = lang.get_lower_case_name() + '_' + k if user_k in properties: # Get from configuration files. o.set_value(properties[user_k]) |