-
Notifications
You must be signed in to change notification settings - Fork 0
/
String.cmake
64 lines (56 loc) · 2.07 KB
/
String.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
#=============================================================================
# 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)
#!
# Usage: mcl_string(JOIN [<values>...] <separator> <variable>)
# mcl_string(FOR_NUMBER <number> <singular> <plural> <variable>)
#
# JOIN will concatenate all of the <values> with <separator> and store the
# result in <variable>. If there are no <values> provided <variable> is
# set to an empty string.
#
# FOR_NUMBER will set <variable> to either <singular> or <plural> as
# appropriate based on the value of <number>.
#
function(mcl_string)
mcl_parse_arguments(mcl_string mcls_
"JOIN [<values>...] <separator> <variable>"
"FOR_NUMBER <number> <singular> <plural> <variable>"
ARGN ${ARGN})
if (mcls_JOIN)
_mcl_string_join()
elseif (mcls_FOR_NUMBER)
_mcl_string_for_number(${mcls_number}
${mcls_singular} ${mcls_plural}
${mcls_variable})
endif()
endfunction()
macro(_mcl_string_join)
set(output)
set(first TRUE)
foreach(entry ${mcls_values})
if (first)
set(first FALSE)
else()
set(output "${output}${mcls_separator}")
endif()
set(output "${output}${entry}")
endforeach()
set(${mcls_variable} ${output} PARENT_SCOPE)
endmacro()
macro(_mcl_string_for_number number singular plural variable)
if (${number} EQUAL 1 OR ${number} EQUAL -1)
set(${variable} ${singular} PARENT_SCOPE)
else()
set(${variable} ${plural} PARENT_SCOPE)
endif()
endmacro()