summaryrefslogtreecommitdiffstats
path: root/Tests/RunCMake/cmake_language/call_valid_command.cmake
blob: 2e965dc9d2def31fee15b7a1337dc304937e10f1 (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
95
96
97
98
99

## check continue() usage
set (VALUE 0)
foreach (i RANGE 1 4)
  set (VALUE "${i}")
  cmake_language (CALL "continue")
  set (VALUE "0")
endforeach()
if (NOT VALUE EQUAL "4")
  message (SEND_ERROR "error on continue() usage.")
endif()


## check break() usage
set (VALUE 0)
foreach (i RANGE 1 4)
  set (VALUE "${i}")
  cmake_language (CALL "break")
  set (VALUE 0)
endforeach()
if (NOT VALUE EQUAL "1")
  message (SEND_ERROR "error on break() usage.")
endif()


## check return() usage in macro
macro (call_return_in_macro)
  cmake_language (CALL "return")
  set (VALUE 1)
endmacro()
function (wrapper)
  call_return_in_macro()
  set (VALUE 1 PARENT_SCOPE)
endfunction()

set (VALUE 0)
wrapper()
if (NOT VALUE EQUAL "0")
  message (SEND_ERROR "error on return() usage in macro.")
endif()

set (VALUE 0)
cmake_language (CALL "wrapper")
if (NOT VALUE EQUAL "0")
  message (SEND_ERROR "error on return() usage in macro.")
endif()

function (wrapper2)
  cmake_language (CALL "call_return_in_macro")
  set (VALUE 1 PARENT_SCOPE)
endfunction()

set (VALUE 0)
wrapper2()
if (NOT VALUE EQUAL "0")
  message (SEND_ERROR "error on return() usage in macro.")
endif()

set (VALUE 0)
cmake_language (CALL "wrapper2")
if (NOT VALUE EQUAL "0")
  message (SEND_ERROR "error on return() usage in macro.")
endif()

## check return() usage in function
function (call_return_in_function)
  cmake_language (CALL "return")
  set (VALUE 1 PARENT_SCOPE)
endfunction()

set (VALUE 0)
call_return_in_function()
if (NOT VALUE EQUAL "0")
  message (SEND_ERROR "error on return() usage in function.")
endif()

set (VALUE 0)
cmake_language (CALL "call_return_in_function")
if (NOT VALUE EQUAL "0")
  message (SEND_ERROR "error on return() usage in function.")
endif()


## check usage of include_guard()
set (GUARD_VALUE 0)
include ("${CMAKE_CURRENT_SOURCE_DIR}/CheckIncludeGuard.cmake")
if (NOT GUARD_VALUE EQUAL "1")
  message (SEND_ERROR "error on include_guard() on first include.")
endif()

set (GUARD_VALUE 0)
include ("${CMAKE_CURRENT_SOURCE_DIR}/CheckIncludeGuard.cmake")
if (NOT GUARD_VALUE EQUAL "0")
  message (SEND_ERROR "error on include_guard() on second include.")
endif()


## check usage of cmake_minimum_required() and project()
add_subdirectory (CheckProject)