Skip to content

Commit

Permalink
Can set compiler options, added language versions for Gnu and Clang.
Browse files Browse the repository at this point in the history
  • Loading branch information
jpakkane committed Oct 4, 2015
1 parent d76e89f commit 5066314
Show file tree
Hide file tree
Showing 8 changed files with 85 additions and 9 deletions.
1 change: 1 addition & 0 deletions backends.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ def generate_basic_compiler_args(self, target, compiler):
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())
Expand Down
74 changes: 74 additions & 0 deletions compilers.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,15 @@ def get_always_args(self):
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)
Expand Down Expand Up @@ -1066,6 +1075,21 @@ def get_soname_args(self, shlib_name, path, soversion):
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']

Expand Down Expand Up @@ -1154,6 +1178,20 @@ def get_pch_use_args(self, pch_dir, header):
# 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
Expand Down Expand Up @@ -1182,6 +1220,21 @@ def get_pch_suffix(self):
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)
Expand All @@ -1205,6 +1258,21 @@ def get_pch_use_args(self, pch_dir, header):
# 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)
Expand Down Expand Up @@ -1495,6 +1563,9 @@ def build_rpath_args(self, build_dir, rpath_paths, install_rpath):
def thread_link_flags(self):
return []

def get_option_link_args(self, options):
return []

class ArLinker():
std_args = ['csr']

Expand Down Expand Up @@ -1528,3 +1599,6 @@ def get_always_args(self):

def thread_link_flags(self):
return []

def get_option_link_args(self, options):
return []
1 change: 1 addition & 0 deletions coredata.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ def __init__(self, options):
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:
Expand Down
7 changes: 7 additions & 0 deletions interpreter.py
Original file line number Diff line number Diff line change
Expand Up @@ -1330,6 +1330,13 @@ def add_languages(self, node, args):
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())
Expand Down
1 change: 1 addition & 0 deletions ninjabackend.py
Original file line number Diff line number Diff line change
Expand Up @@ -1452,6 +1452,7 @@ def generate_link(self, target, outfile, outname, obj_list, linker, extra_args=[
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):
Expand Down
4 changes: 1 addition & 3 deletions test cases/frameworks/1 boost/meson.build
Original file line number Diff line number Diff line change
@@ -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

Expand Down
4 changes: 0 additions & 4 deletions test cases/frameworks/4 qt5/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 0 additions & 2 deletions test cases/frameworks/9 wxwidgets/meson.build
Original file line number Diff line number Diff line change
@@ -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',
Expand Down

0 comments on commit 5066314

Please sign in to comment.