Can set compiler options, added language versions for Gnu and Clang.

pull/275/head
Jussi Pakkanen 9 years ago
parent d76e89f780
commit 50663144c3
  1. 1
      backends.py
  2. 74
      compilers.py
  3. 1
      coredata.py
  4. 7
      interpreter.py
  5. 1
      ninjabackend.py
  6. 4
      test cases/frameworks/1 boost/meson.build
  7. 4
      test cases/frameworks/4 qt5/meson.build
  8. 2
      test cases/frameworks/9 wxwidgets/meson.build

@ -210,6 +210,7 @@ class Backend():
commands += compiler.get_always_args()
if self.environment.coredata.buildtype != 'plain':
commands += compiler.get_warn_args(self.environment.coredata.warning_level)
commands += compiler.get_option_compile_args(self.environment.coredata.compiler_options)
commands += self.build.get_global_args(compiler)
commands += self.environment.coredata.external_args[compiler.get_language()]
commands += target.get_extra_args(compiler.get_language())

@ -134,6 +134,15 @@ class Compiler():
def get_linker_always_args(self):
return []
def get_options(self):
return {} # build afresh every time
def get_option_compile_args(self, options):
return []
def get_option_link_args(self, options):
return []
class CCompiler(Compiler):
def __init__(self, exelist, version, is_cross, exe_wrapper=None):
super().__init__(exelist, version)
@ -1066,6 +1075,21 @@ class GnuCCompiler(CCompiler):
def can_compile(self, filename):
return super().can_compile(filename) or filename.split('.')[-1].lower() == 's' # Gcc can do asm, too.
def get_options(self):
return {'c_std' : mesonlib.UserComboOption('c_std', 'C language standard to use',
['none', 'c89', 'c99', 'c11', 'gnu89', 'gnu99', 'gnu11'],
'c11')}
def get_option_compile_args(self, options):
args = []
std = options['c_std']
if std.value != 'none':
args.append('-std=' + std.value)
return args
def get_option_link_args(self, options):
return []
class GnuObjCCompiler(ObjCCompiler):
std_opt_args = ['-O2']
@ -1154,6 +1178,20 @@ class ClangCCompiler(CCompiler):
# so it might change semantics at any time.
return ['-include-pch', os.path.join (pch_dir, self.get_pch_name (header))]
def get_options(self):
return {'c_std' : mesonlib.UserComboOption('c_std', 'C language standard to use',
['none', 'c89', 'c99', 'c11'],
'c11')}
def get_option_compile_args(self, options):
args = []
std = options['c_std']
if std.value != 'none':
args.append('-std=' + std.value)
return args
def get_option_link_args(self, options):
return []
class GnuCPPCompiler(CPPCompiler):
# may need to separate the latter to extra_debug_args or something
@ -1182,6 +1220,21 @@ class GnuCPPCompiler(CPPCompiler):
def get_soname_args(self, shlib_name, path, soversion):
return get_gcc_soname_args(self.gcc_type, shlib_name, path, soversion)
def get_options(self):
return {'cpp_std' : mesonlib.UserComboOption('cpp_std', 'C language standard to use',
['none', 'c++03', 'c++11', 'c++1y'],
'c++11')}
def get_option_compile_args(self, options):
args = []
std = options['cpp_std']
if std.value != 'none':
args.append('-std=' + std.value)
return args
def get_option_link_args(self, options):
return []
class ClangCPPCompiler(CPPCompiler):
def __init__(self, exelist, version, is_cross, exe_wrapper=None):
CPPCompiler.__init__(self, exelist, version, is_cross, exe_wrapper)
@ -1205,6 +1258,21 @@ class ClangCPPCompiler(CPPCompiler):
# so it might change semantics at any time.
return ['-include-pch', os.path.join (pch_dir, self.get_pch_name (header))]
def get_options(self):
return {'c_std' : mesonlib.UserComboOption('cpp_std', 'C++ language standard to use',
['none', 'c++03', 'c++11', 'c++1y'],
'c++11')}
def get_option_compile_args(self, options):
args = []
std = options['cpp_std']
if std.value != 'none':
args.append('-std=' + std.value)
return args
def get_option_link_args(self, options):
return []
class FortranCompiler(Compiler):
def __init__(self, exelist, version, is_cross, exe_wrapper=None):
super().__init__(exelist, version)
@ -1495,6 +1563,9 @@ class VisualStudioLinker():
def thread_link_flags(self):
return []
def get_option_link_args(self, options):
return []
class ArLinker():
std_args = ['csr']
@ -1528,3 +1599,6 @@ class ArLinker():
def thread_link_flags(self):
return []
def get_option_link_args(self, options):
return []

@ -61,6 +61,7 @@ class CoreData():
self.werror = options.werror
self.layout = options.layout
self.user_options = {}
self.compiler_options = {}
self.external_args = {} # These are set from "the outside" with e.g. mesonconf
self.external_link_args = {}
if options.cross_file is not None:

@ -1330,6 +1330,13 @@ class Interpreter():
if cross_comp is not None:
cross_comp.sanity_check(self.environment.get_scratch_dir())
self.coredata.cross_compilers[lang] = cross_comp
new_options = comp.get_options()
optprefix = lang + '_'
for i in new_options:
if not i.startswith(optprefix):
raise InterpreterException('Internal error, %s has incorrect prefix.' % i)
new_options.update(self.coredata.compiler_options)
self.coredata.compiler_options = new_options
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.get_language())

@ -1452,6 +1452,7 @@ rule FORTRAN_DEP_HACK
commands = []
commands += linker.get_linker_always_args()
commands += linker.get_buildtype_linker_args(self.environment.coredata.buildtype)
commands += linker.get_option_link_args(self.environment.coredata.compiler_options)
if not(isinstance(target, build.StaticLibrary)):
commands += self.environment.coredata.external_link_args[linker.get_language()]
if isinstance(target, build.Executable):

@ -1,8 +1,6 @@
project('boosttest', 'cpp')
if meson.get_compiler('cpp').get_id() != 'msvc'
add_global_arguments('-std=c++11', language : 'cpp')
else
if meson.get_compiler('cpp').get_id() == 'msvc'
add_global_arguments('/EHsc', language : 'cpp')
endif

@ -3,10 +3,6 @@ project('qt5 build test', 'cpp')
qt5 = import('qt5')
qt5dep = dependency('qt5', modules : ['Core', 'Gui', 'Widgets'])
if meson.get_compiler('cpp').get_id() != 'msvc'
add_global_arguments('-std=c++11', language : 'cpp')
endif
prep = qt5.preprocess(
moc_headers : ['mainWindow.h'], # These need to be fed through the moc tool before use.
ui_files : 'mainWindow.ui', # XML files that need to be compiled with the uic tol.

@ -1,7 +1,5 @@
project('wxwidgets test', 'cpp')
add_global_arguments('-std=c++11', language : 'cpp')
wxd = dependency('wxwidgets', version : '>=3.0.0')
wp = executable('wxprog', 'wxprog.cpp',

Loading…
Cancel
Save