From 7eb1d89095054286391565a23c6a4d27465dd617 Mon Sep 17 00:00:00 2001 From: Dylan Baker Date: Thu, 18 Oct 2018 09:15:48 -0700 Subject: [PATCH] compilers: Move lto args into compiler class There are two problems, one is that it assumes -flto is the argument to do LTO/WPO, which isn't true of ICC and MSVC (and presumably) others. It's also incorrect because it assumes that the compiler and linker will always be the same, which isn't necessarily true. You could combine GCC with Apple's linker, or clang with link.exe, which use different arguments. --- mesonbuild/compilers/compilers.py | 14 +++++++++----- mesonbuild/compilers/mixins/gnu.py | 6 ++++++ 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/mesonbuild/compilers/compilers.py b/mesonbuild/compilers/compilers.py index df448f039..4ab4dc661 100644 --- a/mesonbuild/compilers/compilers.py +++ b/mesonbuild/compilers/compilers.py @@ -13,7 +13,7 @@ # limitations under the License. import contextlib, enum, os.path, re, tempfile, shlex -from typing import Optional, Tuple +from typing import Optional, Tuple, List from ..linkers import StaticLinker from .. import coredata @@ -278,10 +278,9 @@ def option_enabled(boptions, options, option): def get_base_compile_args(options, compiler): args = [] - # FIXME, gcc/clang specific. try: if options['b_lto'].value: - args.append('-flto') + args.extend(compiler.get_lto_compile_args()) except KeyError: pass try: @@ -328,10 +327,9 @@ def get_base_compile_args(options, compiler): def get_base_link_args(options, linker, is_shared_module): args = [] - # FIXME, gcc/clang specific. try: if options['b_lto'].value: - args.append('-flto') + args.extend(linker.get_lto_link_args()) except KeyError: pass try: @@ -1197,6 +1195,12 @@ class Compiler: def remove_linkerlike_args(self, args): return [x for x in args if not x.startswith('-Wl')] + def get_lto_compile_args(self) -> List[str]: + return [] + + def get_lto_link_args(self) -> List[str]: + return [] + @enum.unique class CompilerType(enum.Enum): diff --git a/mesonbuild/compilers/mixins/gnu.py b/mesonbuild/compilers/mixins/gnu.py index 46f04c4f1..c5750450e 100644 --- a/mesonbuild/compilers/mixins/gnu.py +++ b/mesonbuild/compilers/mixins/gnu.py @@ -366,6 +366,12 @@ class GnuLikeCompiler(metaclass=abc.ABCMeta): return self._split_fetch_real_dirs(line.split('=', 1)[1]) return [] + def get_lto_compile_args(self) -> typing.List[str]: + return ['-flto'] + + def get_lto_link_args(self) -> typing.List[str]: + return ['-flto'] + class GnuCompiler(GnuLikeCompiler): """