blob: 38c032ffdb6e3a01dad1e9fee869f161315c3079 (
plain)
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
|
set(_THIS_FILE "${CMAKE_CURRENT_LIST_FILE}")
set(_THIS_DIR "${CMAKE_CURRENT_LIST_DIR}")
if(CMAKE_CURRENT_FUNCTION)
message(SEND_ERROR "`CMAKE_CURRENT_FUNCTION` is not expected to be set here")
endif()
if(CMAKE_CURRENT_FUNCTION_LIST_FILE)
message(SEND_ERROR "`CMAKE_CURRENT_FUNCTION_LIST_FILE` is not expected to be set here")
endif()
if(CMAKE_CURRENT_FUNCTION_LIST_DIR)
message(SEND_ERROR "`CMAKE_CURRENT_FUNCTION_LIST_DIR` is not expected to be set here")
endif()
if(CMAKE_CURRENT_FUNCTION_LIST_LINE)
message(SEND_ERROR "`CMAKE_CURRENT_FUNCTION_LIST_LINE` is not expected to be set here")
endif()
function(bar)
if(NOT CMAKE_CURRENT_FUNCTION STREQUAL "bar")
message(SEND_ERROR "Bad value of `CMAKE_CURRENT_FUNCTION`")
endif()
if(NOT CMAKE_CURRENT_FUNCTION_LIST_FILE MATCHES "^.*/CMAKE_CURRENT_FUNCTION.cmake$")
message(SEND_ERROR "Bad value of `CMAKE_CURRENT_FUNCTION_LIST_FILE`")
endif()
if(NOT CMAKE_CURRENT_FUNCTION_LIST_FILE STREQUAL _THIS_FILE)
message(SEND_ERROR "Bad value of `CMAKE_CURRENT_FUNCTION_LIST_FILE`")
endif()
if(NOT CMAKE_CURRENT_FUNCTION_LIST_DIR MATCHES "^.*/Tests/RunCMake/function$")
message(SEND_ERROR "Bad value of `CMAKE_CURRENT_FUNCTION_LIST_DIR`")
endif()
if(NOT CMAKE_CURRENT_FUNCTION_LIST_DIR STREQUAL _THIS_DIR)
message(SEND_ERROR "Bad value of `CMAKE_CURRENT_FUNCTION_LIST_DIR`")
endif()
if(NOT CMAKE_CURRENT_FUNCTION_LIST_LINE EQUAL 17)
message(SEND_ERROR "Bad value of `CMAKE_CURRENT_FUNCTION_LIST_LINE`")
endif()
endfunction()
function(foo)
if(NOT CMAKE_CURRENT_FUNCTION STREQUAL "foo")
message(SEND_ERROR "Bad value of `CMAKE_CURRENT_FUNCTION`")
endif()
if(NOT CMAKE_CURRENT_FUNCTION_LIST_FILE MATCHES "^.*/function/CMAKE_CURRENT_FUNCTION.cmake$")
message(SEND_ERROR "Bad value of `CMAKE_CURRENT_FUNCTION_LIST_FILE`")
endif()
if(NOT CMAKE_CURRENT_FUNCTION_LIST_FILE STREQUAL _THIS_FILE)
message(SEND_ERROR "Bad value of `CMAKE_CURRENT_FUNCTION_LIST_FILE`")
endif()
if(NOT CMAKE_CURRENT_FUNCTION_LIST_DIR MATCHES "^.*/Tests/RunCMake/function$")
message(SEND_ERROR "Bad value of `CMAKE_CURRENT_FUNCTION_LIST_DIR`")
endif()
if(NOT CMAKE_CURRENT_FUNCTION_LIST_LINE EQUAL 38)
message(SEND_ERROR "Bad value of `CMAKE_CURRENT_FUNCTION_LIST_LINE`")
endif()
if(NOT CMAKE_CURRENT_FUNCTION_LIST_DIR STREQUAL _THIS_DIR)
message(SEND_ERROR "Bad value of `CMAKE_CURRENT_FUNCTION_LIST_DIR`")
endif()
bar()
endfunction()
foo()
if(CMAKE_CURRENT_FUNCTION)
message(SEND_ERROR "`CMAKE_CURRENT_FUNCTION` is not expected to be set here")
endif()
if(CMAKE_CURRENT_FUNCTION_LIST_FILE)
message(SEND_ERROR "`CMAKE_CURRENT_FUNCTION_LIST_FILE` is not expected to be set here")
endif()
if(CMAKE_CURRENT_FUNCTION_LIST_DIR)
message(SEND_ERROR "`CMAKE_CURRENT_FUNCTION_LIST_DIR` is not expected to be set here")
endif()
if(CMAKE_CURRENT_FUNCTION_LIST_LINE)
message(SEND_ERROR "`CMAKE_CURRENT_FUNCTION_LIST_LINE` is not expected to be set here")
endif()
include("${CMAKE_CURRENT_LIST_DIR}/DummyMacro.cmake")
function(calling_macro)
dummy()
endfunction()
calling_macro()
cmake_policy(SET CMP0007 NEW)
# ATTENTION `CMAKE_CURRENT_LIST_LINE` can't be used in `math()'
function(print_self)
file(STRINGS "${CMAKE_CURRENT_FUNCTION_LIST_FILE}" _lines)
math(EXPR _begin "${CMAKE_CURRENT_FUNCTION_LIST_LINE} - 1")
list(SUBLIST _lines ${_begin} 7 _lines) # This function has 7 lines only
list(JOIN _lines "\n" _lines)
message(STATUS "Print the `${CMAKE_CURRENT_FUNCTION}` function:\n${_lines}")
endfunction()
print_self()
|