...

/

Command Definitions: Functions

Command Definitions: Functions

Let's learn about functions and procedural paradigms in CMake.

Functions in CMake

To declare a command as a function, follow this syntax:

function(<name> [<argument>…])
<commands>
endfunction()
Function syntax

A function requires a name and optionally accepts a list of names of expected arguments. If a function call passes more arguments than were declared, the excess arguments will be interpreted as anonymous arguments and stored in the ARGN variable.

As mentioned before, functions open their own scope. We can call set(), providing one of the named arguments of the function, and any ...