-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpm__core.disallow_special_names.cmake
72 lines (67 loc) · 3.48 KB
/
pm__core.disallow_special_names.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
71
72
include_guard(GLOBAL)
include(pm__core.msg)
function(pm_disallow_special_names)
foreach(V IN LISTS ARGV)
if(V MATCHES "^ARG[VNC]$" OR
V MATCHES "^ARGV[0-9]+$")
pm_exit(
"A variable, \"${V}\", passed into this function is a "
"special-case variable name that is generated for all CMake "
"function and macro invocations. We are, by definition, unable "
"to read or modify the contents of such variables outside of "
"the scope for which they were geneated---e.g. in any called "
"function. (You might be able to ex; `set(argn ${ARGN})` and "
"pass `argn` to be read/modified by a called function, though.)"
)
elseif(V MATCHES "^UNPARSED_ARGUMENTS$" OR
V MATCHES "^UNSET_PARAMETERS$")
pm_warn_devs(
"A variable, \"${V}\", passed into this function is a "
"special-case variable name that is generated by "
"`pm_parse_arguments`. Called functions are technically "
"capable of reading and modifying the contents of this "
"variable, but it is *highly* likely that passing it will "
"result in local shadowing that will lead to not-so-subtle "
"bugs (it's all but guaranteed if `pm_parse_arguments` is "
"called in the same scope)."
)
elseif(V STREQUAL "OUTn")
pm_warn_devs(
"You seem to be passing the variable \"OUTn\" *into* a called "
"function. It's our convention to use that variable to store "
"the name of functions' output parameters. If you're passing "
"\"OUTn\" into a function that has an argument named \"OUTn\", "
"you're going to see some _really_ weird variable shaodowing "
"issues. (You might be ble to ex; `set(outn ${OUTn})` and pass "
"`outn` into the called function, though.)"
)
endif()
endforeach()
endfunction()
function(pm_loosely_disallow_special_names)
foreach(V IN LISTS ARGV)
if(V MATCHES "^ARG[VNC]$" OR
V MATCHES "^ARGV[0-9]+$")
pm_exit(
"A variable, \"${V}\", passed into this function is a "
"special-case variable name that is generated for all CMake "
"function and macro invocations. We are, by definition, unable "
"to read or modify the contents of such variables outside of "
"the scope for which they were geneated---e.g. in any called "
"function. (You might be able to ex; `set(argn ${ARGN})` and "
"pass `argn` to be read/modified by a called function, though.)"
)
elseif(V STREQUAL "OUTn")
message(STATUS "V :: ${V}")
pm_warn_devs(
"You seem to be passing the variable \"OUTn\" *into* a called "
"function. It's our convention to use that variable to store "
"the name of functions' output parameters. If you're passing "
"\"OUTn\" into a function that has an argument named \"OUTn\", "
"you're going to see some _really_ weird variable shaodowing "
"issues. (You might be ble to ex; `set(outn ${OUTn})` and pass "
"`outn` into the called function, though.)"
)
endif()
endforeach()
endfunction()