backends: Always take options from target

This fixes cases where override_options is not being used.

Fixes: #11923
pull/11964/head
Xavier Claessens 2 years ago committed by Jussi Pakkanen
parent 4166bf1eb2
commit 08972c1277
  1. 6
      mesonbuild/backend/backends.py
  2. 21
      mesonbuild/backend/ninjabackend.py
  3. 32
      mesonbuild/backend/vs2010backend.py
  4. 3
      mesonbuild/backend/xcodebackend.py

@ -945,6 +945,12 @@ class Backend:
mesonlib.replace_if_different(pch_file, pch_file_tmp)
return pch_rel_to_build
def target_uses_pch(self, target: build.BuildTarget) -> bool:
try:
return T.cast('bool', target.get_option(OptionKey('b_pch')))
except KeyError:
return False
@staticmethod
def escape_extra_args(args: T.List[str]) -> T.List[str]:
# all backslashes in defines are doubly-escaped

@ -970,7 +970,7 @@ class NinjaBackend(backends.Backend):
if s.split('.')[-1] in compilers.lang_suffixes['d']:
d_generated_deps.append(o)
use_pch = self.environment.coredata.options.get(OptionKey('b_pch'))
use_pch = self.target_uses_pch(target)
if use_pch and target.has_pch():
pch_objects = self.generate_pch(target, header_deps=header_deps)
else:
@ -1068,7 +1068,7 @@ class NinjaBackend(backends.Backend):
cpp = target.compilers['cpp']
if cpp.get_id() != 'msvc':
return False
cppversion = self.environment.coredata.options[OptionKey('std', machine=target.for_machine, lang='cpp')].value
cppversion = target.get_option(OptionKey('std', machine=target.for_machine, lang='cpp'))
if cppversion not in ('latest', 'c++latest', 'vc++latest'):
return False
if not mesonlib.current_vs_supports_modules():
@ -1662,7 +1662,7 @@ class NinjaBackend(backends.Backend):
valac_outputs.append(vala_c_file)
args = self.generate_basic_compiler_args(target, valac)
args += valac.get_colorout_args(self.environment.coredata.options.get(OptionKey('b_colorout')).value)
args += valac.get_colorout_args(target.get_option(OptionKey('b_colorout')))
# Tell Valac to output everything in our private directory. Sadly this
# means it will also preserve the directory components of Vala sources
# found inside the build tree (generated sources).
@ -1984,8 +1984,8 @@ class NinjaBackend(backends.Backend):
crt_link_args: T.List[str] = []
try:
buildtype = self.environment.coredata.options[OptionKey('buildtype')].value
crt = self.environment.coredata.options[OptionKey('b_vscrt')].value
buildtype = target.get_option(OptionKey('buildtype'))
crt = target.get_option(OptionKey('b_vscrt'))
is_debug = buildtype == 'debug'
if crt == 'from_buildtype':
@ -2943,7 +2943,7 @@ https://gcc.gnu.org/bugzilla/show_bug.cgi?id=47485'''))
def generate_common_compile_args_per_src_type(self, target: build.BuildTarget) -> dict[str, list[str]]:
src_type_to_args = {}
use_pch = self.environment.coredata.options.get(OptionKey('b_pch'))
use_pch = self.target_uses_pch(target)
for src_type_str in target.compilers.keys():
compiler = target.compilers[src_type_str]
@ -2984,7 +2984,7 @@ https://gcc.gnu.org/bugzilla/show_bug.cgi?id=47485'''))
# Include PCH header as first thing as it must be the first one or it will be
# ignored by gcc https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100462
use_pch = self.environment.coredata.options.get(OptionKey('b_pch')) and is_generated != 'pch'
use_pch = self.target_uses_pch(target) and is_generated != 'pch'
if use_pch and 'mw' not in compiler.id:
commands += self.get_pch_include_args(compiler, target)
@ -3023,7 +3023,7 @@ https://gcc.gnu.org/bugzilla/show_bug.cgi?id=47485'''))
commands += self.get_compile_debugfile_args(compiler, target, rel_obj)
# PCH handling
if self.environment.coredata.options.get(OptionKey('b_pch')):
if self.target_uses_pch(target):
pchlist = target.get_pch(compiler.language)
else:
pchlist = []
@ -3245,8 +3245,7 @@ https://gcc.gnu.org/bugzilla/show_bug.cgi?id=47485'''))
commands += linker.get_pie_link_args()
elif isinstance(target, build.SharedLibrary):
if isinstance(target, build.SharedModule):
options = self.environment.coredata.options
commands += linker.get_std_shared_module_link_args(options)
commands += linker.get_std_shared_module_link_args(target.get_options())
else:
commands += linker.get_std_shared_lib_link_args()
# All shared libraries are PIC
@ -3528,7 +3527,7 @@ https://gcc.gnu.org/bugzilla/show_bug.cgi?id=47485'''))
#
# We shouldn't check whether we are making a static library, because
# in the LTO case we do use a real compiler here.
commands += linker.get_option_link_args(self.environment.coredata.options)
commands += linker.get_option_link_args(target.get_options())
dep_targets = []
dep_targets.extend(self.guess_external_link_dependencies(linker, target, commands, internal))

