Allow vs_module_defs to use a custom_target

Allow vs_module_defs to use a custom_target
Add a test and update documentation
pull/1792/head
Jon Turney 8 years ago
parent abd12b69ea
commit 66a6ea984b
  1. 2
      docs/markdown/Reference-manual.md
  2. 9
      mesonbuild/build.py
  3. 10
      test cases/windows/11 vs module defs generated custom target/meson.build
  4. 5
      test cases/windows/11 vs module defs generated custom target/prog.c
  5. 6
      test cases/windows/11 vs module defs generated custom target/subdir/make_def.py
  6. 7
      test cases/windows/11 vs module defs generated custom target/subdir/meson.build
  7. 3
      test cases/windows/11 vs module defs generated custom target/subdir/somedll.c

@ -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()

@ -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)

@ -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)

@ -0,0 +1,5 @@
int somedllfunc();
int main(int argc, char **argv) {
return somedllfunc() == 42 ? 0 : 1;
}

@ -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)

@ -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)
Loading…
Cancel
Save