cmListCommand: handle empty lists for list(REMOVE_AT)

Treat an empty list as a list with no valid bounds and return an error
message indicating that any given indices are out-of-bounds.
This commit is contained in:
Ben Boeckel
2018-10-11 17:26:44 -04:00
parent acfe53c588
commit 121a036f73
9 changed files with 33 additions and 9 deletions

View File

@@ -1,4 +1,4 @@
CMake Error at EmptyRemoveAt0.cmake:2 \(list\):
list REMOVE_AT given empty list
list index: mylist, 0 out of range \(0, 0\)
Call Stack \(most recent call first\):
CMakeLists.txt:3 \(include\)$

View File

@@ -0,0 +1 @@
1

View File

@@ -0,0 +1,4 @@
^CMake Error at REMOVE_AT-EmptyList.cmake:2 \(list\):
list index: nosuchlist, 0 out of range \(0, 0\)
Call Stack \(most recent call first\):
CMakeLists.txt:3 \(include\)$

View File

@@ -0,0 +1,6 @@
set(nosuchlist "")
list(REMOVE_AT nosuchlist 0)
if (NOT DEFINED nosuchlist OR NOT nosuchlist STREQUAL "")
message(FATAL_ERROR
"list(REMOVE_AT) modified our list")
endif ()

View File

@@ -1,4 +1,4 @@
^CMake Error at REMOVE_AT-NotList.cmake:2 \(list\):
list sub-command REMOVE_AT requires list to be present.
list index: nosuchlist, 0 out of range \(0, 0\)
Call Stack \(most recent call first\):
CMakeLists.txt:3 \(include\)$

View File

@@ -1,2 +1,6 @@
unset(nosuchlist)
list(REMOVE_AT nosuchlist 0)
if (DEFINED nosuchlist)
message(FATAL_ERROR
"list(REMOVE_AT) created our list")
endif ()

View File

@@ -22,6 +22,8 @@ run_cmake(REMOVE_DUPLICATES-TooManyArguments)
run_cmake(REVERSE-TooManyArguments)
run_cmake(SUBLIST-TooManyArguments)
run_cmake(REMOVE_AT-EmptyList)
run_cmake(FILTER-NotList)
run_cmake(REMOVE_AT-NotList)
run_cmake(REMOVE_DUPLICATES-NotList)