这里的问题是您需要将列表名称列表传递到列表中,macro
而不是列表中包含的值。
通过这样做("${List1}" "${List2}" ...)
,您将创建一个包含List1
and的串联内容的大列表List2
。
你macro
应该更像这样:
MACRO(Exclude_From_List)
# Split inputs into list of list variable names and items to be removed
SET(FoundExclude FALSE)
FOREACH(arg ${ARGN})
IF(FoundExclude)
LIST(APPEND ToBeRemoved ${arg})
ELSEIF(${arg} STREQUAL "EXCLUDE")
SET(FoundExclude TRUE)
ELSE()
LIST(APPEND ListNames ${arg})
ENDIF()
ENDFOREACH()
MESSAGE("Removing ${ToBeRemoved} from lists named ${ListNames}")
FOREACH(ListName ${ListNames})
# Ensure the variable is actually valid
IF(DEFINED ${ListName})
LIST(REMOVE_ITEM ${ListName} ${ToBeRemoved})
ENDIF()
ENDFOREACH()
ENDMACRO()
然后你可以像这样使用它:
SET(List1 A B C D E F)
SET(List2 F E D C B A)
SET(List3 1 2 3 4 5 6)
SET(List4 "")
SET(List5)
Exclude_From_List(List1 List2 List3 List4 List5 EXCLUDE A D F)