Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Purpose of CMake ENDIF and ELSE arguments

Tags:

cmake

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?

like image 270
Jake Avatar asked Apr 06 '15 13:04

Jake


People also ask

What is CMake Strequal?

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.

What are CMakeLists txt?

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.

What is a .CMake file?

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.

How do you comment on CMake list?

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.


2 Answers

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.

like image 189
Michał Walenciak Avatar answered Oct 01 '22 14:10

Michał Walenciak


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).

like image 27
usr1234567 Avatar answered Oct 01 '22 16:10

usr1234567