From 582e1ede806bb6e540eb9d87ac86c06f88f67d12 Mon Sep 17 00:00:00 2001 From: Paulo Antonio Alvarez Date: Fri, 11 Nov 2016 07:26:51 -0200 Subject: [PATCH 1/2] environment: Static method to get gcc version from compiler defines The method takes a dictionary with defines names as keys and the defines values as values. From it, we assemble the gcc version, using 0 as a default value if the define we want is not defined. --- mesonbuild/environment.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/mesonbuild/environment.py b/mesonbuild/environment.py index f7045f466..6d9a3a403 100644 --- a/mesonbuild/environment.py +++ b/mesonbuild/environment.py @@ -331,6 +331,13 @@ class Environment(): if len(rest) == 2: defines[rest[0]] = rest[1] return defines + @staticmethod + def get_gnu_version_from_defines(defines): + dot = '.' + major = defines.get('__GNUC__', '0') + minor = defines.get('__GNUC_MINOR__', '0') + patch = defines.get('__GNUC_PATCHLEVEL__', '0') + return dot.join((major, minor, patch)) @staticmethod def get_gnu_compiler_type(defines): From 1e54a5e73ccd172cee65a10c619a23c28f598f6e Mon Sep 17 00:00:00 2001 From: Paulo Antonio Alvarez Date: Fri, 11 Nov 2016 07:40:22 -0200 Subject: [PATCH 2/2] environment: Use GNU defines to get version of c, c++, objc and fortran According to https://gcc.gnu.org/onlinedocs/cpp/Common-Predefined-Macros.html, the macros used to get the version are always defined for those languages, so use them to get the version. --- mesonbuild/environment.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/mesonbuild/environment.py b/mesonbuild/environment.py index 6d9a3a403..405685c37 100644 --- a/mesonbuild/environment.py +++ b/mesonbuild/environment.py @@ -392,6 +392,7 @@ class Environment(): popen_exceptions[compiler] = 'no pre-processor defines' continue gtype = self.get_gnu_compiler_type(defines) + version = self.get_gnu_version_from_defines(defines) return GnuCCompiler(ccache + [compiler], version, gtype, is_cross, exe_wrap, defines) if 'clang' in out: if 'Apple' in out: @@ -450,6 +451,7 @@ class Environment(): popen_exceptions[compiler] = 'no pre-processor defines' continue gtype = self.get_gnu_compiler_type(defines) + version = self.get_gnu_version_from_defines(defines) return GnuFortranCompiler([compiler], version, gtype, is_cross, exe_wrap, defines) if 'G95' in out: @@ -531,6 +533,7 @@ class Environment(): popen_exceptions[compiler] = 'no pre-processor defines' continue gtype = self.get_gnu_compiler_type(defines) + version = self.get_gnu_version_from_defines(defines) return GnuCPPCompiler(ccache + [compiler], version, gtype, is_cross, exe_wrap, defines) if 'clang' in out: if 'Apple' in out: @@ -570,6 +573,7 @@ class Environment(): version = search_version(out) if 'Free Software Foundation' in out: defines = self.get_gnu_compiler_defines(exelist) + version = self.get_gnu_version_from_defines(defines) return GnuObjCCompiler(exelist, version, is_cross, exe_wrap, defines) if out.startswith('Apple LLVM'): return ClangObjCCompiler(exelist, version, CLANG_OSX, is_cross, exe_wrap)