[cmake-developers] A CMake representation issue for a list with one empty element
Alan W. Irwin
irwin at beluga.phys.uvic.ca
Thu Jul 11 15:36:50 EDT 2013
The following simple test case works (for CMake-2.8.10.1)
cmake_policy(SET CMP0007 NEW)
set(lines "a;;")
list(GET lines 0 package1)
list(GET lines 1 package2)
list(GET lines 1 package3)
message("${package1}")
message("${package2}")
message("${package3}")
list(REMOVE_AT lines 0 1 2)
e.g.,
software at raven> cmake -P test.cmake 2>&1 |od -a
0000000 a nl nl nl
0000004
However, if I try to process that same list
incrementally and print out lines after each
separate REMOVE_AT, there is an error.
cmake_policy(SET CMP0007 NEW)
set(lines "a;;")
list(GET lines 0 package1)
message("${package1}")
list(REMOVE_AT lines 0)
message(STATUS "lines = ${lines}")
list(GET lines 0 package2)
message("${package2}")
list(REMOVE_AT lines 0)
message(STATUS "lines = ${lines}")
list(GET lines 0 package3)
message("${package3}")
list(REMOVE_AT lines 0)
message(STATUS "lines = ${lines}")
software at raven> cmake -P test.cmake
a
-- lines = ;
-- lines =
CMake Error at test.cmake:11 (list):
list GET given empty list
If I comment out that last GET, then REMOVE_AT produces
a similar error.
I think the problem is in how lists with empty elements are
represented. If the first element is empty, then there
has to be a leading ";". If the last element is empty, then
there has to be a trailing ";". Which means that a list
with two empty elements must be represented as ";", but
that means there is no way to distinguish between a list
with zero elements ("") and a list with one empty element (also
represented by "" if you create it by REMOVE_AT).
If somebody could come up with a solution to what I think is a
fundamental representation issue, that would be great. For example,
maybe a special string to represent a list with one empty element? (My
use case is I found this issue when using file(STRINGS ...) to convert
a file into a list of lines. Subsequent incremental processing of
that list failed with this error because the file had trailing but
meaningful empty lines. I obviously can work around this issue with
special logic, but it would be good if that special workaround was not
needed for the case of a list with one empty element. Which
is why I have brought up this issue for discussion here.
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); the Time
Ephemerides project (timeephem.sf.net); PLplot scientific plotting
software package (plplot.sf.net); 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
__________________________
More information about the cmake-developers
mailing list