A first very simple example

After the motivation is given to learn „cmake“ and working through the first modules of the official cmake tutorial, the first conclusion is: there is no debugger!

Back to the roots and use a print command to show what is going on.

„cmake“ knows a command „message()“.

This command together with some variables can be used to make the configuration step more verbose.

For example:

„cmake“ variables start with „CMAKE_“ and there are many of them.
(https://cmake.org/cmake/help/latest/manual/cmake-variables.7.html)

„${CMAKE_PROJECT_NAME}“ points to „hello“, the name used in the „project()“ command.
„${CMAKE_PROJECT_DESCRIPTION}“ returns the string after „DESCRIPTION“ and should be used to describe what this project will be used for.

The project structure looks like:

Within Geany I am using the „Project Manager“ plugin and created a project from a directory.

I can modify all necessary files now.
The file „compile_steps.txt“ is just supporting my laziness and I can use to „cut and paste“ the different commands in the Geany terminal.
„hello_world.c“ is the classic program from Kernighan and Ritchie.
I think this is the most often used program since the 70s in the last century.

The „CMakeLists.txt“:

Configuring „cmake“ with these instructions returns:

The information shown doesn’t show anything mysterious.

When doing a cross-compile, compiling for a different architecture, on a given architecture it is important to know if the correct compiler is used.

The raspberry Pi uses a different architecture then the RP2xxx.

A second execution shows the messages, but doesn’t change the configuration:

Compiling this with:

Verify the executable exists:

To our surprise, executing the program prints “hello, world!” in the terminal.

Some remarks.

I am a friend of excessive indentation.

This helps me to avoid making mistakes I cannot find by myself.

I really hate those solutions found for whatever language where for example a Jupyter Notebook has single row commands in a cell, because initially it looks like single rows only are allowed.

No, you CAN use newlines and tabs in a Jupyter Notebook cell!

In addition it gives me time to understand what I am doing why.

Using „message()“ provides additional useful information, because a year from now I do not know anymore what I thought today.

What next.

The next example will split an application in several files and combines them into an executable.
A second example using a sub-function

Stay tuned!