Hello,
(new to meson, might be saying stupid or ignorant things, don't hesitate to point it out)
I'm trying to convert a largish legacy codebase on Windows under MSVC, to use meson
rather than handmade solution files. When meson & ninja work, they're awesome to use.
The project uses a large number of pre-built libraries that are installed using pre-made NuGet files. In a typical case, I might have packages/foo_2.1.0/build/native, which contains include/foo.h and lib/foo.lib, and most often the .lib file is just an import library, and there's also packages/foo_redist_2.1.0/build/native/bin/foo.dll.
I'm having trouble handling this easily with meson. What I think I should be able to have is some sort of Dependency object for this case, which would behave as follows:
1. pass the right include args to compiler.
2. pass the right lib args to linker (with MSVC link.exe, the normal thing to do is just add pathnames to the .lib files).
3. arrange for the path to the DLL file to be part of "meson devenv", so I can build & run w/o installing.
4. arrange for the DLL file to be copied to the bin directory when "meson install" is run.
MSVC is relevant here because e.g. gcc under MSYS can just link directly to DLL and considers it a "library", so with such a system compiler.find_library(extra_dirs:...) can
encapsulate the DLL in a library object and help with 3. and 4. MSVC, however, links against the .lib file but then requires the .dll file in the same directory as .exe (or in PATH) at runtime.
What I tried:
- I couldn't find a dependency() call that would give me 1-4. I don't have pkg-config files for these packages anyway, but if I wrote them by hand and pointed pkg-config at them, I don't think that would give me 3. and 4.
- I can do declare_dependency() to enforce 1. and 2., but I can't make it also give me 3. and 4. I think using declare_dependency is probably wrong because it's meant for dependencies getting built by meson, not "pre-built, extrernal" ones like I have.
- I can do custom_target() or install_data() to enforce 4 and copy the DLL. It feels wrong because it won't be tied to the particular target that requires this dependency, instead foo.dll will always be copied unconditionally. And I need to do this separately for each DLL, and I still don't have 3. In fact, the behavior needed for 3. - adding paths to DLLs inside "meson devenv" - seems restricted to internally built DLLs.
If declare_dependency() creates a custom "internal dependency", and dependency() imports an external dependency using other tools' data (pkg-config, cmake etc.), I think there might be a place for something like external_dependency() to create a custom "external dependency" with similar arguments to declare_dependency(), but with the ability to specify "installable libraries" - DLLs on Windows - which are then PATH-enabled for devenv and installed together with executables depending on them.
If the maintainers agree it's a good idea, I can try getting it done and sending a PR. What do you think?