1 # a simple CXX only test case
2 cmake_minimum_required (VERSION 2.6)
5 # these first three tests really test both properties and the management of
6 # cmSourceFile objects by CMake.
8 # test properties on a build tree file that is relative (yuck)
9 configure_file(properties.h.in "${Properties_BINARY_DIR}/properties.h")
10 set_source_files_properties(properties.h PROPERTIES TEST1 1)
11 get_source_file_property(RESULT1 properties.h TEST1)
13 # test properties on a headerfile in the source tree
14 # accessed without an extenion (also yuck)
15 set_source_files_properties(properties2 PROPERTIES TEST2 1)
16 get_source_file_property(RESULT2 properties2 TEST2)
18 # test properties on a relative source that is not generated
19 set_source_files_properties(SubDir/properties3.cxx PROPERTIES TEST3 1)
20 get_source_file_property(RESULT3 SubDir/properties3.cxx TEST3)
22 include_directories("${Properties_SOURCE_DIR}" "${Properties_BINARY_DIR}")
25 # test generic property interfaces
26 get_property(GLOBALRESULT GLOBAL PROPERTY GLOBALTEST DEFINED)
28 message(SEND_ERROR "Error: global prop defined when it should not be, "
29 "result is GLOBALRESULT=${GLOBALRESULT}")
32 define_property(GLOBAL PROPERTY GLOBALTEST
33 BRIEF_DOCS "A test property"
34 FULL_DOCS "A long description of this test property"
37 get_property(GLOBALRESULT GLOBAL PROPERTY GLOBALTEST DEFINED)
39 message(SEND_ERROR "Error: global prop not defined "
40 "result is GLOBALRESULT=${GLOBALRESULT}")
41 endif (NOT GLOBALRESULT)
43 set_property(GLOBAL PROPERTY GLOBALTEST 1)
44 set_property(DIRECTORY PROPERTY DIRECTORYTEST 1)
45 set_property(SOURCE SubDir/properties3.cxx PROPERTY SOURCETEST 1)
46 get_property(GLOBALRESULT GLOBAL PROPERTY GLOBALTEST)
47 get_property(DIRECTORYRESULT DIRECTORY PROPERTY DIRECTORYTEST)
48 get_property(SOURCERESULT
49 SOURCE SubDir/properties3.cxx
53 if (RESULT1 AND RESULT2 AND RESULT3 AND GLOBALRESULT AND
54 DIRECTORYRESULT AND SOURCERESULT)
55 add_executable (Properties SubDir/properties3.cxx properties)
56 else (RESULT1 AND RESULT2 AND RESULT3 AND GLOBALRESULT AND
57 DIRECTORYRESULT AND SOURCERESULT)
59 "Error: test results are RESULT1=${RESULT1} RESULT2=${RESULT2} "
60 "RESULT3=${RESULT3} GLOBALRESULT=${GLOBALRESULT} "
61 "DIRECTORYRESULT=${DIRECTORYRESULT} "
62 "SOURCERESULT=${SOURCERESULT}")
63 endif (RESULT1 AND RESULT2 AND RESULT3 AND GLOBALRESULT AND
64 DIRECTORYRESULT AND SOURCERESULT)
66 # test the target property
67 set_property(TARGET Properties PROPERTY TARGETTEST 1)
68 get_property(TARGETRESULT TARGET Properties PROPERTY TARGETTEST)
71 "Error: target result is TARGETRESULT=${TARGETRESULT}")
72 endif (NOT TARGETRESULT)
74 # test get_property SET
75 get_property(TARGETRESULT TARGET Properties PROPERTY TARGETTEST SET)
78 "Error: target prop not set, result is TARGETRESULT=${TARGETRESULT}")
79 endif (NOT TARGETRESULT)
81 # test unsetting a property
82 set_property(TARGET Properties PROPERTY TARGETTEST)
83 get_property(TARGETRESULT TARGET Properties PROPERTY TARGETTEST SET)
85 message(SEND_ERROR "Error: target prop not unset, "
86 "result is TARGETRESULT=${TARGETRESULT}")
91 # test the target SOURCES property
92 get_property(Properties_SOURCES TARGET Properties PROPERTY SOURCES)
93 set_source_files_properties(${Properties_SOURCES} PROPERTIES TEST4 1)
94 get_source_file_property(RESULT4 properties.h TEST4)
96 message(SEND_ERROR "Error: target result is"
98 " Properties_SOURCES=[${Properties_SOURCES}]")
101 # test CACHE properties
102 macro(check_cache_props)
103 foreach(prop VALUE TYPE HELPSTRING ADVANCED)
104 get_property(result CACHE SOME_ENTRY PROPERTY ${prop})
105 if(NOT "x${result}" STREQUAL "x${expect_${prop}}")
106 message(SEND_ERROR "CACHE property ${prop} is [${result}], not [${expect_${prop}}]")
109 endmacro(check_cache_props)
110 set(expect_VALUE "ON")
111 set(expect_TYPE "BOOL")
112 set(expect_HELPSTRING "sample cache entry")
113 set(expect_ADVANCED 0)
114 set(SOME_ENTRY "${expect_VALUE}" CACHE ${expect_TYPE} "${expect_HELPSTRING}" FORCE)
115 mark_as_advanced(CLEAR SOME_ENTRY)
117 set(expect_VALUE "Some string")
118 set(expect_TYPE "STRING")
119 set(expect_HELPSTRING "sample cache entry help")
120 set(expect_ADVANCED 1)
121 set_property(CACHE SOME_ENTRY PROPERTY TYPE "${expect_TYPE}")
122 set_property(CACHE SOME_ENTRY PROPERTY HELPSTRING "${expect_HELPSTRING}")
123 set_property(CACHE SOME_ENTRY PROPERTY VALUE "${expect_VALUE}")
124 set_property(CACHE SOME_ENTRY PROPERTY ADVANCED "${expect_ADVANCED}")