Difference between Cmake, gnu make and manually compiling

cmakegnu-make

I'm new to programming so this is a more of a abstract question than a technical one. I've been using IDE's to learn but I heard they tend to oversimplify the act of compiling,assembling and linking when creating an executable file.

I'm trying to download and compile a library without relying on an IDE (in this case librocket). I first had to use Cmake to create the binaries. After configuring and generating, I didn't see any object files or .cpp files in the output directory. I then had to use the gnu make command which then created both object files and .cpp files in the output directory.

What steps from downloading the source code to actually creating the object files does Cmake and gnu make do? At what point is the compiler and linker actually called?

I've successfully compiled a test library I wrote and then compiled another program that linked to it using g++ but I'm kind of lost because I have to use Cmake and gnu make instead of calling a compiler directly.

Best Answer

Cmake is a "project generator". It doesn't actually build any object files etc.; what it does is generate the control files for other tools (such as GNU make) which will build object files, etc.

The advantage of using cmake instead of writing the makefile directly is that, using the same cmake input file, cmake can generate project files for all sorts of different build control tools: in addition to makefiles it can generate Xcode (Mac OS X) project files, Microsoft Visual Studio project files, and control files for other tools like Ninja. If you're writing software that needs to be built on lots of different platforms then cmake is often a good choice.

For your situation, it goes like this: cmake generates a set of makefiles (only). You typically only do this once when you have a clean workspace. Then you run make which uses those makefiles to invoke the compiler as needed, when various files change. The makefiles also have rules to re-run cmake itself if any of the cmake input files change.