ENH: New foreach(<var> IN ...) mode

This creates a new mode of the foreach command which allows precise
iteration even over empty elements.  This mode may be safely extended
with more keyword arguments in the future.  The cost now is possibly
breaking scripts that iterate over a list of items beginning with 'IN',
but there is no other way to extend the syntax in a readable way.
This commit is contained in:
Brad King
2009-03-17 15:10:15 -04:00
parent ee00616289
commit ecb0f3af55
3 changed files with 81 additions and 3 deletions

View File

@@ -217,3 +217,22 @@ TEST_RANGE("3;5" "3;4;5")
TEST_RANGE("5;3" "5;4;3")
TEST_RANGE("3;10;2" "3;5;7;9")
TEST_RANGE("10;0;-3" "10;7;4;1")
# Test FOREACH IN signature
set(list1 "" a "")
set(list2 a "" b)
set(var_)
set(var_a)
set(var_b)
foreach(item IN LISTS list1 list2 ITEMS "" a "")
set(var_${item} "${var_${item}}x")
endforeach(item)
if(NOT "${var_}" STREQUAL "xxxxx")
message(FATAL_ERROR "count incorrect for \"\": [${var_}]")
endif()
if(NOT "${var_a}" STREQUAL "xxx")
message(FATAL_ERROR "count incorrect for \"a\": [${var_a}]")
endif()
if(NOT "${var_b}" STREQUAL "x")
message(FATAL_ERROR "count incorrect \"b\": [${var_b}]")
endif()