In CMake the ELSE
and ENDIF
control flow functions take expressions as arguments. These are optional according to the documentation. What is the purpose of these then? Is it just to make the original IF
expression clearer for maintenance purposes, or does it provide some functionality?
if(<variable|string> STREQUAL <variable|string>) True if the given string or variable's value is lexicographically equal to the string or variable on the right.
CMakeLists. txt file contains a set of directives and instructions describing the project's source files and targets (executable, library, or both). When you create a new project, CLion generates CMakeLists. txt file automatically and places it in the project root directory.
A CMAKE file is a project file created by the open-source, cross-platform tool CMake. It contains source script in the CMake language for the entire program. CMake tool uses programming scripts, known as CMakeLists, to generate build files for a specific environment such as makefiles Unix machine.
There is no notion of a block comment in CMake syntax. However, to comment several lines at once, select the required lines and hit CTRL + Q . If the file is a . txt file (e.g. CMakeLists.
These expressions are optional as you said and they are useful when you have nested if()
statements - cmake will warn you when expr
in endif()
doesn't match expr
in nearest if()
.
The same is for else()
.
Simply - this protects you from mistakes in if()
else()
endif()
nested chains.
The optional arguments makes it easier to find matching if/else/endif parts, thus it is for better readability.
I personal do not use the arguments, as I find the else statement else(condition)
really confusing like in
if(condition)
// do something
else(condition)
// do something else
endif(condition)
I often misread else(condition)
as elseif(condition)
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With