[CMake] LIST bugs for cmake version 2.6-patch 0 RC-8
Bill Hoffman
bill.hoffman at kitware.com
Fri Apr 18 12:07:59 EDT 2008
Is this something new to 2.6, or is it the same as 2.4?
Alan W. Irwin wrote:
> The LIST command has issues when dealing with a list with some empty
> elements.
>
> To see this try the following CMakeLists.txt
>
> set(list_example "1;;;2;3;4")
> message("list_example = ${list_example}")
> list(APPEND list_example "5")
> message("list_example = ${list_example}")
> list(LENGTH list_example list_example_length)
> message("list_example_length = ${list_example_length}")
> list(GET list_example 1 list_example1)
> message("list_example1 = ${list_example1}")
> list(REMOVE_AT list_example 5)
> message("list_example = ${list_example}")
>
> The result is
>
> list_example = 1;;;2;3;4
> list_example = 1;;;2;3;4;5
> list_example_length = 5
> list_example1 = 2
>
> CMake Error at CMakeLists.txt:5 (list):
> list index: 5 out of range (-5, 4)
>
> So APPEND is fine, but LENGTH, GET, and REMOVE_AT work as if the two empty
> components of the list are not there.
>
> VARIANT 1.
>
> If I replace the last two lines by
>
> list(REMOVE_AT list_example 1)
> message("list_example = ${list_example}")
>
> the result is
>
> list_example = 1;;;2;3;4
> list_example = 1;;;2;3;4;5
> list_example_length = 5
> list_example1 = 2
> list_example = 1;3;4;5
>
> VARIANT 2.
>
> If I replace the last two lines by
>
> list(REMOVE_ITEM list_example "1")
> message("list_example = ${list_example}")
>
> the result is
>
> list_example = 1;;;2;3;4
> list_example = 1;;;2;3;4;5
> list_example_length = 5
> list_example1 = 2
> list_example = 2;3;4;5
>
> VARIANT 3.
>
> If I replace the last two lines by
>
> list(REMOVE_ITEM list_example "")
> message("list_example = ${list_example}")
>
> the result is
>
> list_example = 1;;;2;3;4
> list_example = 1;;;2;3;4;5
> list_example_length = 5
> list_example1 = 2
> list_example = 1;2;3;4;5
>
> VARIANT 4.
>
> If I replace the last two lines by
>
> list(SORT list_example 1)
> message("list_example = ${list_example}")
>
> the result is
>
> list_example = 1;;;2;3;4
> list_example = 1;;;2;3;4;5
> list_example_length = 5
> list_example1 = 2
> list_example = 1;2;3;4;5
>
> VARIANT 5.
>
> If I replace the last two lines by
>
> list(REVERSE list_example 1)
> message("list_example = ${list_example}")
>
> the result is
>
> list_example = 1;;;2;3;4
> list_example = 1;;;2;3;4;5
> list_example_length = 5
> list_example1 = 2
> list_example = 5;4;3;2;1
>
> VARIANT 6.
>
> If I replace the last two lines by
>
> list(FIND list_example "1" one_index)
> message("list_example = ${list_example}")
> message("one_index = ${one_index}")
>
> the result is
>
> list_example = 1;;;2;3;4
> list_example = 1;;;2;3;4;5
> list_example_length = 5
> list_example1 = 2
> list_example = 1;;;2;3;4;5
> one_index = 0
>
> VARIANT 7.
>
> If I replace the last two lines by
>
> list(FIND list_example "" null_index)
> message("list_example = ${list_example}")
> message("null_index = ${null_index}")
>
> the result is
>
> list_example = 1;;;2;3;4
> list_example = 1;;;2;3;4;5
> list_example_length = 5
> list_example1 = 2
> list_example = 1;;;2;3;4;5
> null_index = -1
>
> VARIANT 8.
>
> If I replace the last two lines by
>
> list(INSERT list_example 4 6 7)
> message("list_example = ${list_example}")
>
> the result is
>
> list_example = 1;;;2;3;4
> list_example = 1;;;2;3;4;5
> list_example_length = 5
> list_example1 = 2
> list_example = 1;2;3;4;6;7;5
>
> All the above results for LENGTH, GET, REMOVE_AT, REMOVE_ITEM, SORT,
> REVERSE, and INSERT are consistent with the mental model that no indices
> are
> assigned to empty elements of a CMake list, and the result has the empty
> elements dropped (which by accident gives the correct result for
> REMOVE_ITEM
> when an empty element is dropped). However, from the above results APPEND
> keeps those empty elements in the result, as does FIND, (but FIND cannot
> find those empty elements).
>
> I am not aware of any other language that ignores empty elements or drops
> them from the results for certain operations so I believe the above results
> are symptoms of a language bug that needs to be addressed. I don't know
> CMake well enough to give you a patch, but I assume it is a fairly trivial
> fix.
>
> I also have a wishlist bug to report which I hope gets addressed at the
> same
> time as the more serious bug above.
>
> VARIANT 9.
>
> If I replace the last two lines by
>
> list(INSERT list_example 5 6 7)
> message("list_example = ${list_example}")
>
> the result is
>
> list_example = 1;;;2;3;4
> list_example = 1;;;2;3;4;5
> list_example_length = 5
> list_example1 = 2
> CMake Error at CMakeLists.txt:21 (list):
> list index: 5 out of range (-5, 4)
>
> If you insert just after the end of the list, it should work just like an
> append instead of giving you an index error as above.
>
> Alan
> __________________________
> Alan W. Irwin
>
> Astronomical research affiliation with Department of Physics and Astronomy,
> University of Victoria (astrowww.phys.uvic.ca).
>
> Programming affiliations with the FreeEOS equation-of-state implementation
> for stellar interiors (freeeos.sf.net); PLplot scientific plotting software
> package (plplot.org); the libLASi project (unifont.org/lasi); the Loads of
> Linux Links project (loll.sf.net); and the Linux Brochure Project
> (lbproject.sf.net).
> __________________________
>
> Linux-powered Science
> __________________________
> _______________________________________________
> CMake mailing list
> CMake at cmake.org
> http://www.cmake.org/mailman/listinfo/cmake
>
More information about the CMake
mailing list