File: ecbuild_list_exclude_pattern.cmake

package info (click to toggle)
ecflow 5.15.2-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 51,868 kB
  • sloc: cpp: 269,341; python: 22,756; sh: 3,609; perl: 770; xml: 333; f90: 204; ansic: 141; makefile: 70
file content (88 lines) | stat: -rw-r--r-- 2,399 bytes parent folder | download | duplicates (27)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# (C) Copyright 2011- ECMWF.
#
# This software is licensed under the terms of the Apache Licence Version 2.0
# which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
# In applying this licence, ECMWF does not waive the privileges and immunities
# granted to it by virtue of its status as an intergovernmental organisation nor
# does it submit to any jurisdiction.

##############################################################################
#.rst:
#
# ecbuild_list_exclude_pattern
# ============================
#
# Exclude items from a list that match a list of patterns. ::
#
#   ecbuild_list_exclude_pattern( LIST <input_list>
#                                 REGEX <regex1> [ <regex2> ... ]
#                                 [ QUIET ] )
#
# Options
# -------
#
# LIST : required
#   list variable to be cleaned
#
# REGEX : required
#   Regex pattern of exclusions
#
# QUIET  : optional
#   Don't warn if patterns don't match
#
##############################################################################

function( ecbuild_list_exclude_pattern )

  set( options QUIET )
  set( single_value_args LIST )
  set( multi_value_args  REGEX )

  cmake_parse_arguments( _p "${options}" "${single_value_args}" "${multi_value_args}"  ${_FIRST_ARG} ${ARGN} )

  if(_p_UNPARSED_ARGUMENTS)
    ecbuild_critical("Unknown keywords given to ecbuild_list_exclude_pattern(): \"${_p_UNPARSED_ARGUMENTS}\"")
  endif()

  if( NOT _p_LIST  )
    ecbuild_critical("The call to ecbuild_list_exclude_pattern() doesn't specify the LIST.")
  endif()

  if( NOT _p_REGEX )
    ecbuild_critical("The call to ecbuild_list_exclude_pattern() doesn't specify the REGEX.")
  endif()

  #####

  set( result "" )
  set( matches_found 0 )

  # ecbuild_debug_var(_p_REGEX)

  foreach( item ${${_p_LIST}} )

    set( _keep 1 )

    foreach( pattern ${_p_REGEX} )
        if( ${item} MATCHES ${pattern} )
            set( _keep 0 )
            set( matches_found 1 )
        endif()
    endforeach()
    if( _keep )
        list( APPEND result ${item} )
#    else()
#      ecbuild_warn( "removing ${item}" )
    endif()

  endforeach()

  if( matches_found )
      set( ${_p_LIST} ${result} PARENT_SCOPE )
  else()
    if( NOT _p_QUIET )
        ecbuild_warn( "ecbuild_list_exclude_pattern: no matches found for patterns ${_p_REGEX} in ${_p_LIST}" )
    endif()
  endif()

endfunction(ecbuild_list_exclude_pattern)