if
: Conditionally execute a group of commands.if(expression)
# then section.
COMMAND1(ARGS ...)
COMMAND2(ARGS ...)
...
elseif(expression2)
# elseif section.
COMMAND1(ARGS ...)
COMMAND2(ARGS ...)
...
else(expression)
# else section.
COMMAND1(ARGS ...)
COMMAND2(ARGS ...)
...
endif(expression)
Evaluates the given expression. If the result is true, the commands in the THEN section are invoked. Otherwise, the commands in the else section are invoked. The elseif and else sections are optional. You may have multiple elseif clauses. Note that the same expression must be given to if, and endif. Long expressions can be used and the order or precedence is that the EXISTS, COMMAND, and DEFINED operators will be evaluated first. Then any EQUAL, LESS, GREATER, STRLESS, STRGREATER, STREQUAL, MATCHES will be evaluated. Then NOT operators and finally AND, OR operators will be evaluated. Possible expressions are:
if(variable)
True if the variable's value is not empty, 0, N, NO, OFF, FALSE, NOTFOUND, or <variable>-NOTFOUND.
if(NOT variable)
True if the variable's value is empty, 0, N, NO, OFF, FALSE, NOTFOUND, or <variable>-NOTFOUND.
if(variable1 AND variable2)
True if both variables would be considered true individually.
if(variable1 OR variable2)
True if either variable would be considered true individually.
if(COMMAND command-name)
True if the given name is a command, macro or function that can be invoked.
if(POLICY policy-id)
True if the given name is an existing policy (of the form CMP<NNNN>).
if(TARGET target-name)
True if the given name is an existing target, built or imported.
if(EXISTS file-name)
if(EXISTS directory-name)
True if the named file or directory exists. Behavior is well-defined only for full paths.
if(file1 IS_NEWER_THAN file2)
True if file1 is newer than file2 or if one of the two files doesn't exist. Behavior is well-defined only for full paths.
if(IS_DIRECTORY directory-name)
True if the given name is a directory. Behavior is well-defined only for full paths.
if(IS_ABSOLUTE path)
True if the given path is an absolute path.
if(variable MATCHES regex)
if(string MATCHES regex)
True if the given string or variable's value matches the given regular expression.
if(variable LESS number)
if(string LESS number)
if(variable GREATER number)
if(string GREATER number)
if(variable EQUAL number)
if(string EQUAL number)
True if the given string or variable's value is a valid number and the inequality or equality is true.
if(variable STRLESS string)
if(string STRLESS string)
if(variable STRGREATER string)
if(string STRGREATER string)
if(variable STREQUAL string)
if(string STREQUAL string)
True if the given string or variable's value is lexicographically less (or greater, or equal) than the string on the right.
if(version1 VERSION_LESS version2)
if(version1 VERSION_EQUAL version2)
if(version1 VERSION_GREATER version2)
Component-wise integer version number comparison (version format is major[.minor[.patch[.tweak]]]).
if(DEFINED variable)
True if the given variable is defined. It does not matter if the variable is true or false just if it has been set.