-
Notifications
You must be signed in to change notification settings - Fork 65
/
Copy pathtest_set_property.cmake
70 lines (59 loc) · 2.75 KB
/
test_set_property.cmake
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
# Blog: https://blog.csdn.net/fengbingchun/article/details/128257921
message("#### test_${TEST_CMAKE_FEATURE}.cmake ####")
# reference: https://github.com/Kitware/CMake/blob/master/Tests/Properties/CMakeLists.txt
get_property(GLOBALRESULT GLOBAL PROPERTY GLOBALTEST DEFINED)
if(GLOBALRESULT)
message(SEND_ERROR "Error: global prop defined when it should not be, result is GLOBALRESULT=${GLOBALRESULT}")
endif()
define_property(GLOBAL PROPERTY GLOBALTEST
BRIEF_DOCS "A test property"
FULL_DOCS "A long description of this test property"
)
get_property(GLOBALRESULT GLOBAL PROPERTY GLOBALTEST DEFINED)
if(NOT GLOBALRESULT)
message(SEND_ERROR "Error: global prop not defined, result is GLOBALRESULT=${GLOBALRESULT}")
endif()
set_property(GLOBAL PROPERTY GLOBALTEST 1)
set_property(DIRECTORY PROPERTY DIRECTORYTEST 1)
set_property(SOURCE source/add.cpp PROPERTY SOURCETEST 1)
get_property(GLOBALRESULT GLOBAL PROPERTY GLOBALTEST)
get_property(DIRECTORYRESULT DIRECTORY PROPERTY DIRECTORYTEST)
get_property(SOURCERESULT SOURCE source/add.cpp PROPERTY SOURCETEST)
if(NOT (GLOBALRESULT AND DIRECTORYRESULT AND SOURCERESULT))
message(SEND_ERROR "Error: test results are "
"GLOBALRESULT=${GLOBALRESULT} "
"DIRECTORYRESULT=${DIRECTORYRESULT} "
"SOURCERESULT=${SOURCERESULT}")
endif()
# test the target property
include_directories(include)
add_library(Properties source/add.cpp)
set_property(TARGET Properties PROPERTY TARGETTEST 1)
get_property(TARGETRESULT TARGET Properties PROPERTY TARGETTEST)
if(NOT TARGETRESULT)
message(SEND_ERROR "Error: target result is TARGETRESULT=${TARGETRESULT}")
endif()
# test APPEND and APPEND_STRING set_property()
set_property(TARGET Properties PROPERTY FOO foo)
set_property(TARGET Properties PROPERTY BAR bar)
set_property(TARGET Properties APPEND PROPERTY FOO 123)
set_property(TARGET Properties APPEND_STRING PROPERTY BAR 456)
get_property(APPEND_RESULT TARGET Properties PROPERTY FOO)
if(NOT "${APPEND_RESULT}" STREQUAL "foo;123")
message(SEND_ERROR "Error: target result is APPEND_RESULT=${APPEND_RESULT}")
endif()
get_property(APPEND_STRING_RESULT TARGET Properties PROPERTY BAR)
if(NOT "${APPEND_STRING_RESULT}" STREQUAL "bar456")
message(SEND_ERROR "Error: target result is APPEND_STRING_RESULT=${APPEND_STRING_RESULT}")
endif()
# test get_property SET
get_property(TARGETRESULT TARGET Properties PROPERTY TARGETTEST SET)
if(NOT TARGETRESULT)
message(SEND_ERROR "Error: target prop not set, result is TARGETRESULT=${TARGETRESULT}")
endif()
# test unsetting a property
set_property(TARGET Properties PROPERTY TARGETTEST)
get_property(TARGETRESULT TARGET Properties PROPERTY TARGETTEST SET)
if(TARGETRESULT)
message(SEND_ERROR "Error: target prop not unset, result is TARGETRESULT=${TARGETRESULT}")
endif()