Joseph Sibony
reading time:
In this blog post, I want to showcase the top seven open-source C++ build systems. The operative word here is showcased because I want not to merely state the facts but to illustrate what the top open-source C++ build systems are and why they are considered to be the top.
Don’t tell me the moon is shining; show me the glint of light on broken glass.
-Anton Chekhov
I am no Anton Chekhov, but let us begin. ?
1. Make
Make is a ubiquitous build system. No wonder, as it was created in 1977! Make is available in all versions of Unix like systems, Macintosh systems, and even Windows through Cygwin or natively thorough nmake. Make uses simple text files called Makefiles to guide the build. Makefiles contain rules, like so:
shownottell: show.c tell.c
gcc –o shownottell show.c tell.c
A rule contains a target and recipe. A target is a filename which in our case is shownottell. Separated by a semicolon are its prerequisites. The recipe line starts with a tab character and consists of shell commands. Executing these shell commands brings the target up-to-date. A rule tells make two things:
- Is the target out of date? à Prerequisites have changed
- If yes, how to update the target à Run the recipe
That is all there to Make. Standalone make as a build system is easy to implement and easy to maintain for simple projects. As the project grows, Makefiles can become very complicated. Despite its age, make is still the most commonly used tool for building software.
2. Modern CMake
The true successor of Make. I have been raving about CMake in a series of previous blog posts. Here they are:
- CMake Vs Make
- How CMake took the world by storm
- Modern CMake tips and tricks
- Cross compilation with CMake
- CMake Generators
- CMake, OpenCV and Unit Tests
Do check them out to see why modern CMake is the true successor of Make. In the true spirit of “show not tell”, I leave the rest of this exposition of CMake to those blog posts. But take my word, many new open-source C++ projects are either already on CMake or migrating to it. CMake is an open-source project hosted here.
3. Ninja
For a product to exist there has to be a Unique Selling Proposition (USP). The USP of Ninja is its focus on speed. In the spirit of “show not tell” let me include this image:
Ninja is a small open source build system that is designed to have its input files generated by a higher-level build system (like CMake) and is designed to run builds as fast as possible. In Visual Studio 2019, Linux projects can directly be build using CMake and Ninja. Ninja is an open-source project hosted here.
4. SCons
In his excellent book “Software Build Systems: Principles and Experience”, Peter Smith observes SCons and I quote him verbatim.
“[However], if you’re writing a new build system for C/C++ software, first consider using SCons or CMake.”
The context was in comparison with GNU Make (learn more about what is GNU Make), but as can clearly be seen, SCons is a worthy contender to CMake. SCons presents itself as an improved cross-platform open source build substitute for classic Make. The configuration files of SCons are in Python which is its USP. It proposes to use a real programming language for solving build problems. The current version of SCons needs at least python version 3.5 to run. SCons is an open-source project hosted here.
5. Meson
Now we are getting somewhere – we are getting into subatomic particle physics. ? Jokes aside, Meson is an open-source build system that is fast and user-friendly. Just as nature abhors a vacuum, Meson abhors:
- Wasted time the developer spends on writing/debugging build definitions
- Wasted time spent for the build system to start compiling
Meson does not intend its build definitions to be written in a Turing Complete language. It has a domain specific language (DSL) that is user-friendly and non-Turing complete, which it keeps as its USP. It is a cross-platform open source build system supporting multiple languages including C, C++, and Rust. Meson uses Ninja as its default build generator. Meson is an open-source project hosted here.
6. MSBuild
The Microsoft Build Engine (MSBuild) is a platform for building applications. But isn’t this blog post about the top seven open source C++ build systems? Is MSBuild open source? In the true spirit of “show not tell”, I present you this image:
Yes, at the fag end of 2015, Microsoft decided to open source software development process of MSBuild. The first release from this repository was on March 7, 2017, where MSBuild from this repository was packaged with Visual Studio 2017. MSBuild is now a true cross-platform application as it can be run on Unix-like systems that support .Net Core. MSBuild is an open source project hosted here.
Related: What is MSBuild
7. Waf
Although you might not have heard of Waf build tool, Incredibuild already has integration to it. Waf is an open source, python based build tool that supports multiple programming languages like C, C++, C#, Java, and even Fortran. It is a framework for configuring, compiling, and installing applications. In the spirit of “show not tell”, let me show here how to work with Waf. I have built Waf from source, so I am first interested in its version:
Here is how I get the build of the demo C++ project included in Waf:
Here is my wscript file which co-ordinated this build:
If you already know Python, then Waf is a pleasure to use. You can check out Waf here.
Chekhov’s gun and parting words
“If it is not going to be fired, it shouldn’t be hanging there ?. “
Each of the tools described here is with a purpose. Set them up and use them to bring your C++ project to life. Know about their pros and cons. Use them wisely and thank me later.
Table of Contents
Shorten your builds
Incredibuild empowers your teams to be productive and focus on innovating.