Don't collect preprocssor flags separately from compiler flags

I recall that @jpakkane never wanted this, but @nirbheek did, but then
@nirbheek changed his mind.

I am fine either way except for the cross inconsistency that exists
today: There is no `c_preproc_args` or similar one can put in the cross
file, so no way to replicate the effect of CPPFLAGS during cross
compilation.
pull/5171/head
John Ericson 6 years ago committed by Nirbheek Chauhan
parent 151961056c
commit e677704d21
  1. 7
      mesonbuild/compilers/c.py
  2. 20
      mesonbuild/compilers/compilers.py
  3. 24
      mesonbuild/coredata.py
  4. 4
      mesonbuild/munstable_coredata.py

@ -422,11 +422,8 @@ class CCompiler(Compiler):
for_machine = MachineChoice.BUILD for_machine = MachineChoice.BUILD
else: else:
for_machine = MachineChoice.HOST for_machine = MachineChoice.HOST
if mode == 'preprocess': if mode in {'compile', 'preprocess'}:
# Add CPPFLAGS from the env. # Add CFLAGS/CXXFLAGS/OBJCFLAGS/OBJCXXFLAGS and CPPFLAGS from the env
args += env.coredata.get_external_preprocess_args(for_machine, self.language)
elif mode == 'compile':
# Add CFLAGS/CXXFLAGS/OBJCFLAGS/OBJCXXFLAGS from the env
sys_args = env.coredata.get_external_args(for_machine, self.language) sys_args = env.coredata.get_external_args(for_machine, self.language)
# Apparently it is a thing to inject linker flags both # Apparently it is a thing to inject linker flags both
# via CFLAGS _and_ LDFLAGS, even though the former are # via CFLAGS _and_ LDFLAGS, even though the former are

@ -970,10 +970,11 @@ class Compiler:
""" """
return [] return []
def get_preproc_flags(self): def use_preproc_flags(self):
if self.get_language() in ('c', 'cpp', 'objc', 'objcpp'): """
return os.environ.get('CPPFLAGS', '') Whether the compiler (or processes it spawns) cares about CPPFLAGS
return '' """
return self.get_language() in ('c', 'cpp', 'objc', 'objcpp')
def get_args_from_envvars(self): def get_args_from_envvars(self):
""" """
@ -1007,11 +1008,12 @@ class Compiler:
# this when the linker is stand-alone such as with MSVC C/C++, etc. # this when the linker is stand-alone such as with MSVC C/C++, etc.
link_flags = compile_flags + link_flags link_flags = compile_flags + link_flags
# Pre-processor flags (not for fortran or D) # Pre-processor flags for certain languages
preproc_flags = self.get_preproc_flags() if self.use_preproc_flags():
log_var('CPPFLAGS', preproc_flags) preproc_flags = os.environ.get('CPPFLAGS', '')
preproc_flags = shlex.split(preproc_flags) log_var('CPPFLAGS', preproc_flags)
compile_flags += preproc_flags preproc_flags = shlex.split(preproc_flags)
compile_flags += preproc_flags
return compile_flags, link_flags return compile_flags, link_flags

@ -264,7 +264,6 @@ class CoreData:
self.user_options = {} self.user_options = {}
self.compiler_options = PerMachine({}, {}, {}) self.compiler_options = PerMachine({}, {}, {})
self.base_options = {} self.base_options = {}
self.external_preprocess_args = PerMachine({}, {}, {}) # CPPFLAGS only
self.cross_files = self.__load_config_files(options.cross_file) self.cross_files = self.__load_config_files(options.cross_file)
self.compilers = OrderedDict() self.compilers = OrderedDict()
self.cross_compilers = OrderedDict() self.cross_compilers = OrderedDict()
@ -446,9 +445,6 @@ class CoreData:
def get_external_link_args(self, for_machine: MachineChoice, lang): def get_external_link_args(self, for_machine: MachineChoice, lang):
return self.compiler_options[for_machine][lang + '_link_args'].value return self.compiler_options[for_machine][lang + '_link_args'].value
def get_external_preprocess_args(self, for_machine: MachineChoice, lang):
return self.external_preprocess_args[for_machine][lang]
def merge_user_options(self, options): def merge_user_options(self, options):
for (name, value) in options.items(): for (name, value) in options.items():
if name not in self.user_options: if name not in self.user_options:
@ -532,21 +528,18 @@ class CoreData:
# Native compiler always exist so always add its options. # Native compiler always exist so always add its options.
new_options_for_build = comp.get_and_default_options(env.properties.build) new_options_for_build = comp.get_and_default_options(env.properties.build)
preproc_flags_for_build = comp.get_preproc_flags()
if cross_comp is not None: if cross_comp is not None:
new_options_for_host = cross_comp.get_and_default_options(env.properties.host) new_options_for_host = cross_comp.get_and_default_options(env.properties.host)
preproc_flags_for_host = cross_comp.get_preproc_flags()
else: else:
new_options_for_host = comp.get_and_default_options(env.properties.host) new_options_for_host = comp.get_and_default_options(env.properties.host)
preproc_flags_for_host = comp.get_preproc_flags()
opts_machines_list = [ opts_machines_list = [
(new_options_for_build, preproc_flags_for_build, MachineChoice.BUILD), (new_options_for_build, MachineChoice.BUILD),
(new_options_for_host, preproc_flags_for_host, MachineChoice.HOST), (new_options_for_host, MachineChoice.HOST),
] ]
optprefix = lang + '_' optprefix = lang + '_'
for new_options, preproc_flags, for_machine in opts_machines_list: for new_options, for_machine in opts_machines_list:
for k, o in new_options.items(): for k, o in new_options.items():
if not k.startswith(optprefix): if not k.startswith(optprefix):
raise MesonException('Internal error, %s has incorrect prefix.' % k) raise MesonException('Internal error, %s has incorrect prefix.' % k)
@ -556,17 +549,6 @@ class CoreData:
o.set_value(env.cmd_line_options[k]) o.set_value(env.cmd_line_options[k])
self.compiler_options[for_machine].setdefault(k, o) self.compiler_options[for_machine].setdefault(k, o)
# Unlike compiler and linker flags, preprocessor flags are not in
# compiler_options because they are not visible to user.
preproc_flags = shlex.split(preproc_flags)
k = lang + '_args'
if lang in ('c', 'cpp', 'objc', 'objcpp') and k in env.properties[for_machine]:
# `c_args` in the cross file are used, like CPPFLAGS but *not*
# CFLAGS, for tests. this is weird, but how it was already
# implemented. Hopefully a new version of #3916 fixes it.
preproc_flags = stringlistify(env.properties[for_machine][k])
self.external_preprocess_args[for_machine].setdefault(lang, preproc_flags)
enabled_opts = [] enabled_opts = []
for optname in comp.base_options: for optname in comp.base_options:
if optname in self.base_options: if optname in self.base_options:

@ -118,10 +118,6 @@ def run(options):
print('Cached dependencies:') print('Cached dependencies:')
for dep_key, dep in cross: for dep_key, dep in cross:
print_dep(dep_key, dep) print_dep(dep_key, dep)
elif k == 'external_preprocess_args':
for lang, opts in v.items():
if opts:
print('Preprocessor args for ' + lang + ': ' + ' '.join(opts))
else: else:
print(k + ':') print(k + ':')
print(textwrap.indent(pprint.pformat(v), ' ')) print(textwrap.indent(pprint.pformat(v), ' '))

Loading…
Cancel
Save