Fundamental building blocks of modules – functions and macros
It is clear that we need some basic building blocks to create utility modules. The most fundamental building blocks for utility modules are functions and macros, so it is essential to learn their working principles well. Let's start by learning about functions.
Functions
Let's remember what we have learned in Chapter 1, Kickstarting CMake, about functions. A function is the CMake language feature to define a logical code block that can be invoked to execute CMake commands. A function starts with function(…)
, has a body that contains CMake commands, and ends with the endfunction()
CMake command. The function()
command needs a name as the first argument, and optional function argument names, shown as follows:
function(<name> [<arg1> ...]) <commands> endfunction()
A function defines a new variable scope, so the changes made on CMake variables are only visible...