1cmake_policy(SET CMP0054 NEW) 2 3function(assert_expected_list_len list_var expected_size) 4 list(LENGTH ${list_var} _size) 5 if(NOT _size EQUAL ${expected_size}) 6 message(FATAL_ERROR "list size expected to be `${expected_size}`, got `${_size}` instead") 7 endif() 8endfunction() 9 10# Pop from undefined list 11list(POP_FRONT test) 12if(DEFINED test) 13 message(FATAL_ERROR "`test` expected to be undefined") 14endif() 15 16# Pop from empty list 17set(test) 18list(POP_FRONT test) 19if(DEFINED test) 20 message(FATAL_ERROR "`test` expected to be undefined") 21endif() 22 23# Default pop from 1-item list 24list(APPEND test one) 25list(POP_FRONT test) 26assert_expected_list_len(test 0) 27 28# Pop from 1-item list to var 29list(APPEND test one) 30list(POP_FRONT test one) 31assert_expected_list_len(test 0) 32if(NOT DEFINED one) 33 message(FATAL_ERROR "`one` expected to be defined") 34endif() 35if(NOT one STREQUAL "one") 36 message(FATAL_ERROR "`one` has unexpected value `${one}`") 37endif() 38 39unset(one) 40unset(two) 41 42# Pop from 1-item list to vars 43list(APPEND test one) 44list(POP_FRONT test one two) 45assert_expected_list_len(test 0) 46if(NOT DEFINED one) 47 message(FATAL_ERROR "`one` expected to be defined") 48endif() 49if(NOT one STREQUAL "one") 50 message(FATAL_ERROR "`one` has unexpected value `${one}`") 51endif() 52if(DEFINED two) 53 message(FATAL_ERROR "`two` expected to be undefined") 54endif() 55 56unset(one) 57unset(two) 58 59# Default pop from 2-item list 60list(APPEND test one two) 61list(POP_FRONT test) 62assert_expected_list_len(test 1) 63if(NOT test STREQUAL "two") 64 message(FATAL_ERROR "`test` has unexpected value `${test}`") 65endif() 66 67# Pop from 2-item list 68list(PREPEND test one) 69list(POP_FRONT test one) 70assert_expected_list_len(test 1) 71if(NOT DEFINED one) 72 message(FATAL_ERROR "`one` expected to be defined") 73endif() 74if(NOT one STREQUAL "one") 75 message(FATAL_ERROR "`one` has unexpected value `${one}`") 76endif() 77if(NOT test STREQUAL "two") 78 message(FATAL_ERROR "`test` has unexpected value `${test}`") 79endif() 80 81# BUG 19436 82set(myList a b c) 83list(POP_FRONT myList first second) 84if(NOT first STREQUAL "a") 85 message(FATAL_ERROR "BUG#19436: `first` has unexpected value `${first}`") 86endif() 87if(NOT second STREQUAL "b") 88 message(FATAL_ERROR "BUG#19436: `second` has unexpected value `${second}`") 89endif() 90if(NOT myList STREQUAL "c") 91 message(FATAL_ERROR "BUG#19436: `myList` has unexpected value `${myList}`") 92endif() 93