Only append compile flags to the link flags when appropriate

We should only append the compiler flags to the link flags when the
compiler is used as a wrapper around the linker during the link process
pull/673/head
Nirbheek Chauhan 8 years ago
parent 5b7e4ac1f6
commit a5e01fa155
  1. 12
      mesonbuild/environment.py
  2. 5
      mesonbuild/interpreter.py

@ -701,7 +701,7 @@ class Environment():
return self.coredata.get_builtin_option('datadir')
def get_args_from_envvars(lang):
def get_args_from_envvars(lang, compiler_is_linker):
"""
@lang: Language to fetch environment flags for
@ -727,15 +727,21 @@ def get_args_from_envvars(lang):
link_flags = os.environ.get('LDFLAGS', '')
log_var('LDFLAGS', link_flags)
link_flags = link_flags.split()
if compiler_is_linker:
# When the compiler is used as a wrapper around the linker (such as
# with GCC and Clang), the compile flags can be needed while linking
# too. This is also what Autotools does. However, we don't want to do
# this when the linker is stand-alone such as with MSVC C/C++, etc.
link_flags = compile_flags + link_flags
# Pre-processof rlags (not for fortran)
preproc_flags = ''
if lang in ('c', 'cpp', 'objc', 'objcpp'):
preproc_flags = os.environ.get('CPPFLAGS', '')
log_var('CPPFLAGS', preproc_flags)
preproc_flags = preproc_flags.split()
compile_flags += preproc_flags.split()
return (compile_flags + preproc_flags, link_flags + compile_flags)
return (compile_flags, link_flags)
class CrossBuildInfo():
def __init__(self, filename):

@ -1619,8 +1619,11 @@ class Interpreter():
else:
raise
mlog.log('Native %s compiler: ' % lang, mlog.bold(' '.join(comp.get_exelist())), ' (%s %s)' % (comp.id, comp.version), sep='')
compiler_is_linker = False
if hasattr(comp, 'get_linker_exelist'):
compiler_is_linker = (comp.get_exelist() == comp.get_linker_exelist())
if not comp.get_language() in self.coredata.external_args:
(ext_compile_args, ext_link_args) = environment.get_args_from_envvars(comp.get_language())
(ext_compile_args, ext_link_args) = environment.get_args_from_envvars(comp.get_language(), compiler_is_linker)
self.coredata.external_args[comp.get_language()] = ext_compile_args
self.coredata.external_link_args[comp.get_language()] = ext_link_args
self.build.add_compiler(comp)

Loading…
Cancel
Save