File: CMakeLists.txt

package info (click to toggle)
cmake 4.2.3-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 152,456 kB
  • sloc: ansic: 403,896; cpp: 303,920; sh: 4,105; python: 3,583; yacc: 3,106; lex: 1,279; f90: 538; asm: 471; lisp: 375; cs: 270; java: 266; fortran: 239; objc: 215; perl: 213; xml: 198; makefile: 111; javascript: 83; pascal: 63; tcl: 55; php: 25; ruby: 22
file content (91 lines) | stat: -rw-r--r-- 2,137 bytes parent folder | download | duplicates (5)
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
cmake_minimum_required(VERSION 3.10)
project(Unset C)

# Local variable
set(x 42)
if(NOT x EQUAL 42)
  message(FATAL_ERROR "x!=42")
endif()

if(NOT DEFINED x)
  message(FATAL_ERROR "x should be defined!")
endif()

unset(x)
if(DEFINED x)
  message(FATAL_ERROR "x should be undefined now!")
endif()

# Local variable test unset via set()
set(x 43)
if(NOT x EQUAL 43)
  message(FATAL_ERROR "x!=43")
endif()
if(DEFINED CACHE{x})
  message(FATAL_ERROR "x shouldn't be found in the cache")
endif()

set(x)
if(DEFINED x)
  message(FATAL_ERROR "x should be undefined now!")
endif()


# Cache variable
set(BAR "test" CACHE STRING "documentation")
if(NOT DEFINED BAR)
  message(FATAL_ERROR "BAR not defined")
endif()

if(NOT DEFINED CACHE{BAR})
  message(FATAL_ERROR "BAR could not be found by CACHE{BAR}")
endif()

# Test interaction of cache entries with variables.
set(BAR "test-var")
if(NOT "$CACHE{BAR}" STREQUAL "test")
  message(FATAL_ERROR "\$CACHE{BAR} changed by variable BAR")
endif()
if(NOT "${BAR}" STREQUAL "test-var")
  message(FATAL_ERROR "\${BAR} not separate from \$CACHE{BAR}")
endif()
unset(BAR)
if(NOT "${BAR}" STREQUAL "test")
  message(FATAL_ERROR "\${BAR} does not fall through to \$CACHE{BAR}")
endif()

# Test unsetting of CACHE entry.
unset(BAR CACHE)
if(DEFINED BAR)
  message(FATAL_ERROR "BAR still defined")
endif()

# Test unset(... PARENT_SCOPE)
function(unset_zots)
  if(NOT DEFINED ZOT1)
    message(FATAL_ERROR "ZOT1 is not defined inside function")
  endif()
  if(NOT DEFINED ZOT2)
    message(FATAL_ERROR "ZOT2 is not defined inside function")
  endif()
  unset(ZOT1)
  unset(ZOT2 PARENT_SCOPE)
  if(DEFINED ZOT1)
    message(FATAL_ERROR "ZOT1 is defined inside function after unset")
  endif()
  if(NOT DEFINED ZOT2)
    message(FATAL_ERROR
      "ZOT2 is not defined inside function after unset(... PARENT_SCOPE)")
  endif()
endfunction()
set(ZOT1 1)
set(ZOT2 2)
unset_zots()
if(NOT DEFINED ZOT1)
  message(FATAL_ERROR "ZOT1 is not still defined after function")
endif()
if(DEFINED ZOT2)
  message(FATAL_ERROR "ZOT2 is still defined after function unset PARENT_SCOPE")
endif()

add_executable(Unset unset.c)