Can set global linker arguments. Closes #536.

This commit is contained in:
Jussi Pakkanen 2016-05-28 21:31:59 +03:00
parent 1b78e354a6
commit 4377f773e0
3 changed files with 21 additions and 0 deletions

View File

@ -1626,6 +1626,8 @@ rule FORTRAN_DEP_HACK
linker_rule = linker_base + crstr + '_LINKER'
abspath = os.path.join(self.environment.get_build_dir(), target.subdir)
commands = []
if not isinstance(target, build.StaticLibrary):
commands += self.build.get_global_link_args(linker)
commands += self.get_cross_stdlib_link_args(target, linker)
commands += linker.get_linker_always_args()
if not isinstance(target, build.StaticLibrary):

View File

@ -88,6 +88,7 @@ class Build:
self.compilers = []
self.cross_compilers = []
self.global_args = {}
self.global_link_args = {}
self.tests = []
self.benchmarks = []
self.headers = []
@ -151,6 +152,9 @@ class Build:
def get_global_args(self, compiler):
return self.global_args.get(compiler.get_language(), [])
def get_global_link_args(self, compiler):
return self.global_link_args.get(compiler.get_language(), [])
class IncludeDirs():
def __init__(self, curdir, dirs, is_system, extra_build_dirs=None):
self.curdir = curdir

View File

@ -1003,6 +1003,7 @@ class Interpreter():
'configure_file' : self.func_configure_file,
'include_directories' : self.func_include_directories,
'add_global_arguments' : self.func_add_global_arguments,
'add_global_link_arguments' : self.func_add_global_link_arguments,
'add_languages' : self.func_add_languages,
'find_program' : self.func_find_program,
'find_library' : self.func_find_library,
@ -1919,6 +1920,20 @@ class Interpreter():
else:
self.build.global_args[lang] = args
@stringArgs
def func_add_global_link_arguments(self, node, args, kwargs):
if self.subproject != '':
raise InvalidCode('Global arguments can not be set in subprojects because there is no way to make that reliable.')
if self.global_args_frozen:
raise InvalidCode('Tried to set global arguments after a build target has been declared.\nThis is not permitted. Please declare all global arguments before your targets.')
if not 'language' in kwargs:
raise InvalidCode('Missing language definition in add_global_arguments')
lang = kwargs['language'].lower()
if lang in self.build.global_link_args:
self.build.global_link_args[lang] += args
else:
self.build.global_link_args[lang] = args
def flatten(self, args):
if isinstance(args, mparser.StringNode):
return args.value