-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlists.cmake
More file actions
81 lines (70 loc) · 2.58 KB
/
Copy pathlists.cmake
File metadata and controls
81 lines (70 loc) · 2.58 KB
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
# =============================================================================
# lists.cmake — list join and boolean toggle
# =============================================================================
## @brief Toggle a boolean-style variable between TRUE and FALSE in the
## parent scope.
## @param[in] var_name Name of the variable to toggle; the current value
## is read and the negated value is written into the parent
## scope.
function(toggle_bool _var)
buildmaster_message(CORE LOWLEVEL "Entering toggle_bool")
if(NOT ARGC EQUAL 1)
buildmaster_message(CORE FATAL "toggle_bool requires one variable name")
endif()
if(${${_var}})
set(${_var} FALSE PARENT_SCOPE)
else()
set(${_var} TRUE PARENT_SCOPE)
endif()
buildmaster_message(CORE LOWLEVEL "Exiting toggle_bool")
endfunction()
## @brief Join a CMake list into a single string while preserving
## semicolons inside quoted substrings.
## @param[out] _out_var Name of the variable to set in the parent scope
## with the resulting joined string.
## @param[in] _list_var Name of a variable that contains a CMake list
## (pass the variable name, not a literal list).
## @param[in] _separator String used to replace top-level semicolons
## (those not inside quotes).
## @note Iterates the serialized list character-by-character tracking
## quote state; replaces semicolons only when not inside quotes.
## Does not validate matching quotes; unbalanced quotes may produce
## unexpected output. Quote characters themselves are not copied
## into the result (the joined string is wrapped in one pair of `"`).
function(list_join _out_var _raw_string _separator)
buildmaster_message(CORE LOWLEVEL "Entering list_join")
set(result "\"")
set(in_single_quote FALSE)
set(in_double_quote FALSE)
set(raw "${_raw_string}")
if(NOT "${raw}" STREQUAL "")
string(LENGTH "${raw}" N)
math(EXPR N "${N} - 1")
foreach(i RANGE ${N})
string(SUBSTRING "${raw}" ${i} 1 ch)
if(ch STREQUAL "'")
if(NOT in_double_quote)
toggle_bool(in_single_quote)
endif()
continue()
endif()
if(ch STREQUAL "\"")
if(NOT in_single_quote)
toggle_bool(in_double_quote)
endif()
continue()
endif()
if(ch STREQUAL ";")
if(NOT in_single_quote AND NOT in_double_quote)
set(ch "\"${_separator}\"")
else()
set(ch ";")
endif()
endif()
set(result "${result}${ch}")
endforeach()
endif()
set(result "${result}\"")
set(${_out_var} "${result}" PARENT_SCOPE)
buildmaster_message(CORE LOWLEVEL "Exiting list_join")
endfunction()