CMake control flow consists of both if statements and for and while loops. They work as we would expect.
The if statement has the usual clauses, if, elseif, and else.
if(<condition>)
<commands>
elseif(<condition>) # optional block, can be repeated
<commands>
else() # optional block
<commands>
endif()
The question becomes, what are truthy and falsey values in cmake? Truthy values are: YES, Y, TRUE, ON, and non-zero numeric values. Falsey values are: NO, N, FALSE, OFF, IGNORE, NOTFOUND, some_library-NOTFOUND, Empty String, and zero. Everything else is considered a variable name or string.
There are boolean conditionals such as: NOT, AND, OR, EQUAL, LESS, LESS_EQUAL, GREATER, GREATER_EQUAL, STREQUAL, STRLESS, STRLESS_EQUAL, STRGREATER, STRGREATER_EQUAL, VERSION_EQUAL, VERSION_LESS, VERSION_LESS_EQUAL, VERSION_GREATER, VERSION_GREATER_EQUAL, PATH_EQUAL, and MATCHES. There is no short-circuiting.
The foreach loop works almost as we would expect:
foreach(<loop_var> <items>)
<commands>
endforeach()
Each command in the loop is recorded but not executed and when the endforeach is reached, all the commands are executed for each of the items. Each iteration, the loop_var is set to the current item. To loop through lists we must use the lists keyword:
foreach(current_item IN LISTS list1 list2)
endforeach()
The while command works as we would expect:
while(<condition>)
<commands>
endwhile()
The condition works in exactly the same was a s the if command. Loops can also be interrupted using the BREAK() and CONTINUE() keywords.