I have a project I am trying to port from makefiles to meson... and am just trying to figure out how to set it up so that everything builds correctly.
Where Foo A is made by combining Platform/A/* and Foo/A/* together and compiling everything... Bar A is made by combining Platform/A/* and Bar/A/* etc... And Foo/A, Foo/B, Foo/C are used together to make Foo.
Basically Platform contains device specific functionality... and Foo/Bar contain use specific functionality, that can change (via headers) some of the device specific values. such that platform/A cannot be compiled without Foo/A.
With a makefile this is doable, but ugly, and it is a pain to setup the dev environment... I am trying to figure out a more elegant way to do this.
rootdir
- Common
- Platform
- A
- inc/*
- src/*
- B
- inc/*
- src/*
- Foo
- A
- inc
- src
- B
- inc
- src
# Seperate build, but has same build philosphy and relies on platform/*
- Bar
- A
- inc/*
- src/*
- B
- inc/*
- src/*
So in a perfect world, your
Platformwould not require external configuration headers to be provided in order for it to compile. If this were the case, then you could simply have this:You could even omit the
subdir(...)calls and inline all of the config in the top-levelmeson.build. A key benefit here is thatPlatformis compiled exactly once, and re-used in the building ofFooandBar.Assuming you can't rework
Platform, then you can actually still use this template, with one small tweak:dependencyobjects can be thought of as a way to 'mix in' compilation and linkage information to a build target. So, when meson interpretsfoo_lib = library(..., dependencies: platform_dep), it will add in all of theplatform...sources to this target. The result is that yourPlatformgets compiled as part of theFoobuild target.However, this is also true of your
Bartarget. So, with this solution, you end up compilingPlatformtwice. If you have more than two targets, andPlatformisn't particularly small, this can end up eating a lot of your build time. The first example I gave does not have this problem, as we will compilePlatformonce, and then simply link it withFooandBar.There are some other solutions involving
subprojectsbut I won't get into those unless this solution doesn't fit your needs.