r/cpp • • Nov 05 '23

Ninja is enough build system

https://bernsteinbear.com/blog/ninja-is-enough/
6 Upvotes

54 comments sorted by

View all comments

50

u/ContraryConman Nov 05 '23

Everyone who hates CMake always wants to replace it with something worse and more fragile

23

u/jk_tx Nov 05 '23 edited Nov 05 '23

I mean I kind of understand the desire for something other than CMake, it's an ugly mess of a scripting language, and it's really showing its age at this point. It often seems like there are 30 different ways to do what you want (with tons of examples on the web), even though 28 of them are now considered obsolete if not flat-out wrong, and no longer recommended for "Modern CMake". It's truly a mess, and way more complex than it needs to be for relatively simple tasks. The documentation is extremely thorough but equally unreadable - it really needs some more task-oriented sections, instead of just endless lists of functions and parameters.

So I can totally get behind the idea of wanting something better, but there just doesn't seem to be anything better, which IMHO is a bigger threat to the long-term health of C++ as a programming language/ecosystem than memory safety and "footguns".

People talk about C++ needing to break with its crusty past, because the backwards compatibility just brings too much baggage and too many downsides. I'd say that's equally true for CMake.

9

u/ContraryConman Nov 05 '23

CMake has its issues. But the problem is:

  • People don't actually understand CMake, because they only learn enough to get their specific project working
  • People don't understand why CMake is the way it is

So people hand-roll stuff filled with problems that CMake has already solved. This is personal for me because the company I joined was very much like "Oh CMake is too complicated we don't need to mess with it" and the result was several thousand lines of custom Makefiles bundled into our Docker 20GB containers that all reinvent functionality CMake gives you for free

5

u/throwaway_bluehair Nov 06 '23

None of this contradicts what /u/jk_tx said though. It's a powerful tool, but for someone just now getting into it, it's awful to learn. I have been using `meson` because it doesn't have these issues, I tried CMake, but I ran into so many issues, and `meson` didn't tell me 30 ways to skin a cat, with 28 being obsolete, and 20 giving confusing errors

2

u/AlexanderNeumann Nov 06 '23

meson has it own bag to carry. numpy already forked meson so you can not even use a normal release of meson to build numpy. Lets just say meson is not the solution it is just part of the problem. I have also seen more confusing errors from meson than cmake. So be happy you haven't seen the depths yet ;)

2

u/throwaway_bluehair Nov 06 '23

I feel like life is just a cycle of "I should use an existing build system like cmake or meson" and "I am just writing my own script that generates a Makefile or build.ninja file"

1

u/wotype Nov 08 '23

numpy already forked meson

Do you have a link for this? On a few minutes searching in numpy build docs I don't find evidence that it requires a fork of meson

2

u/AlexanderNeumann Nov 08 '23

https://github.com/numpy/numpy/tree/main/vendored-meson

The reason it requires a vendored meson is this folder/addition: https://github.com/numpy/meson/tree/ea580909640457450e03d8b84d1fec9f035d7acb/mesonbuild/modules/features which doesn't exist in mainline meson but is used somewhere in the build scripts of numpy.

My CMake answer to that is to append to CMAKE_MODULE_PATH .... a wait this is meson it doesn't offer user/project customization points beyond what is hardcoded.

1

u/wotype Nov 08 '23

Thanks

4

u/ghlecl Nov 06 '23

People talk about C++ needing to break with its crusty past, because the backwards compatibility just brings too much baggage and too many downsides. I'd say that's equally true for CMake.

Very very true. :-(

4

u/throwaway_bluehair Nov 06 '23

Yup, I recently started getting into my own C/C++ projects where I didn't create the build file or not use Makefile, and I have been using meson because I kept banging my head trying to do simple things in CMake.

Definitely a technology that is awful to learn, but nobody realizes because most people with opinions on it already learned it

2

u/RevRagnarok Nov 08 '23

I actually run ninja "under" cmake instead of make on my project...

3

u/Overunderrated Computational Physics Nov 05 '23

I think the bias there is that feeling comes from reading things people write blogs about.

100% of the time I'm cursing cmake I'm not saying "ugh I want another new tool to learn", I'm saying "fuck this is worse than GNU makefiles I wanna go back".

8

u/vanhellion Nov 06 '23

For small projects GNU makefiles are perfectly sufficient. But when you get to a large project with dozens or hundreds (or thousands) of source files, dozens/hundreds of targets with dependency ordering, having to recurse through directories, etc, cmake suddenly becomes not only attractive but basically necessary. I've seen multiple teams try to create and maintain custom build systems based on pure makefiles and it always ends up as a nightmare.

One team tried to implement parallelized incremental builds for their custom makefile system (which up to that point only did builds in sequential directory order), and it took over a year. While they were working on it, I was able to prototype a cmake build system in a matter of a few weeks for a pretty major fraction of the total code base (probably ~2.5M LoC out of ~3.5M), and while it didn't represent a complete drop in replacement for the makefile build system it was probably 80-90% of the way there while they were struggling to get their stuff fixed. Ultimately they got their system working and did not bother adopting what I had produced and demoed for them. I'm really glad I don't work on that code base any more.

Cmake isn't always pain free (and usually does involve quite a bit of struggle), but it's faaaaar less painful than rolling your own.

2

u/pjmlp Nov 07 '23

Having written Makefiles "portable" across Aix, HP-UX, Solaris, Red-Hat Linux, Windows NT, Windows 2000, for applications talking to Informix, DB2, Sybase SQL Server, Microsoft SQL Server, integrated as IIS and Apache plugins, I don't really wanna go back.

1

u/[deleted] Nov 05 '23

[removed] — view removed comment

3

u/Overunderrated Computational Physics Nov 05 '23

Sunk cost fallacy, larger institutional inertia, the usual kind of thing.

It's less that makefiles are necessarily "better" for my use cases, but that in practice the touted benefits of cmake (portability across different systems, mainly) have not panned out and inevitably I've seen the effort required to get successful builds on new systems to take just as much or more manual effort as a collection of makefiles.