An Introduction to Modern CMake People love to hate build systems. Just watch the talks from CppCon17 to see examples of developers making the state of build systems the brunt of jokes. This raises the question: Why? Certainly there are no shortage of problems when building. But I think that we have a very good solution to quite a few of those problems. It’s CMake. Not CMake 2.8 though; that was released before C++11 even existed! Nor the horrible examples out there for CMake (even those posted on KitWare’s own tutorials list). I’m talking about Modern CMake. CMake 3.15+, maybe even CMake 4.0+! It’s clean, powerful, and elegant, so you can spend most of your time coding, not adding lines to an unreadable, unmaintainable Make (Or CMake 2) file. In short, here are the most likely questions in your mind if you are considering Modern CMake: Why do I need a good build system? Do any of the following apply to you? You want to avoid hard-coding paths You need to build a package on more than one computer You want to use CI (continuous integration) You need to support different OSs (maybe even just flavors of Unix) You want to support multiple compilers You want to use an IDE, but maybe not all of the time You want to describe how your program is structured logically, not flags and commands You want to use a library You want to use tools, like Clang-Tidy, to help you code You want to use a debugger If so, you’ll benefit from a CMake-like build system. Why must the answer be CMake? Build systems are a hot topic. Of course there are many options. But even a really good one, or one that re-uses a familiar syntax, can’t come close to CMake. Why? Support. Every IDE supports CMake (or CMake supports that IDE). More packages use CMake than any other system. So, if you use a library that is designed to be included in your code, you have a choice: Make your own build system, or use one of the provided ones, and that will almost always include CMake. And that will quickly be the commo...
First seen: 2025-04-15 19:14
Last seen: 2025-04-15 22:14