summaryrefslogtreecommitdiffstats
path: root/Tests/RunCMake/define_property/define_property-redefine.cmake
blob: b0b5e95e7fe7f48da0a9272a1d224869cf9e8df4 (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
function(verify_value type prop attrib expected actual)
  if(expected STREQUAL "FALSE")
    if(actual)
      message(FATAL_ERROR
        "Expected ${type} property ${prop}'s ${attrib} to be false")
    endif()
  elseif(expected STREQUAL "TRUE")
    if(NOT actual)
      message(FATAL_ERROR
        "Expected ${type} property ${prop}'s ${attrib} to be true")
    endif()
  elseif(NOT actual STREQUAL expected)
    message(FATAL_ERROR
      "Expected value of ${type} property ${prop}'s ${attrib}:\n"
      "  ${expected}\n"
      "Actual value:\n"
      "  ${actual}"
    )
  endif()
endfunction()

function(assert_tgt_prop_attrib_eq prop attrib expected)
  get_property(actual TARGET NONE PROPERTY "${prop}" "${attrib}")
  verify_value(TARGET "${prop}" "${attrib}" "${expected}" "${actual}")
endfunction()

function(assert_dir_prop_attrib_eq prop attrib expected)
  get_property(actual DIRECTORY "" PROPERTY "${prop}" "${attrib}")
  verify_value(DIRECTORY "${prop}" "${attrib}" "${expected}" "${actual}")
endfunction()

#
# TESTS
#

# Define a new target property
message(CHECK_START "Testing define_property(TARGET ...)")
define_property(TARGET PROPERTY TGT1
  BRIEF_DOCS "Brief")
assert_tgt_prop_attrib_eq(TGT1 BRIEF_DOCS "Brief")
assert_tgt_prop_attrib_eq(TGT1 FULL_DOCS "NOTFOUND")
message(CHECK_PASS "Complete")

# Attempt to redefine with different/additional attributes
message(CHECK_START "Testing TARGET property redefinition")
define_property(TARGET PROPERTY TGT1
  BRIEF_DOCS "Changed"
  FULL_DOCS "Full")
assert_tgt_prop_attrib_eq(TGT1 BRIEF_DOCS "Brief")
assert_tgt_prop_attrib_eq(TGT1 FULL_DOCS "NOTFOUND")
message(CHECK_PASS "Complete")

# Query undefined property
message(CHECK_START "Testing undefined TARGET property query")
assert_tgt_prop_attrib_eq(TGT2 DEFINED FALSE)
assert_tgt_prop_attrib_eq(TGT2 BRIEF_DOCS "NOTFOUND")
message(CHECK_PASS "Complete")

# Define after query
message(CHECK_START "Testing TARGET property definition after query")
define_property(TARGET PROPERTY TGT2
  BRIEF_DOCS "Brief"
  FULL_DOCS "Full"
)
assert_tgt_prop_attrib_eq(TGT2 DEFINED TRUE)
assert_tgt_prop_attrib_eq(TGT2 BRIEF_DOCS "Brief")
assert_tgt_prop_attrib_eq(TGT2 FULL_DOCS "Full")
message(CHECK_PASS "Complete")

# Define a new directory property
message(CHECK_START "Testing define_property(DIRECTORY ...)")
define_property(DIRECTORY PROPERTY DIR1
  BRIEF_DOCS "Brief"
  FULL_DOCS "Full"
)
assert_dir_prop_attrib_eq(DIR1 DEFINED TRUE)
assert_dir_prop_attrib_eq(DIR1 BRIEF_DOCS "Brief")
assert_dir_prop_attrib_eq(DIR1 FULL_DOCS "Full")
message(CHECK_PASS "Complete")

# Attempt to redefine existing attributes
message(CHECK_START "Testing DIRECTORY property redefinition")
define_property(DIRECTORY PROPERTY DIR1
  BRIEF_DOCS "Overwritten"
)
assert_dir_prop_attrib_eq(DIR1 BRIEF_DOCS "Brief")
assert_dir_prop_attrib_eq(DIR1 FULL_DOCS "Full")
message(CHECK_PASS "Complete")