Can use object files directly in targets.
This commit is contained in:
parent
34d673984d
commit
bcdb84fcbe
|
@ -171,6 +171,12 @@ class Backend():
|
||||||
for src in target.get_sources():
|
for src in target.get_sources():
|
||||||
if not self.environment.is_header(src):
|
if not self.environment.is_header(src):
|
||||||
obj_list.append(self.generate_single_compile(target, outfile, src, False, header_deps))
|
obj_list.append(self.generate_single_compile(target, outfile, src, False, header_deps))
|
||||||
|
for obj in target.get_objects():
|
||||||
|
if isinstance(obj, str):
|
||||||
|
o = os.path.join(self.build_to_src, target.get_subdir(), obj)
|
||||||
|
else:
|
||||||
|
raise MesonException('Unknown data type in object list.')
|
||||||
|
obj_list.append(o)
|
||||||
elem = self.generate_link(target, outfile, outname, obj_list)
|
elem = self.generate_link(target, outfile, outname, obj_list)
|
||||||
self.generate_shlib_aliases(target, self.get_target_dir(target), outfile, elem)
|
self.generate_shlib_aliases(target, self.get_target_dir(target), outfile, elem)
|
||||||
self.processed_targets[name] = True
|
self.processed_targets[name] = True
|
||||||
|
|
25
build.py
25
build.py
|
@ -91,11 +91,12 @@ class IncludeDirs():
|
||||||
return self.incdirs
|
return self.incdirs
|
||||||
|
|
||||||
class BuildTarget():
|
class BuildTarget():
|
||||||
def __init__(self, name, subdir, is_cross, sources, environment, kwargs):
|
def __init__(self, name, subdir, is_cross, sources, objects, environment, kwargs):
|
||||||
self.name = name
|
self.name = name
|
||||||
self.subdir = subdir
|
self.subdir = subdir
|
||||||
self.is_cross = is_cross
|
self.is_cross = is_cross
|
||||||
self.sources = []
|
self.sources = []
|
||||||
|
self.objects = []
|
||||||
self.external_deps = []
|
self.external_deps = []
|
||||||
self.include_dirs = []
|
self.include_dirs = []
|
||||||
self.link_targets = []
|
self.link_targets = []
|
||||||
|
@ -105,10 +106,19 @@ class BuildTarget():
|
||||||
self.extra_args = {}
|
self.extra_args = {}
|
||||||
self.generated = []
|
self.generated = []
|
||||||
self.process_sourcelist(sources)
|
self.process_sourcelist(sources)
|
||||||
|
self.process_objectlist(objects)
|
||||||
self.process_kwargs(kwargs)
|
self.process_kwargs(kwargs)
|
||||||
if len(self.sources) == 0 and len(self.generated) == 0:
|
if len(self.sources) == 0 and len(self.generated) == 0:
|
||||||
raise InvalidArguments('Build target %s has no sources.' % name)
|
raise InvalidArguments('Build target %s has no sources.' % name)
|
||||||
|
|
||||||
|
def process_objectlist(self, objects):
|
||||||
|
assert(isinstance(objects, list))
|
||||||
|
for s in objects:
|
||||||
|
if isinstance(s, str):
|
||||||
|
self.objects.append(s)
|
||||||
|
else:
|
||||||
|
raise InvalidArguments('Bad object in target %s.' % self.name)
|
||||||
|
|
||||||
def process_sourcelist(self, sources):
|
def process_sourcelist(self, sources):
|
||||||
if not isinstance(sources, list):
|
if not isinstance(sources, list):
|
||||||
sources = [sources]
|
sources = [sources]
|
||||||
|
@ -215,6 +225,9 @@ class BuildTarget():
|
||||||
def get_sources(self):
|
def get_sources(self):
|
||||||
return self.sources
|
return self.sources
|
||||||
|
|
||||||
|
def get_objects(self):
|
||||||
|
return self.objects
|
||||||
|
|
||||||
def get_generated_sources(self):
|
def get_generated_sources(self):
|
||||||
return self.generated
|
return self.generated
|
||||||
|
|
||||||
|
@ -386,8 +399,8 @@ class GeneratedList():
|
||||||
return self.generator
|
return self.generator
|
||||||
|
|
||||||
class Executable(BuildTarget):
|
class Executable(BuildTarget):
|
||||||
def __init__(self, name, subdir, is_cross, sources, environment, kwargs):
|
def __init__(self, name, subdir, is_cross, sources, objects, environment, kwargs):
|
||||||
super().__init__(name, subdir, is_cross, sources, environment, kwargs)
|
super().__init__(name, subdir, is_cross, sources, objects, environment, kwargs)
|
||||||
suffix = environment.get_exe_suffix()
|
suffix = environment.get_exe_suffix()
|
||||||
if suffix != '':
|
if suffix != '':
|
||||||
self.filename = self.name + '.' + suffix
|
self.filename = self.name + '.' + suffix
|
||||||
|
@ -396,14 +409,14 @@ class Executable(BuildTarget):
|
||||||
|
|
||||||
|
|
||||||
class StaticLibrary(BuildTarget):
|
class StaticLibrary(BuildTarget):
|
||||||
def __init__(self, name, subdir, is_cross, sources, environment, kwargs):
|
def __init__(self, name, subdir, is_cross, sources, objects, environment, kwargs):
|
||||||
super().__init__(name, subdir, is_cross, sources, environment, kwargs)
|
super().__init__(name, subdir, is_cross, sources, objects, environment, kwargs)
|
||||||
prefix = environment.get_static_lib_prefix()
|
prefix = environment.get_static_lib_prefix()
|
||||||
suffix = environment.get_static_lib_suffix()
|
suffix = environment.get_static_lib_suffix()
|
||||||
self.filename = prefix + self.name + '.' + suffix
|
self.filename = prefix + self.name + '.' + suffix
|
||||||
|
|
||||||
class SharedLibrary(BuildTarget):
|
class SharedLibrary(BuildTarget):
|
||||||
def __init__(self, name, subdir, is_cross, sources, environment, kwargs):
|
def __init__(self, name, subdir, is_cross, sources, objects, environment, kwargs):
|
||||||
self.version = None
|
self.version = None
|
||||||
self.soversion = None
|
self.soversion = None
|
||||||
super().__init__(name, subdir, is_cross, sources, environment, kwargs);
|
super().__init__(name, subdir, is_cross, sources, environment, kwargs);
|
||||||
|
|
|
@ -312,23 +312,23 @@ class Man(InterpreterObject):
|
||||||
return self.sources
|
return self.sources
|
||||||
|
|
||||||
class BuildTargetHolder(InterpreterObject):
|
class BuildTargetHolder(InterpreterObject):
|
||||||
def __init__(self, targetttype, name, subdir, is_cross, sources, environment, kwargs):
|
def __init__(self, targetttype, name, subdir, is_cross, sources, objects, environment, kwargs):
|
||||||
self.target = targetttype(name, subdir, is_cross, sources, environment, kwargs)
|
self.target = targetttype(name, subdir, is_cross, sources, objects, environment, kwargs)
|
||||||
|
|
||||||
def is_cross(self):
|
def is_cross(self):
|
||||||
return self.target.is_cross()
|
return self.target.is_cross()
|
||||||
|
|
||||||
class ExecutableHolder(BuildTargetHolder):
|
class ExecutableHolder(BuildTargetHolder):
|
||||||
def __init__(self, name, subdir, is_cross, sources, environment, kwargs):
|
def __init__(self, name, subdir, is_cross, sources, objects, environment, kwargs):
|
||||||
super().__init__(build.Executable, name, subdir, is_cross, sources, environment, kwargs)
|
super().__init__(build.Executable, name, subdir, is_cross, sources, objects, environment, kwargs)
|
||||||
|
|
||||||
class StaticLibraryHolder(BuildTargetHolder):
|
class StaticLibraryHolder(BuildTargetHolder):
|
||||||
def __init__(self, name, subdir, is_cross, sources, environment, kwargs):
|
def __init__(self, name, subdir, is_cross, sources, objects, environment, kwargs):
|
||||||
super().__init__(build.StaticLibrary, name, subdir, is_cross, sources, environment, kwargs)
|
super().__init__(build.StaticLibrary, name, subdir, is_cross, sources, objects, environment, kwargs)
|
||||||
|
|
||||||
class SharedLibraryHolder(BuildTargetHolder):
|
class SharedLibraryHolder(BuildTargetHolder):
|
||||||
def __init__(self, name, subdir, is_cross, sources, environment, kwargs):
|
def __init__(self, name, subdir, is_cross, sources, objects, environment, kwargs):
|
||||||
super().__init__(build.SharedLibrary, name, subdir, is_cross, sources, environment, kwargs)
|
super().__init__(build.SharedLibrary, name, subdir, is_cross, sources, objects, environment, kwargs)
|
||||||
|
|
||||||
class Test(InterpreterObject):
|
class Test(InterpreterObject):
|
||||||
def __init__(self, name, exe, is_parallel, cmd_args, env):
|
def __init__(self, name, exe, is_parallel, cmd_args, env):
|
||||||
|
@ -985,10 +985,13 @@ class Interpreter():
|
||||||
except KeyError:
|
except KeyError:
|
||||||
kw_src = []
|
kw_src = []
|
||||||
sources += kw_src
|
sources += kw_src
|
||||||
|
objs = self.flatten(kwargs.get('objects', []))
|
||||||
|
if not isinstance(objs, list):
|
||||||
|
objs = [objs]
|
||||||
if name in self.build.targets:
|
if name in self.build.targets:
|
||||||
raise InvalidCode('Tried to create target "%s", but a target of that name already exists.' % name)
|
raise InvalidCode('Tried to create target "%s", but a target of that name already exists.' % name)
|
||||||
self.check_sources_exist(os.path.join(self.environment.source_dir, self.subdir), sources)
|
self.check_sources_exist(os.path.join(self.environment.source_dir, self.subdir), sources)
|
||||||
l = targetclass(name, self.subdir, is_cross, sources, self.environment, kwargs)
|
l = targetclass(name, self.subdir, is_cross, sources, objs, self.environment, kwargs)
|
||||||
self.build.targets[name] = l.target
|
self.build.targets[name] = l.target
|
||||||
if self.environment.is_cross_build() and l.is_cross:
|
if self.environment.is_cross_build() and l.is_cross:
|
||||||
txt = ' cross build '
|
txt = ' cross build '
|
||||||
|
|
Binary file not shown.
|
@ -0,0 +1,5 @@
|
||||||
|
int func();
|
||||||
|
|
||||||
|
int main(int argc, char **argv) {
|
||||||
|
return func() == 42 ? 0 : 99;
|
||||||
|
}
|
|
@ -0,0 +1,19 @@
|
||||||
|
# This test is on its own because it is special.
|
||||||
|
# To run the test you need the prebuilt object
|
||||||
|
# file for the given platform.
|
||||||
|
#
|
||||||
|
# Combined with cross compilation this would make
|
||||||
|
# the state space explode so let's just keep this
|
||||||
|
# in its own subdir so it's not run during cross
|
||||||
|
# compilation tests.
|
||||||
|
|
||||||
|
project('prebuilt object', 'c')
|
||||||
|
|
||||||
|
object = 'linux-amd64.o'
|
||||||
|
|
||||||
|
# Remember: do not put source.c in this
|
||||||
|
# declaration. Only the prebuilt object.
|
||||||
|
e = executable('prog', 'main.c',
|
||||||
|
objects : object)
|
||||||
|
|
||||||
|
test('objtest', e)
|
|
@ -0,0 +1,8 @@
|
||||||
|
/*
|
||||||
|
* Compile this manually on new platforms and add the
|
||||||
|
* object file to revision control and Meson configuration.
|
||||||
|
*/
|
||||||
|
|
||||||
|
int func() {
|
||||||
|
return 42;
|
||||||
|
}
|
Loading…
Reference in New Issue