Replace misleading example in the if() documentation (#10773)

Remove the example explained by the misleading phrase "CMake will treat
it as if you wrote".  This was originally added by commit a73071ca
(modified the if command to address bug 9123 some, 2009-06-12).  Later
related information elsewhere in the documentation was corrected and
made precise by commit cb185d93 (Fix if() command and CMP0012 OLD/NEW
behavior, 2009-10-27) but the misleading example was not corrected.

Replace the example with a correct one that more directly covers the
case that typically surprises newcomers.  Avoid recommending a "correct"
way to write code because this behavior is always specific to each case.
Also update the main documentation of the behavior to be more explicit.
This commit is contained in:
Brad King 2011-01-14 18:28:56 -05:00
parent 63d21c1f8e
commit e4e14e8568
1 changed files with 25 additions and 34 deletions

View File

@ -125,10 +125,13 @@ public:
"True if the constant is 1, ON, YES, TRUE, Y, or a non-zero number. " "True if the constant is 1, ON, YES, TRUE, Y, or a non-zero number. "
"False if the constant is 0, OFF, NO, FALSE, N, IGNORE, \"\", " "False if the constant is 0, OFF, NO, FALSE, N, IGNORE, \"\", "
"or ends in the suffix '-NOTFOUND'. " "or ends in the suffix '-NOTFOUND'. "
"Named boolean constants are case-insensitive." "Named boolean constants are case-insensitive. "
"If the argument is not one of these constants, "
"it is treated as a variable:"
"\n" "\n"
" if(<variable>)\n" " if(<variable>)\n"
"True if the variable's value is not a false constant." "True if the variable is defined to a value that is not a false "
"constant. False otherwise. "
"\n" "\n"
" if(NOT <expression>)\n" " if(NOT <expression>)\n"
"True if the expression is not true." "True if the expression is not true."
@ -199,38 +202,26 @@ public:
"that contains them." "that contains them."
"\n" "\n"
"The if statement was written fairly early in CMake's history " "The if command was written very early in CMake's history, predating "
"and it has some convenience features that are worth covering. " "the ${} variable evaluation syntax, and for convenience evaluates "
"The if statement reduces operations until there is " "variables named by its arguments. "
"a single remaining value, at that point if the case " "Note that normal variable evaluation with ${} applies before the "
"insensitive value is: ON, 1, YES, TRUE, Y it returns true, if " "if command even receives the arguments. "
"it is OFF, 0, NO, FALSE, N, NOTFOUND, *-NOTFOUND, IGNORE it " "Therefore code like\n"
"will return false. \n" " set(var1 OFF)\n"
" set(var2 \"var1\")\n"
"This is fairly reasonable. The convenience feature that sometimes " " if(${var2})\n"
"throws new authors is how CMake handles values that do not " "appears to the if command as\n"
"match the true or false list. Those values are treated as " " if(var1)\n"
"variables and are dereferenced even though they do not have " "and is evaluated according to the if(<variable>) case "
"the required ${} syntax. This means that if you write\n" "documented above. "
"The result is OFF which is false. "
" if (boobah)\n" "However, if we remove the ${} from the example then the command sees\n"
" if(var2)\n"
"CMake will treat it as if you wrote \n" "which is true because var2 is defined to \"var1\" which is not "
"a false constant."
" if (${boobah})\n" "\n"
"Automatic evaluation applies in the other cases as follows:\n"
"likewise if you write \n"
" if (fubar AND sol)\n"
"CMake will conveniently treat it as \n"
" if (\"${fubar}\" AND \"${sol}\")\n"
"The later is really the correct way to write it, but the "
"former will work as well. Only some operations in the if "
"statement have this special handling of arguments. The "
"specific details follow: \n"
"1) The left hand argument to MATCHES is first checked to see " "1) The left hand argument to MATCHES is first checked to see "
"if it is a defined variable, if so the variable's value is " "if it is a defined variable, if so the variable's value is "