On 11/6/21 1:16 PM, oyvind wrote:
> So much background info but I hope you are still with me. I guess my
> questions are:
> - At a glance, can subprojects be a better alternative to git submodules
> for us?
> - Are the two options even mutually exclusive?
As Jussi said, they are not exclusive and you can use them together. I'd
like to elaborate on this:
subprojects attempt to configure a directory as an isolated namespace.
You don't get to (or want to) share context between a subproject and a
superproject -- you cannot poke directly at files in a subproject e.g.
add them as source files for build targets in the superproject.
What you are supposed to do instead is provide exported interfaces,
built programs and dependency objects created by declare_dependency,
which you can access via foo_subproject.get_variable() or by
override_find_program() and override_dependency().
That's all that a subproject means. Logical dependency isolation. So, I
think your impression is right and using them will appeal to you. :)
There are a couple ways to *get* the source files of a subproject. Either:
- add them as submodules, then `git submodule update --init --recursive`
- check them directly into the superproject repo
- use wrap files and meson will download (clone or http tarball) them
for you
- use wrap files *and* submodules, and meson will init the submodule for
you
This last option is highly convenient, as you get the best of both worlds.
> - Are there any pitfalls, limitations or gotchas to look out for with
> subprojects?
> - Are there any recommendations or best practices for using Meson
> subprojects?
As you mention diamond dependencies, keep in mind that meson resolves
all dependencies by hoisting them from subprojects into the superproject
and using a single version of each one. Hopefully that is a good
thing... if you have nested component dependencies, ideally you want to
only have one version of that dependency and share it between the
subprojects that need it.
In meson, the rule is that the first time meson encounters a
subproject('name') or a dependency('name') that is resolved using wrap
provides, it is hoisted to the toplevel, and thereafter every attempt to
resolve that dependency will resolve to the originally resolved version.
(For cases where two different versions of a dependency are maintained
in parallel, e.g. Gtk 3 and Gtk 4, they simply get different names.)
--
Eli Schwartz