diff options
author | Yevhenii Kolesnikov <yevhenii.kolesnikov@globallogic.com> | 2020-05-21 18:58:47 +0300 |
---|---|---|
committer | Jussi Pakkanen <jpakkane@gmail.com> | 2020-05-22 16:58:12 +0300 |
commit | 9dc3ca2c1c9fbb47e731551c6432df144f725261 (patch) | |
tree | 404adf95bb405fcef5a048d490922046ae14d960 /mesonbuild/environment.py | |
parent | 29ef4478df6d3aaca40c7993f125b29409be1de2 (diff) | |
download | meson-9dc3ca2c1c9fbb47e731551c6432df144f725261.zip meson-9dc3ca2c1c9fbb47e731551c6432df144f725261.tar.gz meson-9dc3ca2c1c9fbb47e731551c6432df144f725261.tar.bz2 |
compilers: add fetching of define list for clang
Simmilar to gcc, the list of pre-processor defines can be fetched with
`-dM -E` option. The way cpu_family is determined on linux relies on
this list.
Fixes incorrect value of cpu_family on linux, when crosscompiling:
```
CC="clang -m32" meson ./build
```
Signed-off-by: Yevhenii Kolesnikov <yevhenii.kolesnikov@globallogic.com>
Co-authored-by: Dylan Baker <dylan@pnwbakers.com>
Diffstat (limited to 'mesonbuild/environment.py')
-rw-r--r-- | mesonbuild/environment.py | 26 |
1 files changed, 25 insertions, 1 deletions
diff --git a/mesonbuild/environment.py b/mesonbuild/environment.py index 8fad628..cb6ae7d 100644 --- a/mesonbuild/environment.py +++ b/mesonbuild/environment.py @@ -726,6 +726,28 @@ class Environment: minor = defines.get('__LCC_MINOR__', '0') return dot.join((generation, major, minor)) + @staticmethod + def get_clang_compiler_defines(compiler): + """ + Get the list of Clang pre-processor defines + """ + args = compiler + ['-E', '-dM', '-'] + p, output, error = Popen_safe(args, write='', stdin=subprocess.PIPE) + if p.returncode != 0: + raise EnvironmentException('Unable to get clang pre-processor defines:\n' + output + error) + defines = {} + for line in output.split('\n'): + if not line: + continue + d, *rest = line.split(' ', 2) + if d != '#define': + continue + if len(rest) == 1: + defines[rest] = True + if len(rest) == 2: + defines[rest[0]] = rest[1] + return defines + def _get_compilers(self, lang, for_machine): ''' The list of compilers is detected in the exact same way for @@ -1043,6 +1065,8 @@ class Environment: if 'clang' in out: linker = None + defines = self.get_clang_compiler_defines(compiler) + # Even if the for_machine is darwin, we could be using vanilla # clang. if 'Apple' in out: @@ -1063,7 +1087,7 @@ class Environment: return cls( ccache + compiler, version, for_machine, is_cross, info, - exe_wrap, full_version=full_version, linker=linker) + exe_wrap, defines, full_version=full_version, linker=linker) if 'Intel(R) C++ Intel(R)' in err: version = search_version(err) |