Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Alex Ghosh
CMake
Commits
a73071ca
Commit
a73071ca
authored
Jun 12, 2009
by
Ken Martin
Browse files
ENH: modified the if command to address bug 9123 some
parent
7e03edf1
Changes
5
Expand all
Hide whitespace changes
Inline
Side-by-side
Source/cmIfCommand.cxx
View file @
a73071ca
This diff is collapsed.
Click to expand it.
Source/cmIfCommand.h
View file @
a73071ca
...
...
@@ -191,6 +191,71 @@ public:
"examples. Where there are nested parenthesis the innermost are "
"evaluated as part of evaluating the expression "
"that contains them."
"
\n
"
"The if statement was written fairly early in CMake's history "
"and it has some convenience features that may be confusing for "
"new users. The if statement reduces operations until there is "
"a single remaining value, at that point if the case "
"insensitive value is: ON, 1, YES, TRUE, Y it returns true, if "
"it is OFF, 0, NO, FALSE, N, NOTFOUND, *-NOTFOUND, IGNORE it "
"will return false.
\n
"
"This is fairly reasonable. The convenience feature that makes "
"it more confusing is how CMake handles values that do not "
"match the true or false list. Those values are treated as "
"variables and are dereferenced even though they do not have "
"the required ${} syntax. This means that if you write
\n
"
" if (boobah)
\n
"
"CMake will treat it as if you wrote
\n
"
" if (${boobah})
\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 "
"if it is a defined variable, if so the variable's value is "
"used, otherwise the original value is used.
\n
"
"2) If the left hand argument to MATCHES is missing it returns "
"false without error
\n
"
"3) Both left and right hand arguments to LESS GREATER EQUAL "
"are independently tested to see if they are defined variables, "
"if so their defined values are used otherwise the original "
"value is used.
\n
"
"4) Both left and right hand arguments to STRLESS STREQUAL "
"STRGREATER are independently tested to see if they are defined "
"variables, if so their defined values are used otherwise the "
"original value is used.
\n
"
"5) Both left and right hand argumemnts to VERSION_LESS "
"VERSION_EQUAL VERSION_GREATER are independently tested to see "
"if they are defined variables, if so their defined values are "
"used otherwise the original value is used.
\n
"
"6) The right hand argument to NOT is tested to see if it is a "
"boolean constant, if so the value is used, otherwise it is "
"assumed to be a variable and it is dereferenced.
\n
"
"7) The left and right hand arguments to AND OR are "
"independently tested to see if they are boolean constants, if "
"so they are used as such, otherwise they are assumed to be "
"variables and are dereferenced.
\n
"
;
}
...
...
@@ -198,15 +263,13 @@ public:
// arguments were valid, and if so, was the response true. If there is
// an error, the errorString will be set.
static
bool
IsTrue
(
const
std
::
vector
<
std
::
string
>
&
args
,
std
::
string
&
errorString
,
cmMakefile
*
mf
);
std
::
string
&
errorString
,
cmMakefile
*
mf
,
cmake
::
MessageType
&
status
);
// Get a definition from the makefile. If it doesn't exist,
// return the original string.
static
const
char
*
GetVariableOrString
(
const
char
*
str
,
const
cmMakefile
*
mf
);
static
const
char
*
GetVariableOrNumber
(
const
char
*
str
,
const
cmMakefile
*
mf
);
cmTypeMacro
(
cmIfCommand
,
cmCommand
);
};
...
...
Source/cmPolicies.cxx
View file @
a73071ca
...
...
@@ -355,6 +355,19 @@ cmPolicies::cmPolicies()
"The NEW behavior for this policy is to allow the commands to do their "
"default cmake_policy PUSH and POP."
,
2
,
6
,
3
,
cmPolicies
::
WARN
);
this
->
DefinePolicy
(
CMP0012
,
"CMP0012"
,
"In CMake versions prior to 2.6.5 the only boolean constants were 0 and 1. "
"Other boolean constants such as true, false, yes, no, "
"on, off, y, n, notfound, ignore were recognized in some cases but not all. "
"In later versions of cmake these values are treated as boolean constants "
"more consistently and should not be used as variable names. "
"Please do not use them as variable names."
,
"The OLD behavior for this policy is to allow variables to have names such as "
"true and to dereference them. "
"The NEW behavior for this policy is to treat strings like true as a boolean constant."
,
2
,
6
,
5
,
cmPolicies
::
WARN
);
}
cmPolicies
::~
cmPolicies
()
...
...
Source/cmPolicies.h
View file @
a73071ca
...
...
@@ -52,6 +52,7 @@ public:
CMP0009
,
// GLOB_RECURSE should not follow symlinks by default
CMP0010
,
// Bad variable reference syntax is an error
CMP0011
,
// Strong policy scope for include and find_package
CMP0012
,
// Strong handling of boolean constants
// Always the last entry. Useful mostly to avoid adding a comma
// the last policy when adding a new one.
...
...
Source/cmWhileCommand.cxx
View file @
a73071ca
...
...
@@ -41,11 +41,35 @@ IsFunctionBlocked(const cmListFileFunction& lff, cmMakefile &mf,
std
::
vector
<
std
::
string
>
expandedArguments
;
mf
.
ExpandArguments
(
this
->
Args
,
expandedArguments
);
cmake
::
MessageType
messageType
;
bool
isTrue
=
cmIfCommand
::
IsTrue
(
expandedArguments
,
errorString
,
&
mf
);
cmIfCommand
::
IsTrue
(
expandedArguments
,
errorString
,
&
mf
,
messageType
);
while
(
isTrue
)
{
if
(
errorString
.
size
())
{
std
::
string
err
=
"had incorrect arguments: "
;
unsigned
int
i
;
for
(
i
=
0
;
i
<
this
->
Args
.
size
();
++
i
)
{
err
+=
(
this
->
Args
[
i
].
Quoted
?
"
\"
"
:
""
);
err
+=
this
->
Args
[
i
].
Value
;
err
+=
(
this
->
Args
[
i
].
Quoted
?
"
\"
"
:
""
);
err
+=
" "
;
}
err
+=
"("
;
err
+=
errorString
;
err
+=
")."
;
mf
.
IssueMessage
(
messageType
,
err
);
if
(
messageType
==
cmake
::
FATAL_ERROR
)
{
cmSystemTools
::
SetFatalErrorOccured
();
return
true
;
}
}
// Invoke all the functions that were collected in the block.
for
(
unsigned
int
c
=
0
;
c
<
this
->
Functions
.
size
();
++
c
)
{
...
...
@@ -68,7 +92,8 @@ IsFunctionBlocked(const cmListFileFunction& lff, cmMakefile &mf,
expandedArguments
.
clear
();
mf
.
ExpandArguments
(
this
->
Args
,
expandedArguments
);
isTrue
=
cmIfCommand
::
IsTrue
(
expandedArguments
,
errorString
,
&
mf
);
cmIfCommand
::
IsTrue
(
expandedArguments
,
errorString
,
&
mf
,
messageType
);
}
return
true
;
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment