Skip to content

Commit

Permalink
MSVC: support -LIBPATH
Browse files Browse the repository at this point in the history
Fixes mesonbuild#6101 (with a test), following up mesonbuild#5881
  • Loading branch information
agurtovoy authored and jpakkane committed Oct 29, 2019
1 parent 6e18e5b commit 6eee9e4
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
6 changes: 4 additions & 2 deletions mesonbuild/compilers/mixins/visualstudio.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,9 @@ def unix_args_to_native(cls, args: typing.List[str]) -> typing.List[str]:
# -pthread is only valid for GCC
if i in ('-mms-bitfields', '-pthread'):
continue
if i.startswith('-L'):
if i.startswith('-LIBPATH:'):
i = '/LIBPATH:' + i[9:]
elif i.startswith('-L'):
i = '/LIBPATH:' + i[2:]
# Translate GNU-style -lfoo library name to the import library
elif i.startswith('-l'):
Expand Down Expand Up @@ -250,7 +252,7 @@ def unix_args_to_native(cls, args: typing.List[str]) -> typing.List[str]:
def native_args_to_unix(cls, args: typing.List[str]) -> typing.List[str]:
result = []
for arg in args:
if arg.startswith('/LIBPATH:'):
if arg.startswith(('/LIBPATH:', '-LIBPATH:')):
result.append('-L' + arg[9:])
elif arg.endswith(('.a', '.lib')) and not os.path.isabs(arg):
result.append('-l' + arg)
Expand Down
3 changes: 2 additions & 1 deletion run_unittests.py
Original file line number Diff line number Diff line change
Expand Up @@ -3162,7 +3162,7 @@ def test_guessed_linker_dependencies(self):
env = get_fake_env(testdirlib, self.builddir, self.prefix)
if env.detect_c_compiler(MachineChoice.HOST).get_id() in {'msvc', 'clang-cl', 'intel-cl'}:
# msvc-like compiler, also test it with msvc-specific flags
libdir_flags += ['/LIBPATH:']
libdir_flags += ['/LIBPATH:', '-LIBPATH:']
else:
# static libraries are not linkable with -l with msvc because meson installs them
# as .a files which unix_args_to_native will not know as it expects libraries to use
Expand All @@ -3176,6 +3176,7 @@ def test_guessed_linker_dependencies(self):

for libdir_flag in libdir_flags:
# build library
self.new_builddir()
self.init(testdirlib, extra_args=extra_args)
self.build()
self.install()
Expand Down

0 comments on commit 6eee9e4

Please sign in to comment.