[CMake] Bug in CMake documentation?

Alexander Neundorf a.neundorf-work at gmx.net
Sun May 9 07:49:13 EDT 2010


On Sunday 09 May 2010, Esben Mose Hansen wrote:
> On Sunday 09 May 2010 11:12:54 Esben Mose Hansen wrote:
> > I quote from the documentation (2.8)
> >
> > >   if(<constant>)
> > >
> > >
> > > 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, "", or ends in
> > > the suffix '-NOTFOUND'. Named boolean constants are case-insensitive.
> >
> > So what is the value of say "/home/esben/kde/lib/mylibrary.so"?
> > Experimental  test and common sense say true, but the documentation
> > doesn't say so. Wouldn't the correct documentation be
> >
> >   if(<constant>)
> > False if the constant is 0, OFF, NO, FALSE, N, IGNORE, "", or ends in the
> > suffix '-NOTFOUND'. Named boolean constants are case-insensitive. IF the
> > constant has any other value, it is true.
> >
> > Right?
>
> Wrong. I made some experiments, and as far as I have been able to
> determine, anything not on the true list (1 being there twice?!) is
> actually false, including non-zero numbers with space appended (but not
> prefixed) That means that the -NOTFOUND suffix is actually quite useless,
> except perhaps that it has a greater chance of being false in the future,
> too. So true constants include
>
> "ON"
> "on"
> "On"
> " 32"
>
> and false constant include
>
> "32 "
> "Off"
> " ON"
> "ON "
> "0"
> "/usr/lib/libmylib.so"
>
> Very interesting.

I can't confirm that.
I get the following with the attached CMakeLists.txt with cmake 2.8.1:

-- TMP("TRUE") is TRUE
-- TMP("true") is TRUE
-- TMP("ON") is TRUE
-- TMP("on") is TRUE
-- TMP("1") is TRUE
-- TMP("2") is TRUE
-- TMP("3") is TRUE
-- TMP("0") is FALSE
-- TMP("TrUe") is TRUE
-- TMP("foo") is TRUE
-- TMP("blub") is TRUE
-- TMP("/usr/lib/foooo") is TRUE
-- TMP(" on") is TRUE
-- TMP("on ") is TRUE
-- TMP(" on ") is TRUE
-- TMP("FALSE") is FALSE
-- TMP("false") is FALSE
-- TMP("OFF") is FALSE
-- TMP("off") is FALSE
-- TMP(" ") is TRUE
-- TMP("NOTFOUND") is FALSE
-- TMP("foo-NOTFOUND") is FALSE
-- TMP("foo;NOTFOUND") is TRUE
-- TMP("foo;blub-NOTFOUND") is FALSE
-- TMP("blub-NOTFOUND;foo") is TRUE
-- TMP("") is FALSE
-- Configuring done
-- Generating done
-- Build files have been written to: /home/alex/src/CMake/tests/booltest/b

Only things which I don't really like there are that both "foo;NOTFOUND" 
and "blub-NOTFOUND;foo" are considered TRUE.

Alex
-------------- next part --------------
cmake_minimum_required(VERSION 2.6)

macro(PRINT_BOOL _var)
   if(${_var})
      message(STATUS "${_var} is TRUE (\"${${_var}}\")")
   else(${_var})
      message(STATUS "${_var} is FALSE (\"${${_var}}\")")
   endif(${_var})
endmacro(PRINT_BOOL _var)

macro(TEST_BOOL)
   foreach(currentValue ${ARGN})
      set(TMP "${currentValue}")
      print_bool(TMP)
   endforeach(currentValue ${ARGN})
endmacro(TEST_BOOL)

test_bool(TRUE true ON on 1 2 3 0 TrUe foo blub /usr/lib/foooo " on" "on " " on ")

test_bool(FALSE false OFF off " " NOTFOUND foo-NOTFOUND)

set(TMP foo;NOTFOUND)
print_bool(TMP)

set(TMP foo;blub-NOTFOUND)
print_bool(TMP)

set(TMP blub-NOTFOUND;foo )
print_bool(TMP)



More information about the CMake mailing list