summaryrefslogtreecommitdiffstats
path: root/Tests/RunCMake/block/Workflows.cmake
blob: cbf032eb456fddd5fbce81e9abca043d48228ebb (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

set(VAR1 "OUTER1")
set(VAR2 "OUTER2")
set(VAR3 "OUTER3")

while (TRUE)
  # create a block with a new scope for variables
  block(SCOPE_FOR VARIABLES PROPAGATE VAR3)
    set(VAR2 "INNER2" PARENT_SCOPE)
    set(VAR3 "INNER3")
    break()
  endblock()
endwhile()

# check final values for variables
if(NOT DEFINED VAR1 OR NOT VAR1 STREQUAL "OUTER1")
  message(SEND_ERROR "block/endblock: VAR1 has unexpected value: ${VAR1}")
endif()
if(NOT DEFINED VAR2 OR NOT VAR2 STREQUAL "INNER2")
  message(SEND_ERROR "block/endblock: VAR2 has unexpected value: ${VAR2}")
endif()
if(NOT DEFINED VAR3 OR NOT VAR3 STREQUAL "INNER3")
  message(SEND_ERROR "block/endblock: VAR3 has unexpected value: ${VAR3}")
endif()



set(VAR1 "OUTER1")
set(VAR2 "OUTER2")
set(VAR3 "OUTER3")

function (OUTER)
  # create a block with a new scope for variables
  block(SCOPE_FOR VARIABLES PROPAGATE VAR3)
    set(VAR2 "INNER2" PARENT_SCOPE)
    set(VAR3 "INNER3")
    return()
  endblock()
  set(VAR1 "INNER1" PARENT_SCOPE)
endfunction()
outer()

# check final values for variables
if(NOT DEFINED VAR1 OR NOT VAR1 STREQUAL "OUTER1")
  message(SEND_ERROR "block/endblock: VAR1 has unexpected value: ${VAR1}")
endif()
if(NOT DEFINED VAR2 OR NOT VAR2 STREQUAL "OUTER2")
  message(SEND_ERROR "block/endblock: VAR2 has unexpected value: ${VAR2}")
endif()
if(NOT DEFINED VAR3 OR NOT VAR3 STREQUAL "OUTER3")
  message(SEND_ERROR "block/endblock: VAR3 has unexpected value: ${VAR3}")
endif()



set(VAR1 "OUTER1")
set(VAR2 "OUTER2")
set(VAR3 "OUTER3")

foreach (id IN ITEMS 1 2 3)
  # create a block with a new scope for variables
  block(SCOPE_FOR VARIABLES PROPAGATE VAR${id})
    set(VAR${id} "INNER${id}")
    continue()
    set(VAR${id} "BAD${id}")
  endblock()
endforeach()

# check final values for variables
if(NOT DEFINED VAR1 OR NOT VAR1 STREQUAL "INNER1")
  message(SEND_ERROR "block/endblock: VAR1 has unexpected value: ${VAR1}")
endif()
if(NOT DEFINED VAR2 OR NOT VAR2 STREQUAL "INNER2")
  message(SEND_ERROR "block/endblock: VAR2 has unexpected value: ${VAR2}")
endif()
if(NOT DEFINED VAR3 OR NOT VAR3 STREQUAL "INNER3")
  message(SEND_ERROR "block/endblock: VAR3 has unexpected value: ${VAR3}")
endif()