aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJussi Pakkanen <jpakkane@gmail.com>2019-03-17 22:34:19 +0200
committerJussi Pakkanen <jpakkane@gmail.com>2019-03-18 22:01:07 +0200
commite81f48db1600056942e30e2567af73d6d7678188 (patch)
tree1a724fd7876a2cad22e016e71d34e176e3ab42c2
parent93df9530c820402d553d3db2b1b3a93ba13161fb (diff)
downloadmeson-e81f48db1600056942e30e2567af73d6d7678188.zip
meson-e81f48db1600056942e30e2567af73d6d7678188.tar.gz
meson-e81f48db1600056942e30e2567af73d6d7678188.tar.bz2
Can link against custom targets. Closes #4908.
-rw-r--r--mesonbuild/backend/backends.py4
-rw-r--r--mesonbuild/build.py19
-rw-r--r--test cases/common/216 link custom/meson.build9
-rw-r--r--test cases/common/216 link custom/prog.c6
4 files changed, 35 insertions, 3 deletions
diff --git a/mesonbuild/backend/backends.py b/mesonbuild/backend/backends.py
index be181a8..b62438e 100644
--- a/mesonbuild/backend/backends.py
+++ b/mesonbuild/backend/backends.py
@@ -211,6 +211,10 @@ class Backend:
return os.path.join(self.get_target_dir(target), link_lib)
elif isinstance(target, build.StaticLibrary):
return os.path.join(self.get_target_dir(target), target.get_filename())
+ elif isinstance(target, build.CustomTarget):
+ if not target.is_linkable_target():
+ raise MesonException('Tried to link against custom target "%s", which is not linkable.' % target.name)
+ return os.path.join(self.get_target_dir(target), target.get_filename())
elif isinstance(target, build.Executable):
if target.import_filename:
return os.path.join(self.get_target_dir(target), target.get_import_filename())
diff --git a/mesonbuild/build.py b/mesonbuild/build.py
index 20f0cdb..eb8e60c 100644
--- a/mesonbuild/build.py
+++ b/mesonbuild/build.py
@@ -567,6 +567,8 @@ class BuildTarget(Target):
if self.link_targets or self.link_whole_targets:
extra = set()
for t in itertools.chain(self.link_targets, self.link_whole_targets):
+ if isinstance(t, CustomTarget):
+ continue # We can't know anything about these.
for name, compiler in t.compilers.items():
if name in clink_langs:
extra.add((name, compiler))
@@ -1062,7 +1064,7 @@ You probably should put it in link_with instead.''')
msg = "Can't link non-PIC static library {!r} into shared library {!r}. ".format(t.name, self.name)
msg += "Use the 'pic' option to static_library to build with PIC."
raise InvalidArguments(msg)
- if self.is_cross != t.is_cross:
+ if not isinstance(t, CustomTarget) and self.is_cross != t.is_cross:
raise InvalidArguments('Tried to mix cross built and native libraries in target {!r}'.format(self.name))
self.link_targets.append(t)
@@ -1149,6 +1151,8 @@ You probably should put it in link_with instead.''')
# Check if any of the internal libraries this target links to were
# written in this language
for link_target in itertools.chain(self.link_targets, self.link_whole_targets):
+ if isinstance(link_target, CustomTarget):
+ continue
for language in link_target.compilers:
if language not in langs:
langs.append(language)
@@ -2090,6 +2094,19 @@ class CustomTarget(Target):
raise InvalidArguments('Substitution in depfile for custom_target that does not have an input file.')
return self.depfile
+ def is_linkable_target(self):
+ if len(self.outputs) != 1:
+ return False
+ suf = os.path.splitext(self.outputs[0])[-1]
+ if suf == '.a' or suf == '.dll' or suf == '.lib' or suf == '.so':
+ return True
+
+ def get_link_dep_subdirs(self):
+ return OrderedSet()
+
+ def get_all_link_deps(self):
+ return []
+
def type_suffix(self):
return "@cus"
diff --git a/test cases/common/216 link custom/meson.build b/test cases/common/216 link custom/meson.build
index dc01354..a1923b9 100644
--- a/test cases/common/216 link custom/meson.build
+++ b/test cases/common/216 link custom/meson.build
@@ -16,5 +16,10 @@ clib = custom_target('linkcustom',
'-o', '@OUTPUT@',
'--private-dir', '@PRIVATE_DIR@'] + cc.cmd_array())
-#exe = executable('prog', 'prog.c', link_with: clib)
-#test('linkcustom', exe)
+exe = executable('prog', 'prog.c', link_with: clib)
+test('linkcustom', exe)
+
+d = declare_dependency(link_with: clib)
+
+exe2 = executable('prog2', 'prog.c', dependencies: d)
+test('linkcustom2', exe2)
diff --git a/test cases/common/216 link custom/prog.c b/test cases/common/216 link custom/prog.c
new file mode 100644
index 0000000..eaede6d
--- /dev/null
+++ b/test cases/common/216 link custom/prog.c
@@ -0,0 +1,6 @@
+void flob();
+
+int main(int argc, char **argv) {
+ flob();
+ return 0;
+}