diff options
author | Jakub Adam <jakub.adam@ktknet.cz> | 2019-07-26 18:49:49 +0200 |
---|---|---|
committer | Michael Tüxen <tuexen@fh-muenster.de> | 2019-07-26 12:49:49 -0400 |
commit | 47d338c6d3ee61f95307eb1771aa041e0a04ef1a (patch) | |
tree | d5d49952a593f271d0e0681f08d887f2c8ea8235 | |
parent | 2a5aff3baab0711ef8930adfee3d1aeb1a16f79a (diff) | |
download | usrsctp-47d338c6d3ee61f95307eb1771aa041e0a04ef1a.tar.gz |
Fix shared library build for Windows with MSVC and Meson (#328)
usrsctp-1.dll built with Meson didn't export any symbols. Meson needs
a .def file listing the names of functions to export when creating a
shared library on Windows.
This patch generates usrsctp.def automatically at build time from the
output of "dumpbin /linkermember" run on the static version
of usrsctp lib.
Kudos to Lennart Grahl for help with fixing broken static build.
-rw-r--r-- | gen-def.py | 26 | ||||
-rw-r--r-- | meson.build | 31 |
2 files changed, 52 insertions, 5 deletions
diff --git a/gen-def.py b/gen-def.py new file mode 100644 index 00000000..55c02854 --- /dev/null +++ b/gen-def.py @@ -0,0 +1,26 @@ +#!/usr/bin/env python3 +# +# gen-def.py usrsctp.lib +import re +import sys +import subprocess +from shutil import which + +try: + lib_file = sys.argv[1] +except: + print('Usage: gen-def.py LIB-FILE') + exit(-1) + +print('EXPORTS') + +if which('dumpbin'): + dumpbin_cmd = subprocess.run(['dumpbin', '/linkermember:1', lib_file], + stdout=subprocess.PIPE) + + pattern = re.compile('\s*[0-9a-fA-F]+ _?(?P<functionname>usrsctp_[^\s]*)') + + for line in dumpbin_cmd.stdout.decode('utf-8').splitlines(): + match = pattern.match(line) + if match: + print(match.group('functionname')) diff --git a/meson.build b/meson.build index 942bbed8..763edf93 100644 --- a/meson.build +++ b/meson.build @@ -183,11 +183,32 @@ endif subdir('usrsctplib') # Build library -usrsctp = library('usrsctp', sources, - dependencies: dependencies, - include_directories: include_dirs, - install: true, - version: meson.project_version()) +if compiler.get_id() == 'msvc' and get_option('default_library') == 'shared' + # Needed by usrsctp_def + find_program('dumpbin') + + usrsctp_static = static_library('usrsctp-static', sources, + dependencies: dependencies, + include_directories: include_dirs) + + usrsctp_def = custom_target('usrsctp.def', + command: [find_program('gen-def.py'), '@INPUT@'], + input: usrsctp_static, + output: 'usrsctp.def', + capture: true) + + usrsctp = shared_library('usrsctp', + link_whole: usrsctp_static, + vs_module_defs: usrsctp_def, + install: true, + version: meson.project_version()) +else + usrsctp = library('usrsctp', sources, + dependencies: dependencies, + include_directories: include_dirs, + install: true, + version: meson.project_version()) +endif # Declare dependency usrsctp_dep = declare_dependency( |