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?
相关问题
- Avoid cmake to add the flags -search_paths_first a
- CMakeList file to generate LLVM bitcode file from
- How to fix NDK build error for HelloCardboard samp
- Linking against GLEW with CMake
- Linking libavcodec in Cmake, find_library won'
相关文章
- Target requires the language dialect “CXX17” (with
- How do I tell cmake not to create a console window
- Do something for all targets
- CMake: Replace compile flags of an INTERFACE targe
- Generate Web Assembly from CMake Project with a Sp
- Integrate ITK (Insight Toolkit) into own project
- Is there a way to disallow “experimental” C++17 in
- CMake properties and expanding generator expressio
These expressions are optional as you said and they are useful when you have nested
if()
statements - cmake will warn you whenexpr
inendif()
doesn't matchexpr
in nearestif()
.The same is for
else()
.Simply - this protects you from mistakes in
if()
else()
endif()
nested chains.It is not that the else and endif are optional. The expression inside () are optional. From the documentation:
Previous versions of cmake required that you repeat the condition in else and endif:
The arguments to else() and endif() were required before version 2.6.0. From the CMake FAQ:
Other than helping with readability, they do not seem to have any function. See also this excellent answer.
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 inI often misread
else(condition)
aselseif(condition)
.