diff options
author | Jussi Pakkanen <jpakkane@gmail.com> | 2017-05-21 21:31:14 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-05-21 21:31:14 +0300 |
commit | 189784b47404a7ab8b9443e4604721df2941a042 (patch) | |
tree | a144d266f0bb1829f92fc7371780a4d54f480e82 | |
parent | c352c34ff19a75882dce89d71a2643f1913bebc6 (diff) | |
parent | 197594146cd588b4c6027a3bcc218e8c00b70a4d (diff) | |
download | meson-189784b47404a7ab8b9443e4604721df2941a042.zip meson-189784b47404a7ab8b9443e4604721df2941a042.tar.gz meson-189784b47404a7ab8b9443e4604721df2941a042.tar.bz2 |
Merge pull request #1792 from jon-turney/custom_target_vs_module_defs
Allow vs_module_defs to use a custom_target
10 files changed, 79 insertions, 2 deletions
diff --git a/docs/markdown/Reference-manual.md b/docs/markdown/Reference-manual.md index 366ece7..c835f6f 100644 --- a/docs/markdown/Reference-manual.md +++ b/docs/markdown/Reference-manual.md @@ -584,7 +584,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 242ce6f..855c0bd 100644 --- a/mesonbuild/build.py +++ b/mesonbuild/build.py @@ -1279,6 +1279,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) @@ -1289,10 +1291,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/common/152 link depends custom target/foo.c b/test cases/common/152 link depends custom target/foo.c new file mode 100644 index 0000000..8700a9e --- /dev/null +++ b/test cases/common/152 link depends custom target/foo.c @@ -0,0 +1,15 @@ +#include <stdio.h> + +int main() { + const char *fn = DEPFILE; + FILE *f = fopen(fn, "r"); + if (!f) { + printf("could not open %s", fn); + return 1; + } + else { + printf("successfully opened %s", fn); + } + + return 0; +} diff --git a/test cases/common/152 link depends custom target/make_file.py b/test cases/common/152 link depends custom target/make_file.py new file mode 100755 index 0000000..ceb6e19 --- /dev/null +++ b/test cases/common/152 link depends custom target/make_file.py @@ -0,0 +1,5 @@ +#!/usr/bin/env python3 +import sys + +with open(sys.argv[1], 'w') as f: + print('# this file does nothing', file=f) diff --git a/test cases/common/152 link depends custom target/meson.build b/test cases/common/152 link depends custom target/meson.build new file mode 100644 index 0000000..ee7a865 --- /dev/null +++ b/test cases/common/152 link depends custom target/meson.build @@ -0,0 +1,19 @@ +project('link_depends_custom_target', '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 + +cmd = find_program('make_file.py') + +dep_file = custom_target('gen_dep', + command: [cmd, '@OUTPUT@'], + output: 'dep_file') + +exe = executable('foo', 'foo.c', + link_depends: dep_file, + c_args: ['-DDEPFILE="' + dep_file.full_path()+ '"']) + +# check that dep_file exists, which means that link_depends target ran +test('runtest', exe) 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 0000000..fe594c8 --- /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 0000000..f35f4a0 --- /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 0000000..50acfb5 --- /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 0000000..c4ae33a --- /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 0000000..b23d8fe --- /dev/null +++ b/test cases/windows/11 vs module defs generated custom target/subdir/somedll.c @@ -0,0 +1,3 @@ +int somedllfunc() { + return 42; +} |