2 #! See http://www.cmake.org/Wiki/CMakeMacroListOperations#LIST_FILTER
6 #! ctkMacroListFilter(<list> <regexp_var> [<regexp_var> ...]
7 #! [OUTPUT_VARIABLE <variable>])
10 #! Removes items from <list> which do not match any of the specified
11 #! regular expressions. An optional argument OUTPUT_VARIABLE
12 #! specifies a variable in which to store the matched items instead of
14 #! As regular expressions can not be given to macros (see bug #5389), we pass
15 #! variable names whose content is the regular expressions.
16 #! Note that this macro requires PARSE_ARGUMENTS macro, available here:
17 #! http://www.cmake.org/Wiki/CMakeMacroParseArguments
19 #! \ingroup CMakeUtilities
20 macro(ctkMacroListFilter)
21 ctkMacroParseArguments(LIST_FILTER "OUTPUT_VARIABLE" "" ${ARGV})
23 list(LENGTH LIST_FILTER_DEFAULT_ARGS LIST_FILTER_default_length)
24 if(${LIST_FILTER_default_length} EQUAL 0)
25 message(FATAL_ERROR "LIST_FILTER: missing list variable.")
27 if(${LIST_FILTER_default_length} EQUAL 1)
28 message(FATAL_ERROR "LIST_FILTER: missing regular expression variable.")
30 # Reset output variable
31 if(NOT LIST_FILTER_OUTPUT_VARIABLE)
32 set(LIST_FILTER_OUTPUT_VARIABLE "LIST_FILTER_internal_output")
34 set(${LIST_FILTER_OUTPUT_VARIABLE})
35 # Extract input list from arguments
36 list(GET LIST_FILTER_DEFAULT_ARGS 0 LIST_FILTER_input_list)
37 list(REMOVE_AT LIST_FILTER_DEFAULT_ARGS 0)
38 foreach(LIST_FILTER_item ${${LIST_FILTER_input_list}})
39 foreach(LIST_FILTER_regexp_var ${LIST_FILTER_DEFAULT_ARGS})
40 foreach(LIST_FILTER_regexp ${${LIST_FILTER_regexp_var}})
41 if(${LIST_FILTER_item} MATCHES ${LIST_FILTER_regexp})
42 list(APPEND ${LIST_FILTER_OUTPUT_VARIABLE} ${LIST_FILTER_item})
47 # If OUTPUT_VARIABLE is not specified, overwrite the input list.
48 if(${LIST_FILTER_OUTPUT_VARIABLE} STREQUAL "LIST_FILTER_internal_output")
49 set(${LIST_FILTER_input_list} ${${LIST_FILTER_OUTPUT_VARIABLE}})
51 endmacro(ctkMacroListFilter)