Search code examples
c++meson-build

Meson targets that depend on subdir siblings


Here is my project structure:

.
├── include
├── src
│   ├── abc
│   │   ├── include
│   │   └── src
│   ├── def
│   │   ├── include
│   │   └── src
│   └── ghi
│       ├── include
│       └── src
└── vendor
    ├── bar
    │   ├── include
    │   └── src
    └── foo

16 directories

I would like to port my build to Meson. However, I'm not sure how to link targets defined in sibling folders.

My dependency graph looks like this:

  • src/abc/meson.build defines a static library abc
  • src/def/meson.build defines a static library def that depends on abc and foo
  • src/ghi/meson.build defines a static library ghi that depends on bar
  • vendor/bar/meson.build defines a static library bar
  • vendor/foo/meson.build defines a static library foo
  • The top-level meson.build defines an executable app that depends on abc, def and ghi

In the documentation, there seem to be two mechanisms:

  • subdir
  • subproject

It is not clear to me which is best here. I do not have any dependencies outside of my source-code.

What should I write in my meson.build files to link these targets together?


Solution

  • You can use subdir from the top-level meson.build file down. All variables you declare in the subdir meson.build files are available to later meson.build files. As long as you get the order of subdir calls correct, it will work.