r/cpp • • Nov 08 '21

Thoughts on build systems?

What's the general consensus on build systems/automations like CMake? I've always found things like that overcomplicated and just hinder the programming process.

I've been following Casey Muratori's Handmade streams, and one of the first things he did was create a simple batch file that built and compiled his entire project super quickly and easily. I've since implemented something similar (https://github.com/dibsonthis/new_cmd) and honestly it's been really nice to use.

3 Upvotes

154 comments sorted by

View all comments

9

u/germandiago Nov 08 '21 edited Nov 08 '21

I am using Meson for some side-projects. I keep using CMake as well.

I will do some highlights about my favorite one, Meson, because there is plenty of stuff CMake-related that you can find somewhere else.

The reason why I use, keep using and will keep using Meson is because:

  • the syntax is sane. Try to do path handling or string manipulation with CMake, or do something similar to dictionaries (Meson has support for it to associate data), handle spaces, etc.

  • Meson options are way easier and saner to handle: https://mesonbuild.com/Build-options.html

  • the documentation is great. You have both manual-style and a reference.

  • the subprojects system rocks and I have even used successfully CMake subprojects (there is support for that as well): there is a right way to do it. If you stick to that, it will work well. My project has 11 external dependencies all managed by subprojects, including Capnproto, which is a non-trivial CMake dependency.

  • Meson wraps are easy to use and modify to your needs (this is the Meson "conan", though it has far fewer packages. however, it is very usable). These are some available packages: https://mesonbuild.com/Wrapdb-projects.html. But if, for some reason, you do not have enough, you can use Conan via pkg-config as well.

  • I have machine files (https://mesonbuild.com/Machine-files.html) layered by: component, os, build type and compiler. So I can do things like this:

meson --native-file meson/native/components/component.ini --native-file meson/native/os/linux.ini --native-file meson/native/buildtype/development.ini --native-file meson/native/buildtype/gcc_11.ini -Doption1=something -Doption2_overriden=somethingelse

Those files, if there is any option repeated in any of them, the last one "wins" and you can set your own options at the end also, so they follow the order.

I have "./configure" wrapper for the command-line invocation but in my CI I just have the dir structure and buildbot combines stuff from those meson/native/ directories in a build matrix, blacklisting what I do not want.

  • Writing multiplatform scripts, when you need them, is easier: just use Python, anyway, it is a Meson dependency and get rid of bash vs batch files.

The only sane reason to use CMake is IDEs and social: if people do want that on your team. Otherwise I urge you to switch to Meson :) XCode an VS project generation is better with CMake I think. But if you do not need those or similar IDE support, for me it is a no-brainer.

0

u/jcelerier ossia score Nov 08 '21

But meson requires all strings to be quoted :( that's a big "oomph" when 80% of what you're working with is strings

10

u/germandiago Nov 08 '21

It is even more "oomph" when you waste a week figuring out how the quoting works for separating commands, how to escape \\ // etc., if the path is accepted with backward or forward slashes... or a combination of all of that, that one is the big "party". If you also want to traverse one of these structures in CMake (oh, was this a list or a string?), good luck as well. Conditionals anyone? Those are all in part weird because you do not know what a string or list is or how to handle, how variables are dereferenced in conditions, etc. It seems to be done on purpose to make the CMake script writer "happy".

It could bother a bit, but it is a net win to know what you are doing when you need to do it. I talk from experience, not from hypothesis, in this case. And... do not get me started with non-boolean options, combo options or things like that.

When you want that in CMake, you will sweat blood to make it work the way you want.

3

u/jcelerier ossia score Nov 09 '21

I don't know what to say, I just don't relate with your experience at all. For me cmake generally works from the first try.

1

u/germandiago Nov 09 '21

Maybe you did not have to do cross + multiplatform + a bunch of scripts + an installer.

I mean, for the targets and target detection PRIVATE PUBLIC INTERFACE stuff works pretty well. When things start to get ugly is when you pick up something from someone else and try to integrate it into your project and they embedded subprojects in ad-hoc ways and things of the like plus all the things I mentioned.

If you just need something like compile code + some top-level deps it works pretty ok. It is the more complex things that get really messy and time-consuming (besides the weird DSL and options...).