[CMake] Bug in CMake documentation?

Alexander Neundorf a.neundorf-work at gmx.net
Sun May 9 12:01:32 EDT 2010


On Sunday 09 May 2010, Esben Mose Hansen wrote:
> On Sunday 09 May 2010 13:49:13 Alexander Neundorf wrote:
> > I can't confirm that.
> > I get the following with the attached CMakeLists.txt with cmake 2.8.1:
>
> Interesting. Actually, CMake behaves very oddly in this case. 2.8.0 prints
> "B is true" (and nothing else) for this small program:
>
> PROJECT(my)
>
> cmake_minimum_required(VERSION 2.8)
>
>
> SET(MYVAR "/var/lib")
>
> IF ("/var/lib")
> MESSAGE("A IS TRUE")
> ENDIF()
> IF (MYVAR)
> MESSAGE("B IS TRUE")
> ENDIF()
>
>
> Is that really intentional? It certainly explains the variance between our
> results.

Yes.
The argument to if() is the name of a variable.
So in 
IF ("/var/lib")
cmake checks whether the variable named "/var/lib" has a TRUE value. This 
variable most probably does not exist, so it returns false.
In 
IF (MYVAR)
cmake checks whether the variable named "MYVAR" has a TRUE value, now the 
value exists as "/var/lib", so it returns true.

Alex






More information about the CMake mailing list