

#MODERN CMAKE CODE#
You could code up something in make using intermediate files to cover the last two gaps, but you're on your own. With make, you're stuck on a file-by-file and manage-directories-by-hand level. These transitive dependencies can be exposed to or hidden from the dependent packages. A target is still a single output file, but it can have transitive ("public"/"interface" in CMake terms) dependencies. Modern CMake (starting with version 3.something) works in terms of dependencies between "targets". If one of library sources was removed since the previous version of Makefile, make won't rebuild it.

What sources it was built from, what compiler flags? CMake tracks it, make leaves it up to you. Once make builds an artifact, it forgets how it was built. The grammar of CMake is much easier to support for external tools than make's. Thus, CMake build can be orders of magnitude faster. All the shell script pieces that are normally piled into Makefile are only executed at the generation stage. make has some built-in C/C++ rules as well, but they are useless at best.ĬMake does a two-step build: it generates a low-level build script in ninja or make or many other generators, and then you run it. It's tailored to compile C++, for which you write much less build code, but can be also used for general purpose build. In the context of the question, they do the same thing: take a bunch of C/C++ files and turn them into a binary.ĬMake is much more high-level. It's not technically wrong it just describes HOW it works, but not WHAT it does.

The statement about CMake being a "build generator" is a common misconception.
#MODERN CMAKE WINDOWS#
Even if you're GNU-Make-only now, what if you later decide to expand to other platforms (be it Windows or something embedded), or just want to use an IDE?
#MODERN CMAKE GENERATOR#
Using a buildsystem generator makes your project more future-proof. CMake itself also provides some nice features like dependency detection, library interface management, or integration with CTest, CDash and CPack. I would always recommend using CMake (or another buildsystem generator, but CMake is my personal preference) if you intend your project to be multi-platform or widely usable. If you have Windows developers used to Visual Studio and Unix developers who swear by GNU Make, CMake is (one of) the way(s) to go.

So if you have a platform-independent project, CMake is a way to make it buildsystem-independent as well. From the same starting point, the same CMakeLists.txt file. It can produce Makefiles, it can produce Ninja build files, it can produce KDEvelop or Xcode projects, it can produce Visual Studio solutions. Make (or rather a Makefile) is a buildsystem - it drives the compiler and other build tools to build your code.ĬMake is a generator of buildsystems.
