MantisBT - CMake
View Issue Details
0006852CMakeCMakepublic2008-04-19 14:412008-04-21 17:51
irwin 
 
normalminoralways
closedfixed 
CMake-2-6 
 
0006852: LIST does not handle empty elements consistently or correctly
The attached CMakeLists.txt file demonstrates a number of issues with the CMake LIST command with either CMake 2.4.8 or 2.6.0 RC-8 if the list contains empty elements. 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.

The attached CMakeLists.txt also shows that any attempt to INSERT items exactly after the last element of the list fails with an out of range error. The INSERT should do the same thing as an APPEND in this case. Formally, this is a separate wish-list bug, but I am reporting it here since the fix is best done at the same time as the fix for the empty item problems.
No tags attached.
txt CMakeLists.txt (2,006) 2008-04-19 14:41
https://public.kitware.com/Bug/file/1419/CMakeLists.txt
? rc8_cmake.out (1,359) 2008-04-19 14:43
https://public.kitware.com/Bug/file/1420/rc8_cmake.out
Issue History
2008-04-19 14:41irwinNew Issue
2008-04-19 14:41irwinFile Added: CMakeLists.txt
2008-04-19 14:43irwinFile Added: rc8_cmake.out
2008-04-19 14:45irwinNote Added: 0011440
2008-04-21 17:51Bill HoffmanStatusnew => closed
2008-04-21 17:51Bill HoffmanNote Added: 0011464
2008-04-21 17:51Bill HoffmanResolutionopen => fixed

Notes
(0011440)
irwin   
2008-04-19 14:45   
Attached rc8.cmake.out is cmake output for attached CMakeLists.txt.
(0011464)
Bill Hoffman   
2008-04-21 17:51   
To avoid breaking backwards compatibility I have created a new policy for this:
CMP0007

If you set the policy to NEW, then empty elements are not skipped:

cmake_policy(SET CMP0007 NEW)

The default will be to warn when empty elements are found in a list given to the list command.

$ cvs commit -m "ENH: fix list command with empty elements" cmListCommand.cxx c
mPolicies.h cmPolicies.cxx
/cvsroot/CMake/CMake/Source/cmListCommand.cxx,v <-- cmListCommand.cxx
new revision: 1.20; previous revision: 1.19
/cvsroot/CMake/CMake/Source/cmPolicies.h,v <-- cmPolicies.h
new revision: 1.15; previous revision: 1.14
/cvsroot/CMake/CMake/Source/cmPolicies.cxx,v <-- cmPolicies.cxx
new revision: 1.30; previous revision: 1.29