@ -1059,8 +1059,7 @@ class Vs2010Backend(backends.Backend):
# Compile args added from the env or cross file: CFLAGS/CXXFLAGS, etc. We want these
# to override all the defaults, but not the per-target compile args.
for l in file_args.keys():
opts = self.environment.coredata.options[OptionKey('args', machine=target.for_machine, lang=l)]
file_args[l] += opts.value
file_args[l] += target.get_option(OptionKey('args', machine=target.for_machine, lang=l))
for args in file_args.values():
# This is where Visual Studio will insert target_args, target_defines,
# etc, which are added later from external deps (see below).
@ -1355,29 +1354,29 @@ class Vs2010Backend(backends.Backend):
if True in ((dep.name == 'openmp') for dep in target.get_external_deps()):
ET.SubElement(clconf, 'OpenMPSupport').text = 'true'
# CRT type; debug or release
vscrt_type = self.environment.coredata.options[OptionKey('b_vscrt')]
if vscrt_type.value == 'from_buildtype':
vscrt_type = target.get_option(OptionKey('b_vscrt'))
if vscrt_type == 'from_buildtype':
if self.buildtype == 'debug':
ET.SubElement(type_config, 'UseDebugLibraries').text = 'true'
ET.SubElement(clconf, 'RuntimeLibrary').text = 'MultiThreadedDebugDLL'
else:
ET.SubElement(type_config, 'UseDebugLibraries').text = 'false'
ET.SubElement(clconf, 'RuntimeLibrary').text = 'MultiThreadedDLL'
elif vscrt_type.value == 'static_from_buildtype':
elif vscrt_type == 'static_from_buildtype':
if self.buildtype == 'debug':
ET.SubElement(type_config, 'UseDebugLibraries').text = 'true'
ET.SubElement(clconf, 'RuntimeLibrary').text = 'MultiThreadedDebug'
else:
ET.SubElement(type_config, 'UseDebugLibraries').text = 'false'
ET.SubElement(clconf, 'RuntimeLibrary').text = 'MultiThreaded'
elif vscrt_type.value == 'mdd':
elif vscrt_type == 'mdd':
ET.SubElement(type_config, 'UseDebugLibraries').text = 'true'
ET.SubElement(clconf, 'RuntimeLibrary').text = 'MultiThreadedDebugDLL'
elif vscrt_type.value == 'mt':
elif vscrt_type == 'mt':
# FIXME, wrong
ET.SubElement(type_config, 'UseDebugLibraries').text = 'false'
ET.SubElement(clconf, 'RuntimeLibrary').text = 'MultiThreaded'
elif vscrt_type.value == 'mtd':
elif vscrt_type == 'mtd':
# FIXME, wrong
ET.SubElement(type_config, 'UseDebugLibraries').text = 'true'
ET.SubElement(clconf, 'RuntimeLibrary').text = 'MultiThreadedDebug'
@ -1406,12 +1405,12 @@ class Vs2010Backend(backends.Backend):
# Exception handling has to be set in the xml in addition to the "AdditionalOptions" because otherwise
# cl will give warning D9025: overriding '/Ehs' with cpp_eh value
if 'cpp' in target.compilers:
eh = self.environment.coredata.options[OptionKey('eh', machine=target.for_machine, lang='cpp')]
if eh.value == 'a':
eh = target.get_option(OptionKey('eh', machine=target.for_machine, lang='cpp'))
if eh == 'a':
ET.SubElement(clconf, 'ExceptionHandling').text = 'Async'
elif eh.value == 's':
elif eh == 's':
ET.SubElement(clconf, 'ExceptionHandling').text = 'SyncCThrow'
elif eh.value == 'none':
elif eh == 'none':
ET.SubElement(clconf, 'ExceptionHandling').text = 'false'
else: # 'sc' or 'default'
ET.SubElement(clconf, 'ExceptionHandling').text = 'Sync'
@ -1470,8 +1469,7 @@ class Vs2010Backend(backends.Backend):
ET.SubElement(link, 'GenerateDebugInformation').text = 'false'
if not isinstance(target, build.StaticLibrary):
if isinstance(target, build.SharedModule):
options = self.environment.coredata.options
extra_link_args += compiler.get_std_shared_module_link_args(options)
extra_link_args += compiler.get_std_shared_module_link_args(target.get_options())
# Add link args added using add_project_link_arguments()
extra_link_args += self.build.get_project_link_args(compiler, target.subproject, target.for_machine)
# Add link args added using add_global_link_arguments()
@ -1504,7 +1502,7 @@ class Vs2010Backend(backends.Backend):
# to be after all internal and external libraries so that unresolved
# symbols from those can be found here. This is needed when the
# *_winlibs that we want to link to are static mingw64 libraries.
extra_link_args += compiler.get_option_link_args(self.environment.coredata.options)
extra_link_args += compiler.get_option_link_args(target.get_options())
(additional_libpaths, additional_links, extra_link_args) = self.split_link_args(extra_link_args.to_native())
# Add more libraries to be linked if needed
@ -1605,7 +1603,7 @@ class Vs2010Backend(backends.Backend):
# /nologo
ET.SubElement(link, 'SuppressStartupBanner').text = 'true'
# /release
if not self.environment.coredata.get_option(OptionKey('debug')):
if not target.get_option(OptionKey('debug')):
ET.SubElement(link, 'SetChecksum').text = 'true'
# Visual studio doesn't simply allow the src files of a project to be added with the 'Condition=...' attribute,
@ -1732,7 +1730,7 @@ class Vs2010Backend(backends.Backend):
return False
pch_sources = {}
if self.environment.coredata.options.get(OptionKey('b_pch')):
if self.target_uses_pch(target):
for lang in ['c', 'cpp']:
pch = target.get_pch(lang)
if not pch:

@ -1495,8 +1495,7 @@ class XCodeBackend(backends.Backend):
else:
raise RuntimeError(o)
if isinstance(target, build.SharedModule):
options = self.environment.coredata.options
ldargs += linker.get_std_shared_module_link_args(options)
ldargs += linker.get_std_shared_module_link_args(target.get_options())
elif isinstance(target, build.SharedLibrary):
ldargs += linker.get_std_shared_lib_link_args()
ldstr = ' '.join(ldargs)

Loading…
Cancel
Save