I have a new meson project with 58 targets. Many of them use the same *.cc files, and meson builds each *.cc file once for each target, which is much slower than autotools. Also, the compile flags should be the same between targets, so in theory meson should be able to re-use the objects.
Is building many targets well-supported in meson? Is there a standard solution for situations like this? I could try to organize all of the sources in my project into shared libraries, but then I would have to decide how to group them, and with autotools I don't have to decide that. I haven't managed to find documentation on this.
-BenRI
P.S. Here is a minimal example:
-------- file: app1.cc -------
int f(int x ,int y) {return x;}
int main() { return f(0,1);}
------ file: meson.build -----
project('app12','cpp')
executable('app1',['app1.cc'])
executable('app2',['app1.cc'])
---------- command -----------
% meson . meson
% cd meson
% meson configure -Dwarning_level=3
% ninja
You should see a warning for unused parameter 'y' occur twice. The file compile_commands.json also has two entries for app1.cc .
Having the same source compiled with the same compile flags again and again is just waste of CPU power because it will generate the same binary file unless you have unreproducible build tricks like date and time.
If what you meant was to build common code for all targets, you can
just use static_library
to build your code and reuse it from all of
your target binary.
Move your f()
in lib.cc
and use the following meson.build
.
project('app12','cpp')
mylib = static_library('mylib', 'lib.cc')
executable('app1', 'app1.cc', link_with : mylib)
executable('app2', 'app1.cc', link_with : mylib)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With