Use CPPFLAGS for pre-processor compiler checks

Also don't add CFLAGS twice for links() checks

Includes a test for this.
pull/1511/head
Nirbheek Chauhan 8 years ago
parent 09fee02dd9
commit 6042e21e25
  1. 14
      mesonbuild/compilers.py
  2. 7
      mesonbuild/coredata.py
  3. 6
      mesonbuild/environment.py
  4. 7
      mesonbuild/interpreter.py
  5. 15
      run_unittests.py
  6. 9
      test cases/common/140 get define/meson.build
  7. 1
      test cases/common/140 get define/meson_options.txt

@ -953,12 +953,14 @@ class CCompiler(Compiler):
# Read c_args/cpp_args/etc from the cross-info file (if needed)
args += self.get_cross_extra_flags(env, compile=(mode != 'preprocess'),
link=(mode == 'link'))
# Add CFLAGS/CXXFLAGS/OBJCFLAGS/OBJCXXFLAGS from the env
# We assume that the user has ensured these are compiler-specific
args += env.coredata.external_args[self.language]
# Add LDFLAGS from the env. We assume that the user has ensured these
# are compiler-specific
if mode == 'link':
if mode == 'preprocess':
# Add CPPFLAGS from the env.
args += env.coredata.external_preprocess_args[self.language]
elif mode == 'compile':
# Add CFLAGS/CXXFLAGS/OBJCFLAGS/OBJCXXFLAGS from the env
args += env.coredata.external_args[self.language]
elif mode == 'link':
# Add LDFLAGS from the env
args += env.coredata.external_link_args[self.language]
args += self.get_compiler_check_args()
# extra_args must override all other arguments, so we add them last

@ -148,10 +148,11 @@ class CoreData:
self.user_options = {}
self.compiler_options = {}
self.base_options = {}
# These two, external_*args, are set via env vars CFLAGS, LDFLAGS, etc
# These external_*args, are set via env vars CFLAGS, LDFLAGS, etc
# but only when not cross-compiling.
self.external_args = {}
self.external_link_args = {}
self.external_preprocess_args = {} # CPPFLAGS only
self.external_args = {} # CPPFLAGS + CFLAGS
self.external_link_args = {} # CFLAGS + LDFLAGS (with MSVC: only LDFLAGS)
if options.cross_file is not None:
self.cross_file = os.path.join(os.getcwd(), options.cross_file)
else:

@ -770,7 +770,7 @@ def get_args_from_envvars(compiler):
compiler_is_linker = (compiler.get_exelist() == compiler.get_linker_exelist())
if lang not in ('c', 'cpp', 'objc', 'objcpp', 'fortran', 'd'):
return [], []
return [], [], []
# Compile flags
cflags_mapping = {'c': 'CFLAGS',
@ -794,7 +794,7 @@ def get_args_from_envvars(compiler):
# 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)
# Pre-processor flags (not for fortran or D)
preproc_flags = ''
if lang in ('c', 'cpp', 'objc', 'objcpp'):
preproc_flags = os.environ.get('CPPFLAGS', '')
@ -802,7 +802,7 @@ def get_args_from_envvars(compiler):
preproc_flags = shlex.split(preproc_flags)
compile_flags += preproc_flags
return compile_flags, link_flags
return preproc_flags, compile_flags, link_flags
class CrossBuildInfo:
def __init__(self, filename):

@ -1787,9 +1787,10 @@ class Interpreter(InterpreterBase):
raise
mlog.log('Native %s compiler: ' % lang, mlog.bold(' '.join(comp.get_exelist())), ' (%s %s)' % (comp.id, comp.version), sep='')
if not comp.get_language() in self.coredata.external_args:
(ext_compile_args, ext_link_args) = environment.get_args_from_envvars(comp)
self.coredata.external_args[comp.get_language()] = ext_compile_args
self.coredata.external_link_args[comp.get_language()] = ext_link_args
(preproc_args, compile_args, link_args) = environment.get_args_from_envvars(comp)
self.coredata.external_preprocess_args[comp.get_language()] = preproc_args
self.coredata.external_args[comp.get_language()] = compile_args
self.coredata.external_link_args[comp.get_language()] = link_args
self.build.add_compiler(comp)
if need_cross_compiler:
mlog.log('Cross %s compiler: ' % lang, mlog.bold(' '.join(cross_comp.get_exelist())), ' (%s %s)' % (cross_comp.id, cross_comp.version), sep='')

@ -947,6 +947,21 @@ class AllPlatformTests(BasePlatformTests):
m = re.search('build c-asm.*: c_LINKER', contents)
self.assertIsNotNone(m, msg=contents)
def test_preprocessor_checks_CPPFLAGS(self):
'''
Test that preprocessor compiler checks read CPPFLAGS but not CFLAGS
'''
testdir = os.path.join(self.common_test_dir, '140 get define')
define = 'MESON_TEST_DEFINE_VALUE'
# NOTE: this list can't have \n, ' or "
# \n is never substituted by the GNU pre-processor via a -D define
# ' and " confuse shlex.split() even when they are escaped
# % and # confuse the MSVC preprocessor
value = 'spaces and fun!@$^&*()-=_+{}[]:;<>?,./~`'
os.environ['CPPFLAGS'] = '-D{}="{}"'.format(define, value)
os.environ['CFLAGS'] = '-DMESON_FAIL_VALUE=cflags-read'.format(define)
self.init(testdir, ['-D{}={}'.format(define, value)])
class WindowsTests(BasePlatformTests):
'''

@ -16,4 +16,13 @@ foreach lang : ['c', 'cpp']
else
error('Please report a bug and help us improve support for this platform')
endif
# Check that an undefined value is empty.
have = cc.get_define('MESON_FAIL_VALUE')
assert(have == '', 'MESON_FAIL_VALUE value is "@0@" instead of ""'.format(have))
# This is used in the test_preprocessor_checks_CPPFLAGS() unit test.
have = cc.get_define('MESON_TEST_DEFINE_VALUE')
expect = get_option('MESON_TEST_DEFINE_VALUE')
assert(have == expect, 'MESON_TEST_DEFINE_VALUE value is "@0@" instead of "@1@"'.format(have, expect))
endforeach

@ -0,0 +1 @@
option('MESON_TEST_DEFINE_VALUE', type : 'string', default : '')
Loading…
Cancel
Save