Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I speed up Meson build when many targets use the same C++ sources

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 .

like image 589
Benjamin Redelings Avatar asked Dec 08 '17 12:12

Benjamin Redelings


1 Answers

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)
like image 100
Yasushi Shoji Avatar answered Nov 15 '22 08:11

Yasushi Shoji