aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--docs/markdown/Builtin-options.md2
-rw-r--r--mesonbuild/backend/backends.py2
-rw-r--r--mesonbuild/backend/ninjabackend.py2
-rw-r--r--mesonbuild/backend/vs2010backend.py9
-rw-r--r--mesonbuild/compilers/c.py6
-rw-r--r--mesonbuild/compilers/compilers.py31
-rw-r--r--mesonbuild/compilers/d.py4
-rw-r--r--mesonbuild/coredata.py19
-rw-r--r--mesonbuild/interpreter.py35
-rw-r--r--mesonbuild/mconf.py21
-rw-r--r--mesonbuild/modules/gnome.py8
11 files changed, 62 insertions, 77 deletions
diff --git a/docs/markdown/Builtin-options.md b/docs/markdown/Builtin-options.md
index 62a37f4..39db4fa 100644
--- a/docs/markdown/Builtin-options.md
+++ b/docs/markdown/Builtin-options.md
@@ -100,9 +100,11 @@ compiler being used:
| Option | Default value | Possible values | Description
| ------ | ------------- | --------------- | -----------
| c_args | | free-form comma-separated list | C compile arguments to use
+| c_link_args | | free-form comma-separated list | C link arguments to use
| c_std | none | none, c89, c99, c11, gnu89, gnu99, gnu11 | C language standard to use
| c_winlibs | see below | free-form comma-separated list | Standard Windows libs to link against
| cpp_args | | free-form comma-separated list | C++ compile arguments to use
+| cpp_link_args| | free-form comma-separated list | C++ link arguments to use
| cpp_std | none | none, c++98, c++03, c++11, c++14, c++17, <br/>c++1z, gnu++03, gnu++11, gnu++14, gnu++17, gnu++1z | C++ language standard to use
| cpp_debugstl | false | true, false | C++ STL debug mode
| cpp_eh | sc | none, a, s, sc | C++ exception handling type
diff --git a/mesonbuild/backend/backends.py b/mesonbuild/backend/backends.py
index 7a50431..d347e66 100644
--- a/mesonbuild/backend/backends.py
+++ b/mesonbuild/backend/backends.py
@@ -510,7 +510,7 @@ class Backend:
if not target.is_cross:
# Compile args added from the env: CFLAGS/CXXFLAGS, etc. We want these
# to override all the defaults, but not the per-target compile args.
- commands += self.environment.coredata.external_args[compiler.get_language()]
+ commands += self.environment.coredata.get_external_args(compiler.get_language())
# Always set -fPIC for shared libraries
if isinstance(target, build.SharedLibrary):
commands += compiler.get_pic_args()
diff --git a/mesonbuild/backend/ninjabackend.py b/mesonbuild/backend/ninjabackend.py
index cd43b69..0398401 100644
--- a/mesonbuild/backend/ninjabackend.py
+++ b/mesonbuild/backend/ninjabackend.py
@@ -2555,7 +2555,7 @@ rule FORTRAN_DEP_HACK%s
if not target.is_cross:
# Link args added from the env: LDFLAGS. We want these to
# override all the defaults but not the per-target link args.
- commands += self.environment.coredata.external_link_args[linker.get_language()]
+ commands += self.environment.coredata.get_external_link_args(linker.get_language())
# Now we will add libraries and library paths from various sources
diff --git a/mesonbuild/backend/vs2010backend.py b/mesonbuild/backend/vs2010backend.py
index 0ff7157..dc2660b 100644
--- a/mesonbuild/backend/vs2010backend.py
+++ b/mesonbuild/backend/vs2010backend.py
@@ -793,9 +793,10 @@ class Vs2010Backend(backends.Backend):
if not target.is_cross:
# Compile args added from the env: CFLAGS/CXXFLAGS, etc. We want these
# to override all the defaults, but not the per-target compile args.
- for l, args in self.environment.coredata.external_args.items():
- if l in file_args:
- file_args[l] += args
+ for key, opt in self.environment.coredata.compiler_options.items():
+ l, suffix = key.split('_', 1)
+ if suffix == 'args' and l in file_args:
+ file_args[l] += opt.value
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).
@@ -960,7 +961,7 @@ class Vs2010Backend(backends.Backend):
if not target.is_cross:
# Link args added from the env: LDFLAGS. We want these to
# override all the defaults but not the per-target link args.
- extra_link_args += self.environment.coredata.external_link_args[compiler.get_language()]
+ extra_link_args += self.environment.coredata.get_external_link_args(compiler.get_language())
# Only non-static built targets need link args and link dependencies
extra_link_args += target.link_args
# External deps must be last because target link libraries may depend on them.
diff --git a/mesonbuild/compilers/c.py b/mesonbuild/compilers/c.py
index 09ac99c..e14d3d8 100644
--- a/mesonbuild/compilers/c.py
+++ b/mesonbuild/compilers/c.py
@@ -351,13 +351,13 @@ class CCompiler(Compiler):
if not self.is_cross:
if mode == 'preprocess':
# Add CPPFLAGS from the env.
- args += env.coredata.external_preprocess_args[self.language]
+ args += env.coredata.get_external_preprocess_args(self.language)
elif mode == 'compile':
# Add CFLAGS/CXXFLAGS/OBJCFLAGS/OBJCXXFLAGS from the env
- args += env.coredata.external_args[self.language]
+ args += env.coredata.get_external_args(self.language)
elif mode == 'link':
# Add LDFLAGS from the env
- args += env.coredata.external_link_args[self.language]
+ args += env.coredata.get_external_link_args(self.language)
args += self.get_compiler_check_args()
# extra_args must override all other arguments, so we add them last
args += extra_args
diff --git a/mesonbuild/compilers/compilers.py b/mesonbuild/compilers/compilers.py
index 7ac0753..fcb658b 100644
--- a/mesonbuild/compilers/compilers.py
+++ b/mesonbuild/compilers/compilers.py
@@ -725,6 +725,11 @@ class Compiler:
"""
return []
+ def get_preproc_flags(self):
+ if self.get_language() in ('c', 'cpp', 'objc', 'objcpp'):
+ return os.environ.get('CPPFLAGS', '')
+ return ''
+
def get_args_from_envvars(self):
"""
Returns a tuple of (compile_flags, link_flags) for the specified language
@@ -740,7 +745,7 @@ class Compiler:
compiler_is_linker = (self.get_exelist() == self.get_linker_exelist())
if lang not in cflags_mapping:
- return [], [], []
+ return [], []
compile_flags = os.environ.get(cflags_mapping[lang], '')
log_var(cflags_mapping[lang], compile_flags)
@@ -758,17 +763,31 @@ class Compiler:
link_flags = compile_flags + link_flags
# Pre-processor flags (not for fortran or D)
- preproc_flags = ''
- if lang in ('c', 'cpp', 'objc', 'objcpp'):
- preproc_flags = os.environ.get('CPPFLAGS', '')
+ preproc_flags = self.get_preproc_flags()
log_var('CPPFLAGS', preproc_flags)
preproc_flags = shlex.split(preproc_flags)
compile_flags += preproc_flags
- return preproc_flags, compile_flags, link_flags
+ return compile_flags, link_flags
def get_options(self):
- return {} # build afresh every time
+ opts = {} # build afresh every time
+
+ # Take default values from env variables.
+ compile_args, link_args = self.get_args_from_envvars()
+ description = 'Extra arguments passed to the {}'.format(self.get_display_language())
+ opts.update({
+ self.language + '_args': coredata.UserArrayOption(
+ self.language + '_args',
+ description + ' compiler',
+ compile_args, shlex_split=True, user_input=True),
+ self.language + '_link_args': coredata.UserArrayOption(
+ self.language + '_link_args',
+ description + ' linker',
+ link_args, shlex_split=True, user_input=True),
+ })
+
+ return opts
def get_option_compile_args(self, options):
return []
diff --git a/mesonbuild/compilers/d.py b/mesonbuild/compilers/d.py
index 474e1bd..5cb3659 100644
--- a/mesonbuild/compilers/d.py
+++ b/mesonbuild/compilers/d.py
@@ -180,10 +180,10 @@ class DCompiler(Compiler):
if mode == 'compile':
# Add DFLAGS from the env
- args += env.coredata.external_args[self.language]
+ args += env.coredata.get_external_args(self.language)
elif mode == 'link':
# Add LDFLAGS from the env
- args += env.coredata.external_link_args[self.language]
+ args += env.coredata.get_external_link_args(self.language)
# extra_args must override all other arguments, so we add them last
args += extra_args
return args
diff --git a/mesonbuild/coredata.py b/mesonbuild/coredata.py
index aaadfcb..1e2a213 100644
--- a/mesonbuild/coredata.py
+++ b/mesonbuild/coredata.py
@@ -13,7 +13,7 @@
# limitations under the License.
from . import mlog
-import pickle, os, uuid
+import pickle, os, uuid, shlex
import sys
from pathlib import PurePath
from collections import OrderedDict
@@ -138,10 +138,10 @@ class UserComboOption(UserOption):
return value
class UserArrayOption(UserOption):
- def __init__(self, name, description, value, shlex_split=False, **kwargs):
+ def __init__(self, name, description, value, shlex_split=False, user_input=False, **kwargs):
super().__init__(name, description, kwargs.get('choices', []), yielding=kwargs.get('yielding', None))
self.shlex_split = shlex_split
- self.value = self.validate_value(value, user_input=False)
+ self.value = self.validate_value(value, user_input=user_input)
def validate_value(self, value, user_input=True):
# User input is for options defined on the command line (via -D
@@ -201,11 +201,7 @@ class CoreData:
self.user_options = {}
self.compiler_options = {}
self.base_options = {}
- # These external_*args, are set via env vars CFLAGS, LDFLAGS, etc
- # but only when not cross-compiling.
self.external_preprocess_args = {} # CPPFLAGS only
- self.external_args = {} # CPPFLAGS + CFLAGS
- self.external_link_args = {} # CFLAGS + LDFLAGS (with MSVC: only LDFLAGS)
self.cross_file = self.__load_cross_file(options.cross_file)
self.wrap_mode = options.wrap_mode
self.compilers = OrderedDict()
@@ -340,6 +336,15 @@ class CoreData:
return opt.validate_value(override_value)
raise MesonException('Tried to validate unknown option %s.' % option_name)
+ def get_external_args(self, lang):
+ return self.compiler_options[lang + '_args'].value
+
+ def get_external_link_args(self, lang):
+ return self.compiler_options[lang + '_link_args'].value
+
+ def get_external_preprocess_args(self, lang):
+ return self.external_preprocess_args[lang]
+
def load(build_dir):
filename = os.path.join(build_dir, 'meson-private', 'coredata.dat')
load_fail_msg = 'Coredata file {!r} is corrupted. Try with a fresh build tree.'.format(filename)
diff --git a/mesonbuild/interpreter.py b/mesonbuild/interpreter.py
index dcd54a3..0dbe8ca 100644
--- a/mesonbuild/interpreter.py
+++ b/mesonbuild/interpreter.py
@@ -2193,18 +2193,6 @@ to directly access options of other subprojects.''')
return opt.value
except KeyError:
pass
- if optname.endswith('_link_args'):
- try:
- lang = optname[:-10]
- return self.coredata.external_link_args[lang]
- except KeyError:
- pass
- if optname.endswith('_args'):
- try:
- lang = optname[:-5]
- return self.coredata.external_args[lang]
- except KeyError:
- pass
# Some base options are not defined in some environments, return the default value.
try:
return compilers.base_options[optname].value
@@ -2443,6 +2431,13 @@ to directly access options of other subprojects.''')
new_options[i].set_value(value)
new_options.update(self.coredata.compiler_options)
self.coredata.compiler_options = new_options
+
+ # Unlike compiler and linker flags, preprocessor flags are not in
+ # compiler_options because they are not visible to user.
+ preproc_flags = comp.get_preproc_flags()
+ preproc_flags = shlex.split(preproc_flags)
+ self.coredata.external_preprocess_args.setdefault(lang, preproc_flags)
+
return comp, cross_comp
def add_languages(self, args, required):
@@ -2469,22 +2464,6 @@ to directly access options of other subprojects.''')
version_string = ' (%s %s)' % (comp.id, comp.version)
mlog.log('Native %s compiler: ' % comp.get_display_language(), mlog.bold(' '.join(comp.get_exelist())), version_string, sep='')
- # If <language>_args/_link_args settings are given on the
- # command line, use them, otherwise take them from env.
- (preproc_args, compile_args, link_args) = comp.get_args_from_envvars()
- for optspec in self.build.environment.cmd_line_options.projectoptions:
- (optname, optvalue) = optspec.split('=', maxsplit=1)
- if optname == lang + '_link_args':
- link_args = shlex.split(optvalue)
- elif optname.endswith('_args'):
- compile_args = shlex.split(optvalue)
- if lang not in self.coredata.external_preprocess_args:
- self.coredata.external_preprocess_args[lang] = preproc_args
- if lang not in self.coredata.external_args:
- self.coredata.external_args[lang] = compile_args
- if lang not in self.coredata.external_link_args:
- self.coredata.external_link_args[lang] = link_args
-
self.build.add_compiler(comp)
if need_cross_compiler:
mlog.log('Cross %s compiler: ' % cross_comp.get_display_language(), mlog.bold(' '.join(cross_comp.get_exelist())), ' (%s %s)' % (cross_comp.id, cross_comp.version), sep='')
diff --git a/mesonbuild/mconf.py b/mesonbuild/mconf.py
index f65d6ff..9ac5d4a 100644
--- a/mesonbuild/mconf.py
+++ b/mesonbuild/mconf.py
@@ -114,21 +114,6 @@ class Conf:
elif k in self.coredata.base_options:
tgt = self.coredata.base_options[k]
tgt.set_value(v)
- elif k.endswith('_link_args'):
- lang = k[:-10]
- if lang not in self.coredata.external_link_args:
- raise ConfException('Unknown language %s in linkargs.' % lang)
- # TODO, currently split on spaces, make it so that user
- # can pass in an array string.
- newvalue = shlex.split(v)
- self.coredata.external_link_args[lang] = newvalue
- elif k.endswith('_args'):
- lang = k[:-5]
- if lang not in self.coredata.external_args:
- raise ConfException('Unknown language %s in compile args' % lang)
- # TODO same fix as above
- newvalue = shlex.split(v)
- self.coredata.external_args[lang] = newvalue
else:
raise ConfException('Unknown option %s.' % k)
@@ -161,12 +146,6 @@ class Conf:
o = self.coredata.base_options[k]
coarr.append({'name': k, 'descr': o.description, 'value': o.value, 'choices': o.choices})
self.print_aligned(coarr)
- print('\nCompiler arguments:')
- for (lang, args) in self.coredata.external_args.items():
- print(' ' + lang + '_args', str(args))
- print('\nLinker args:')
- for (lang, args) in self.coredata.external_link_args.items():
- print(' ' + lang + '_link_args', str(args))
print('\nCompiler options:')
if not self.coredata.compiler_options:
print(' No compiler options\n')
diff --git a/mesonbuild/modules/gnome.py b/mesonbuild/modules/gnome.py
index 0c5da17..436a0e4 100644
--- a/mesonbuild/modules/gnome.py
+++ b/mesonbuild/modules/gnome.py
@@ -570,7 +570,7 @@ class GnomeModule(ExtensionModule):
ldflags += list(dep_ldflags)
scan_command += ['--cflags-begin']
scan_command += cflags
- scan_command += state.environment.coredata.external_args[lang]
+ scan_command += state.environment.coredata.get_external_args(lang)
scan_command += ['--cflags-end']
# need to put our output directory first as we need to use the
# generated libraries instead of any possibly installed system/prefix
@@ -602,7 +602,7 @@ class GnomeModule(ExtensionModule):
scan_command.append('-L' + d)
scan_command += ['--library', libname]
- for link_arg in state.environment.coredata.external_link_args[lang]:
+ for link_arg in state.environment.coredata.get_external_link_args(lang):
if link_arg.startswith('-L'):
scan_command.append(link_arg)
@@ -838,8 +838,8 @@ This will become a hard error in the future.''')
raise MesonException(
'Gir include dirs should be include_directories().')
cflags.update(get_include_args(inc_dirs))
- cflags.update(state.environment.coredata.external_args['c'])
- ldflags.update(state.environment.coredata.external_link_args['c'])
+ cflags.update(state.environment.coredata.get_external_args('c'))
+ ldflags.update(state.environment.coredata.get_external_link_args('c'))
if cflags:
args += ['--cflags=%s' % ' '.join(cflags)]
if ldflags: