File: ecbuild_list_add_pattern.cmake

package info (click to toggle)
ecbuild 3.13.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 3,068 kB
  • sloc: sh: 1,404; perl: 732; f90: 472; cpp: 466; python: 383; ansic: 304; fortran: 43; makefile: 15
file content (102 lines) | stat: -rw-r--r-- 3,261 bytes parent folder | download | duplicates (28)
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# (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_add_pattern
# ========================
#
# Exclude items from a list that match a list of patterns. ::
#
#   ecbuild_list_add_pattern( LIST <input_list>
#                             GLOB <pattern1> [ <pattern2> ... ]
#                             [ SOURCE_DIR <source_dir> ]
#                             [ QUIET ] )
#
# Options
# -------
#
# LIST : required
#   list variable to be appended to
#
# GLOB : required
#   Regex pattern of exclusion
#
# SOURCE_DIR : optional
#   Directory from where to start search
#
# QUIET  : optional
#   Don't warn if patterns don't match
#
##############################################################################

function( ecbuild_list_add_pattern )

  set( options QUIET )
  set( single_value_args LIST SOURCE_DIR )
  set( multi_value_args  GLOB )

  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_add_pattern(): \"${_p_UNPARSED_ARGUMENTS}\"")
  endif()

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

  if( NOT _p_GLOB )
    ecbuild_critical("The call to ecbuild_list_add_pattern() doesn't specify the GLOB.")
  endif()

  #####

  set( input_list ${${_p_LIST}} )
  unset( matched_files )

  foreach( pattern ${_p_GLOB} )

    if( IS_ABSOLUTE ${pattern} )
      ecbuild_debug( "ecbuild_list_add_pattern: Adding ${pattern}" )
      file( GLOB_RECURSE matched_files ${pattern} )
    else()

      if(_p_SOURCE_DIR)
        if( IS_ABSOLUTE ${_p_SOURCE_DIR} )
          ecbuild_debug( "ecbuild_list_add_pattern: Adding ${_p_SOURCE_DIR}/${pattern}" )
          file( GLOB_RECURSE matched_files ${_p_SOURCE_DIR}/${pattern} )
        else()
          ecbuild_debug( "ecbuild_list_add_pattern: Adding ${_p_SOURCE_DIR}/${pattern}" )
          file( GLOB_RECURSE matched_files RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} ${_p_SOURCE_DIR}/${pattern} )
        endif()
      else()
        ecbuild_debug( "ecbuild_list_add_pattern: Adding ${pattern} ")
        file( GLOB_RECURSE matched_files RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} ${pattern} )
      endif()

    endif()

    if(matched_files)
      ecbuild_debug( "ecbuild_list_add_pattern: Found ${matched_files}" )
      list( APPEND input_list ${matched_files} )
      list( REMOVE_DUPLICATES input_list )
      set( ${_p_LIST} ${input_list} PARENT_SCOPE )
    else()
      if(NOT _p_QUIET)
        ecbuild_warn( "ecbuild_list_add_pattern: no matches found for patterns ${pattern}" )
      else()
        ecbuild_debug( "ecbuild_list_add_pattern:no matches found for patterns ${pattern}" )
      endif()
    endif()

  endforeach()


endfunction(ecbuild_list_add_pattern)