mesonbuild / meson

The Meson Build System
http://mesonbuild.com
Apache License 2.0
5.56k stars 1.61k forks source link

meson does not support alternate spelling -libpath: in .pc files #5811

Open dankegel opened 5 years ago

dankegel commented 5 years ago

This is similar to #5727

I just ran into this with meson 0.51.1.

I have a .pc file that contains -libpath. Standalone pkgconfig outputs:

$ PKG_CONFIG_PATH=c:/opt/oblong/g-speak5.1/lib/pkgconfig /cygdrive/c/pkg-config-lite/bin/pkg-config.exe --libs libBasement
Basement.lib Plasma++.lib Loam++.lib C:/opt/oblong/deps-64-13/lib/boost_filesystem-vc141-mt-x64-1_67.lib C:/opt/oblong/deps-64-13/lib/boost_regex-vc141-mt-x64-1_67.lib C:/opt/oblong/deps-64-13/lib/boost_system-vc141-mt-x64-1_67.lib -libpath:C://opt/oblong/deps-64-13/lib icuin.lib icuuc.lib Plasma.lib -libpath:C://opt/oblong/deps-64-13/lib yaml.lib ssleay32.lib libeay32.lib -libpath:C:/opt/oblong/g-speak5.1/lib Loam.lib

but ninja mangles this to "ibpath:C://opt/oblong/deps-64-13/lib.lib":

$ cat btmp-RelWithDebInfo/listener-drome.exe.rsp
 /MACHINE:x64 /OUT:listener-drome.exe listener-drome@exe/src_listener-drome.cpp.obj "/nologo" "/DEBUG" "/PDB:listener-drome.pdb" "Basement.lib" "Plasma++.lib" "Loam++.lib" "C:/opt/oblong/deps-64-13/lib/boost_filesystem-vc141-mt-x64-1_67.lib" "C:/opt/oblong/deps-64-13/lib/boost_regex-vc141-mt-x64-1_67.lib" "C:/opt/oblong/deps-64-13/lib/boost_system-vc141-mt-x64-1_67.lib" "icuin.lib" "icuuc.lib" "Plasma.lib" "yaml.lib" "ssleay32.lib" "libeay32.lib" "Loam.lib" "ibpath:C://opt/oblong/deps-64-13/lib.lib" "ibpath:C:/opt/oblong/g-speak5.1/lib.lib" "/SUBSYSTEM:CONSOLE" "kernel32.lib" "user32.lib" "gdi32.lib" "winspool.lib" "shell32.lib" "ole32.lib" "oleaut32.lib" "uuid.lib" "comdlg32.lib" "advapi32.lib"

Looks like master knows a little about /libpath:

buildbot@rbb-win10-4 ~/src/meson
$ git describe
0.51.0-288-g80ef6fd6

$ find . -type f -print0 | xargs -0 grep -i libpath:
./mesonbuild/backend/vs2010backend.py:            if arg.startswith('/LIBPATH:'):
./mesonbuild/compilers/mixins/visualstudio.py:        return ['/LIBPATH:' + dirname]
./mesonbuild/compilers/mixins/visualstudio.py:                i = '/LIBPATH:' + i[2:]
./mesonbuild/compilers/mixins/visualstudio.py:            elif i[:9] == '/LIBPATH:':
./mesonbuild/dependencies/dev.py:            - Windows: We may get -LIBPATH:... which is later interpreted as
./mesonbuild/dependencies/dev.py:            elif arg.startswith('-LIBPATH:'):
./mesonbuild/dependencies/dev.py:                new_args.extend(cpp.get_linker_search_args(arg.lstrip('-LIBPATH:')))

On a hunch, I changed all my pc files to use /libpath rather than -libpath, and it worked around the problem.

I can't remember exactly why I settled on -libpath: rather than /libpath. I think I had to do that to squeak by some other problem. Indeed, using /libpath: in the .pc files causes my cmake build to fail with

ninja: error: FindFirstFileExA(/libpath:c:/opt/oblong/deps-64-13): The filename, directory name, or volume label syntax is incorrect.

And I don't think I'm the only one using -libpath: rather than /libpath:, so perhaps Meson should accept the alternate form.

dankegel commented 5 years ago

Patching PkgConfigDependency._search_libs like this:

--- a/mesonbuild/dependencies/base.py
+++ b/mesonbuild/dependencies/base.py
@@ -739,7 +739,7 @@ class PkgConfigDependency(ExternalDependency):
         # We also store this raw_link_args on the object later
         raw_link_args = self._convert_mingw_paths(shlex.split(out_raw))
         for arg in raw_link_args:
-            if arg.startswith('-L') and not arg.startswith(('-L-l', '-L-L')):
+            if arg.startswith('-L') and not arg.startswith(('-L-l', '-L-L')) and not arg.startswith(('-LIBPATH:')):
                 path = arg[2:]
                 if not os.path.isabs(path):
                     # Resolve the path as a compiler in the build directory would

causes the -LIBPATH: option to be dropped rather than mangled, so that's a bit of a clue.

dankegel commented 5 years ago

https://github.com/mesonbuild/meson/pull/5812 adds real test cases and a quick-and-dirty workaround.