-
Notifications
You must be signed in to change notification settings - Fork 0
/
List.cmake
70 lines (60 loc) · 2.35 KB
/
List.cmake
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
#=============================================================================
# mcl - The Missing CMake Library
# Copyright 2013 John Lamp
#
# Distributed under the OSI-approved Modified BSD License (the "License");
# see accompanying file Copyright.txt for details.
#
# This software is distributed WITHOUT ANY WARRANTY; without even the
# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
# See the License for more information.
#=============================================================================
include(mcl/ParseArguments)
include(mcl/String)
#!
# Usage: mcl_list(PROCESS_TAGS <list> <prefix> <tags>...)
#
# PROCESS_TAGS processes a <list> with tagged elements by removing the tags and
# creating a set of lists named after the <tags> prefixed by
# <prefix>. Tags take the form of a word enclosed in square
# brackets immediately preceding the element. For example:
# "[tagged]element", the tag would be "tagged" and the element
# would be "element".
#
function(mcl_list)
mcl_parse_arguments(mcl_list mcll_
"PROCESS_TAGS <list> <prefix> <tags>..."
ARGN ${ARGN})
if(mcll_PROCESS_TAGS)
_mcl_list_processTags()
endif()
endfunction()
macro(_mcl_list_processTags)
set(tagRe "\\[(.+)\\](.+)")
foreach (tag ${mcll_tags})
set(${mcll_prefix}${tag})
endforeach()
set(result)
foreach (item ${${mcll_list}})
if (item MATCHES ${tagRe})
string(REGEX REPLACE ${tagRe} "\\1;\\2" parts ${item})
list(GET parts 0 tag)
list(GET parts 1 item)
list(FIND mcll_tags ${tag} tagIndex)
if (tagIndex EQUAL -1)
mcl_string(JOIN ${mcll_tags} ", " expectedTags)
message(FATAL_ERROR "Found unexpected tag (${tag}) in list. "
"Expected tags are: "
${expectedTags})
endif()
list(APPEND result ${item})
list(APPEND ${mcll_prefix}${tag} ${item})
else()
list(APPEND result ${item})
endif()
endforeach()
set(${mcll_list} ${result} PARENT_SCOPE)
foreach (tag ${mcll_tags})
set(${mcll_prefix}${tag} ${${mcll_prefix}${tag}} PARENT_SCOPE)
endforeach()
endmacro()