Deemo(Yizhou) Chen's Observatory

# CMake vs. Make

C

## What was the Problem? :()

When playing with my RP2040, following the official SDK instructions, I wonder why I have to type cmake then do make, why does it take two steps to build my project?

Well, long story short: Cmake is a cross-platform Makefiles generator, while make “reads the makefile and invokes a compiler, linker, and possibly other programs to make an executable file.”(Microsoft).

## CMake

Instead of thinking of CMake as a “C/C++ program maker,” I tend to say it as a “Cross-platform maker.” As its design principle says: “CMake is designed to be used in conjunction with the native build environment.”(Cmake.org); thus, it is independent of the Operating System it is working on(thus, the compilers), Which means as long as we configure the CMakeLists.txt correctly, CMake should “generate standard build files (e.g., makefiles on Unix and projects/workspaces in Windows MSVC).” on all the supported OS(Cmake.org)

## Make

On macOS(as it is based on UNIX) make is a tool from GNU which is included in the Xcode developer toolkit(GNU.org). Microsoft Visual Studio uses NMAKE.

Alternatively, it is also possible to call CMake functions to build the generated MakeFiles by calling cmake --build . in the build dir(CMake).

## A Demo for showing how it works

I am going to generate the Unix Makefiles for one of my ECE4760 Lab examples.

By running the following command in my build dir, CMake will be looking at the upper folder for the CMakeLists.txt.

cmake ..

Which generates the following files in the build folder:

CMakeCache.txt is more like the configuration file generated when CMake runs for the first time. It has, for example, the PATH to the compiler gonna be used, and the release mode, FLAGs, etc.

And the Makefile.txt has all the information the local make program needs to know to build the project(specify the build variables, preprocess, how to generate object files, etc.), unlike CMakeCache.txt CMake does not recommend users change Makefile.txt. And if I call:

cmake --build .  #or "make"

So, yeah, pretty cool stuff.