From 66a6ea984bc43d9ac144e22cf411c16e9f911bb3 Mon Sep 17 00:00:00 2001 From: Jon Turney Date: Sun, 7 May 2017 23:20:50 +0100 Subject: [PATCH] Allow vs_module_defs to use a custom_target Allow vs_module_defs to use a custom_target Add a test and update documentation --- docs/markdown/Reference-manual.md | 2 +- mesonbuild/build.py | 9 ++++++++- .../meson.build | 10 ++++++++++ .../11 vs module defs generated custom target/prog.c | 5 +++++ .../subdir/make_def.py | 6 ++++++ .../subdir/meson.build | 7 +++++++ .../subdir/somedll.c | 3 +++ 7 files changed, 40 insertions(+), 2 deletions(-) create mode 100644 test cases/windows/11 vs module defs generated custom target/meson.build create mode 100644 test cases/windows/11 vs module defs generated custom target/prog.c create mode 100755 test cases/windows/11 vs module defs generated custom target/subdir/make_def.py create mode 100644 test cases/windows/11 vs module defs generated custom target/subdir/meson.build create mode 100644 test cases/windows/11 vs module defs generated custom target/subdir/somedll.c diff --git a/docs/markdown/Reference-manual.md b/docs/markdown/Reference-manual.md index 62c0fb3b2..a6dc96813 100644 --- a/docs/markdown/Reference-manual.md +++ b/docs/markdown/Reference-manual.md @@ -582,7 +582,7 @@ Builds a shared library with the given sources. Positional and keyword arguments - `version` a string specifying the version of this shared library, such as `1.1.0`. On Linux and OS X, this is used to set the shared library version in the filename, such as `libfoo.so.1.1.0` and `libfoo.1.1.0.dylib`. If this is not specified, `soversion` is used instead (see below). - `soversion` a string specifying the soversion of this shared library, such as `0`. On Linux and Windows this is used to set the soversion (or equivalent) in the filename. For example, if `soversion` is `4`, a Windows DLL will be called `foo-4.dll` and one of the aliases of the Linux shared library would be `libfoo.so.4`. If this is not specified, the first part of `version` is used instead. For example, if `version` is `3.6.0` and `soversion` is not defined, it is set to `3`. -- `vs_module_defs` a string pointing to a file or a File object that is a Microsoft module definition file for controlling symbol exports, etc., on platforms where that is possible (e.g. Windows). +- `vs_module_defs` a string, a File object, or Custom Target for a Microsoft module definition file for controlling symbol exports, etc., on platforms where that is possible (e.g. Windows). ### shared_module() diff --git a/mesonbuild/build.py b/mesonbuild/build.py index ce6405b2f..c1e192dd3 100644 --- a/mesonbuild/build.py +++ b/mesonbuild/build.py @@ -1281,6 +1281,8 @@ class SharedLibrary(BuildTarget): # Visual Studio module-definitions file if 'vs_module_defs' in kwargs: path = kwargs['vs_module_defs'] + if hasattr(path, 'held_object'): + path = path.held_object if isinstance(path, str): if os.path.isabs(path): self.vs_module_defs = File.from_absolute_file(path) @@ -1291,10 +1293,15 @@ class SharedLibrary(BuildTarget): # When passing a generated file. self.vs_module_defs = path self.link_depends.append(path) + elif hasattr(path, 'get_filename'): + # When passing output of a Custom Target + path = File.from_built_file(path.subdir, path.get_filename()) + self.vs_module_defs = path + self.link_depends.append(path) else: raise InvalidArguments( 'Shared library vs_module_defs must be either a string, ' - 'or a file object') + 'a file object or a Custom Target') def check_unknown_kwargs(self, kwargs): self.check_unknown_kwargs_int(kwargs, known_lib_kwargs) diff --git a/test cases/windows/11 vs module defs generated custom target/meson.build b/test cases/windows/11 vs module defs generated custom target/meson.build new file mode 100644 index 000000000..fe594c878 --- /dev/null +++ b/test cases/windows/11 vs module defs generated custom target/meson.build @@ -0,0 +1,10 @@ +project('generated_dll_module_defs', 'c') + +if meson.backend().startswith('vs') + # FIXME: Broken on the VS backends + error('MESON_SKIP_TEST see https://github.com/mesonbuild/meson/issues/1799') +endif + +subdir('subdir') +exe = executable('prog', 'prog.c', link_with : shlib) +test('runtest', exe) diff --git a/test cases/windows/11 vs module defs generated custom target/prog.c b/test cases/windows/11 vs module defs generated custom target/prog.c new file mode 100644 index 000000000..f35f4a02d --- /dev/null +++ b/test cases/windows/11 vs module defs generated custom target/prog.c @@ -0,0 +1,5 @@ +int somedllfunc(); + +int main(int argc, char **argv) { + return somedllfunc() == 42 ? 0 : 1; +} diff --git a/test cases/windows/11 vs module defs generated custom target/subdir/make_def.py b/test cases/windows/11 vs module defs generated custom target/subdir/make_def.py new file mode 100755 index 000000000..50acfb5ef --- /dev/null +++ b/test cases/windows/11 vs module defs generated custom target/subdir/make_def.py @@ -0,0 +1,6 @@ +#!/usr/bin/env python3 +import sys + +with open(sys.argv[1], 'w') as f: + print('EXPORTS', file=f) + print(' somedllfunc', file=f) diff --git a/test cases/windows/11 vs module defs generated custom target/subdir/meson.build b/test cases/windows/11 vs module defs generated custom target/subdir/meson.build new file mode 100644 index 000000000..c4ae33ae4 --- /dev/null +++ b/test cases/windows/11 vs module defs generated custom target/subdir/meson.build @@ -0,0 +1,7 @@ +make_def = find_program('make_def.py') + +def_file = custom_target('gen_def', + command: [make_def, '@OUTPUT@'], + output: 'somedll.def') + +shlib = shared_library('somedll', 'somedll.c', vs_module_defs: def_file) diff --git a/test cases/windows/11 vs module defs generated custom target/subdir/somedll.c b/test cases/windows/11 vs module defs generated custom target/subdir/somedll.c new file mode 100644 index 000000000..b23d8fed5 --- /dev/null +++ b/test cases/windows/11 vs module defs generated custom target/subdir/somedll.c @@ -0,0 +1,3 @@ +int somedllfunc() { + return 42; +}