4040 endmacro ()
4141endif ()
4242
43- if (${CMAKE_VERSION } VERSION_GREATER_EQUAL "3.18 .0" )
43+ if (${CMAKE_VERSION } VERSION_GREATER_EQUAL "3.19 .0" )
4444 macro (rocm_defer FNAME )
45- cmake_language (DEFER DIRECTORY ${CMAKE_SOURCE_DIR } CALL ${FNAME} ())
45+ cmake_language (DEFER DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR } CALL ${FNAME} ())
4646 endmacro ()
4747else ()
4848 macro (rocm_defer FNAME )
@@ -55,6 +55,101 @@ else()
5555 endmacro ()
5656endif ()
5757
58+ function (rocm_test_property_names OUTPUT )
59+ set (${OUTPUT}
60+ ATTACHED_FILES
61+ ATTACHED_FILES_ON_FAIL
62+ COST
63+ DEPENDS
64+ DISABLED
65+ ENVIRONMENT
66+ ENVIRONMENT_MODIFICATION
67+ FAIL_REGULAR_EXPRESSION
68+ FIXTURES_CLEANUP
69+ FIXTURES_REQUIRED
70+ FIXTURES_SETUP
71+ LABELS
72+ MEASUREMENT
73+ PASS_REGULAR_EXPRESSION
74+ PROCESSOR_AFFINITY
75+ PROCESSORS
76+ REQUIRED_FILES
77+ RESOURCE_GROUPS
78+ RESOURCE_LOCK
79+ RUN_SERIAL
80+ SKIP_REGULAR_EXPRESSION
81+ SKIP_RETURN_CODE
82+ TIMEOUT
83+ TIMEOUT_AFTER_MATCH
84+ WILL_FAIL
85+ WORKING_DIRECTORY
86+ PARENT_SCOPE )
87+ endfunction ()
88+
89+ # Stashes the local tests' properties into directory-keyed globals so they can
90+ # be read from another scope before cmake 3.28. Runs in the test's own scope.
91+ function (rocm_test_collect_local_test_props )
92+ rocm_test_property_names (props )
93+ get_property (tests DIRECTORY PROPERTY TESTS)
94+ foreach (test IN LISTS tests)
95+ foreach (prop IN LISTS props)
96+ get_test_property (${test} ${prop} val)
97+ if (NOT val STREQUAL "NOTFOUND" )
98+ set_property (GLOBAL PROPERTY "_rocm_test_prop|${CMAKE_CURRENT_SOURCE_DIR } |${test} |${prop} " "${val} " )
99+ endif ()
100+ endforeach ()
101+ endforeach ()
102+ endfunction ()
103+
104+ # Schedules the collector once per directory (only needed before cmake 3.28).
105+ function (rocm_auto_register_test_props )
106+ if (CMAKE_VERSION VERSION_GREATER_EQUAL "3.28.0" )
107+ return ()
108+ endif ()
109+ get_property (scheduled DIRECTORY PROPERTY _rocm_test_props_collector_scheduled)
110+ if (NOT scheduled)
111+ set_property (DIRECTORY PROPERTY _rocm_test_props_collector_scheduled TRUE )
112+ rocm_defer (rocm_test_collect_local_test_props )
113+ endif ()
114+ endfunction ()
115+
116+ # get_test_property that also reads across directory scopes: built-in DIRECTORY
117+ # support on cmake 3.28+, otherwise the value rocm_test_collect_local_test_props
118+ # stashed for that directory.
119+ function (rocm_get_test_property )
120+ cmake_parse_arguments (ARG "" "DIRECTORY" "" ${ARGN} )
121+ list (LENGTH ARG_UNPARSED_ARGUMENTS _n)
122+ if (NOT _n EQUAL 3)
123+ message (FATAL_ERROR "rocm_get_test_property: expected <test> <property> [DIRECTORY <dir>] <out-var>" )
124+ endif ()
125+ list (GET ARG_UNPARSED_ARGUMENTS 0 _test)
126+ list (GET ARG_UNPARSED_ARGUMENTS 1 _prop)
127+ list (GET ARG_UNPARSED_ARGUMENTS 2 _out)
128+ if (NOT DEFINED ARG_DIRECTORY)
129+ get_test_property (${_test} ${_prop} _val)
130+ set (${_out} "${_val} " PARENT_SCOPE )
131+ return ()
132+ endif ()
133+ get_filename_component (_dir "${ARG_DIRECTORY} " ABSOLUTE )
134+ if (_dir STREQUAL CMAKE_CURRENT_SOURCE_DIR )
135+ get_test_property (${_test} ${_prop} _val)
136+ set (${_out} "${_val} " PARENT_SCOPE )
137+ return ()
138+ endif ()
139+ if (CMAKE_VERSION VERSION_GREATER_EQUAL "3.28.0" )
140+ get_property (_val TEST ${_test} DIRECTORY "${_dir} " PROPERTY ${_prop} )
141+ else ()
142+ set (_key "_rocm_test_prop|${_dir} |${_test} |${_prop} " )
143+ get_property (_set GLOBAL PROPERTY "${_key} " SET)
144+ if (_set)
145+ get_property (_val GLOBAL PROPERTY "${_key} " )
146+ else ()
147+ set (_val "NOTFOUND" )
148+ endif ()
149+ endif ()
150+ set (${_out} "${_val} " PARENT_SCOPE )
151+ endfunction ()
152+
58153function (rocm_find_program_version PROGRAM )
59154 set (options QUIET REQUIRED)
60155 set (oneValueArgs GREATER GREATER_EQUAL LESS LESS_EQUAL EQUAL OUTPUT_VARIABLE)
0 commit comments