-
Book Overview & Buying
-
Table Of Contents
-
Feedback & Rating

Minimal CMake
By :

CMake is one of those tools that unfortunately (though, not necessarily undeservedly) has a bit of a bad reputation. There are many developers out there who’ve been burned by CMake. They may have been forced to interact with it in a legacy code base, having had to deal with significant complexity, reams of CMake scripts, and questionable practices. Alternatively, they may have tried to use it for a new project, only to get stuck and frustrated trying to get things to work. As CMake has been around for a long time, there are many outdated examples and resources referencing old versions of CMake without all the latest features (and the benefit of hindsight about what works, and what not to do). As with any successful framework or language, CMake also comes with a certain amount of baggage, which is unfortunately unavoidable.
With all that being said, the good news is that over the last few years, there has been somewhat of a renaissance in CMake, and from version 3.0 (technically 2.8 for the diehards) onward, the new functionality to compose complex projects from targets has made an enormous difference, and it has been slowly gaining in popularity since.
One of the reasons for CMake’s growing popularity is a crucial detail that cannot be overstated. If you describe your build using CMake, you’ll by default have a project that you can build on Windows, Linux, and macOS. If you instead start a project with Visual Studio on Windows, Xcode on macOS, or Make files on Linux, it’s harder to migrate to other platforms, and harder for others working on different platforms to contribute. Having your build settings and options stored in versioned, human-readable scripts is incredibly useful (no more searching through nested tabs and windows in IDEs to find the right value to change).
The other interesting development is with this increasing popularity, CMake is now the lingua franca of build systems in C and C++. If a C or C++ project lives on GitHub, chances are it’s using CMake, and even if it’s not, with a minimal amount of effort, it’s possible to write a simple integration or wrapper to make that library consumable from CMake. This unlocks a vast wealth of potential, as adding a dependency to provide improvements to your project suddenly becomes a few lines of code, instead of an agonizing, laborious, and time-consuming process, usually requiring either embedding code from other libraries in your project or downloading and writing the code to build those libraries yourself.
Using CMake to build your projects and knowing enough CMake to get by (you most certainly do not need to be an expert) will make writing your applications faster, more maintainable, and more collaborative. It will also make working with C or C++ more fun (we promise), and not only C and C++, as there’s CMake support for C#, Fortran, CUDA, Objective-C, and Swift at the time of publication.
CMake is by no means perfect, but today, it is ubiquitous across the C and C++ landscape, and it is constantly evolving and improving thanks to the excellent work of the developers at Kitware and the many impactful open source contributors. We’re convinced, that whether you’re a professional C++ developer with years of experience, or a student or hobbyist just starting out, picking up, or getting reacquainted with CMake, will make you a happier, more productive developer. The experience you’ll gain when it comes to things such as dependency management and project structure will also serve you well in the future.
Let’s now turn our attention toward which group you feel most aligned with to help get the most out of this book.