Skip to content

[Question] How to handle build of multiple projects? #6404

Closed
@second-reality

Description

@second-reality

Dear meson developers,

I successfully ported build system of my company from Make to Meson (~50 binaries in different projects, custom targets, generators, multiple languages). I have been very pleased by Meson. I added all our code (from multiple git submodules) in a single repo, and implemented a monolithic (and massive) meson.build file. So far, so good.

My coworkers adopted Meson, and for a new project, we would like to use it as the native build system (instead of make). However, some people prefer to clone only one project, instead of having whole repository (with submodules).

I want to allow to build a project, either as a separate project, or as part of my monolithic build. And I didn't find a correct solution to do it.


Concrete example

Imagine I have a project A and B. I want both of them to be buildable independently or together.

$ tree

├── A
│   ├── meson.build
│   └── src
│       ├── a.cpp
│       └── meson.build
├── B
│   ├── meson.build
│   └── src
│       ├── b.cpp
│       └── meson.build
└── meson.build

$ cat A/meson.build

project('a', 'cpp')
subdir('src')

$ cat A/src/meson.build
executable('a', ['a.cpp'])

-- here is my toplevel meson build file
$ cat meson.build

project('all', 'cpp')
subdir('A/src')
subdir('B/src')

By doing this, I can easily build A, B, or both of them.

Alas, I need both binaries a and b to be directly under my build folder. With this solution, I have this hierarchy:
$ tree build

build
├── A
│   └── src
│       ├── 4f2b75d@@a@exe
│       │   └── a.cpp.o
│       └── a
├── B
│   └── src
│       ├── 862d3b9@@b@exe
│       │   └── b.cpp.o
│       └── b
├── build.ninja

Main problem is that, to build only A or B, you need to fully specify path to it. Which is not very convenient.

$ ninja -C build a

ninja: Entering directory `build'
ninja: error: unknown target 'a', did you mean 'all'?

Expected result would be to be able to build 'a' like this, and that it would be available as 'build/a'

$ ninja -C build A/src/a

ninja: Entering directory `build'
ninja: no work to do. 

Other ideas

I tried to hack around meson.build_root() + 'exe_name', but I still have the issue with ninja (and a warning saying that what I do is wrong!). So, I shamely copy/pasted build of both project in my monolithic meson.build. This is boring, especially because paths are not the same (hierarchy has one level more), and when you change somewhere, you have to think at the other place.

I could as well define only list of sources in meson.build src directories, and copy/paste only the executables definition, but it still feels wrong to me.

I searched extensively in documentation, and a little bit in source code, without finding what I wanted.

So, what is the way to do it? Is there a way to define a kind of "alias" for my subdirs build targets? Or else, how am I supposed to organize build system to do this?

I don't want to use subproject, because it does not match my need there. All my projects are more or less independent.

Thank you for your answers and this delightful build system!

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions