CMake vs Ninja – a real-life comparison with actual code

Which build system should you use: CMake? Or Ninja? That’s actually a rather weird question, but it’s a question that gets asked all the same. So let’s answer it…

For a full answer, watch the video.

In brief: Ninja is designed with one goal in mind: speed. To achieve maximum build speed, they’ve traded scriptability for speed. As a result, you’re not meant to write Ninja build scripts by hand, but should generate them with higher-level build systems such as CMake.

From Ninja’s own website:

Ninja is a small build system with a focus on speed. It differs from other build systems in two major respects: it is designed to have its input files generated by a higher-level build system, and it is designed to run builds as fast as possible.

This is why CMake vs Ninja is a weird question. Ninja’s authors are literally telling you not to write Ninja scripts by hand, but to use something like CMake instead.

So, forget CMake vs Ninja, and think instead: should I use CMake with Ninja?

Answer: yes, at least with huge projects. That’s because Ninja’s fast build speed is a time-saver, but writing Ninja scripts by hand definitely is not. Using CMake and Ninja together gives you the benefits of both. CMake is great when writing software for multiple platforms, while Ninja does fast builds.

CMake does have a steepish learning curve, but it’s quite good once you learn how to use it properly. I’ve created The CMake Tutorial to help you get up to speed with CMake fast. Check it out at cmaketutorial.com.

NOTE: This is part of a series comparing C/C++ build systems. Click here to compare more build systems.

Leave a Comment

Your email address will not be published. Required fields are marked *

 


Shopping Cart
Scroll to Top