Loops
Explore how to implement while and foreach loops in CMake scripts to automate repetitive commands. Understand loop control commands like break and continue, as well as techniques for iterating through lists and multiple variables. This lesson helps you gain practical skills in managing control structures within CMake for more efficient project setup and scripting.
We'll cover the following...
Loops in CMake are fairly straightforward – we can use either while() or foreach() to repeatedly execute the same set of commands. Both of these commands support loop control mechanisms:
The
break()loop stops the execution of the remaining block and breaks from the enclosing loop.The
continue()loop stops the execution of the current iteration and starts at the top of the next one.
The while() loop
The loop block is opened with a while() command and closed with an endwhile() command. ...