@@ -55,6 +55,45 @@ function(add_qml_test PATH COMPONENT_NAME)
5555endfunction()
5656
5757
58+# add_qml_test_data(path component_name
59+# [...]
60+# )
61+#
62+# Install file called ${component_name} (or ${component_name}.qml) under
63+# ${path}.
64+
65+function(add_qml_test_data PATH COMPONENT_NAME)
66+ set(filename "${CMAKE_CURRENT_SOURCE_DIR}/${PATH}/${COMPONENT_NAME}")
67+
68+ if (IS_DIRECTORY "${filename}")
69+ # As a convenience, allow specifying a directory and we will install
70+ # all files in the dir. We do it this way rather than passing
71+ # DIRECTORY to install() because we want to process any qml files.
72+ file(GLOB subfiles RELATIVE "${filename}" "${filename}/*")
73+ foreach(subfile ${subfiles})
74+ add_qml_test_data("${PATH}/${COMPONENT_NAME}" "${subfile}")
75+ endforeach()
76+ return()
77+ endif()
78+
79+ if (NOT EXISTS "${filename}")
80+ set(filename "${filename}.qml")
81+ set(COMPONENT_NAME "${COMPONENT_NAME}.qml")
82+ endif()
83+
84+ if ("${filename}" MATCHES "\\.qml$")
85+ file(READ "${filename}" contents)
86+ string(REGEX REPLACE "(\"[./]*/)qml/" "\\1" contents "${contents}")
87+ set(filename "${CMAKE_CURRENT_BINARY_DIR}/${PATH}/${COMPONENT_NAME}")
88+ file(WRITE "${filename}" "${contents}")
89+ endif()
90+
91+ install(FILES "${filename}"
92+ DESTINATION "${SHELL_APP_DIR}/tests/qmltests/${PATH}"
93+ )
94+endfunction()
95+
96+
5897# add_qml_unittest(path component_name
5998# [...]
6099# )
@@ -72,7 +111,9 @@ function(add_qml_unittest PATH COMPONENT_NAME)
72111 ARGS -input ${CMAKE_CURRENT_SOURCE_DIR}/${PATH}/tst_${COMPONENT_NAME}.qml ${QMLTEST_ARGS}
73112 )
74113
75− install_qmltest("${PATH}" "${COMPONENT_NAME}")
114+ if (EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${PATH}/tst_${COMPONENT_NAME}.qml")
115+ add_qml_test_data("${PATH}" "tst_${COMPONENT_NAME}.qml")
116+ endif()
76117endfunction()
77118
78119
@@ -94,7 +135,9 @@ function(add_manual_qml_test PATH COMPONENT_NAME)
94135 ARGS ${CMAKE_CURRENT_SOURCE_DIR}/${PATH}/tst_${COMPONENT_NAME}.qml ${QMLTEST_ARGS}
95136 )
96137
97− install_qmltest("${PATH}" "${COMPONENT_NAME}")
138+ if (EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${PATH}/tst_${COMPONENT_NAME}.qml")
139+ add_qml_test_data("${PATH}" "tst_${COMPONENT_NAME}.qml")
140+ endif()
98141endfunction()
99142
100143
@@ -213,19 +256,6 @@ endfunction()
213256
214257################### INTERNAL ####################
215258
216−function(install_qmltest PATH COMPONENT_NAME)
217− set(filename "${CMAKE_CURRENT_SOURCE_DIR}/${PATH}/tst_${COMPONENT_NAME}.qml")
218− set(out_filename "${CMAKE_CURRENT_BINARY_DIR}/${PATH}/tst_${COMPONENT_NAME}.qml")
219− if (EXISTS "${filename}")
220− file(READ "${filename}" contents)
221− string(REGEX REPLACE "(import \"[./]*)/qml" "\\1" contents "${contents}")
222− file(WRITE "${out_filename}" "${contents}")
223− install(FILES "${out_filename}"
224− DESTINATION "${SHELL_APP_DIR}/tests/qmltests/${PATH}"
225− )
226− endif()
227−endfunction()
228−
229259function(add_test_target TARGET_NAME)
230260 cmake_parse_arguments(TEST "" "" "COMMAND;ENVIRONMENT;DEPENDS" ${ARGN})
231261
@@ -241,7 +271,8 @@ function(add_test_target TARGET_NAME)
241271 foreach(ONE_ENV ${TEST_ENVIRONMENT})
242272 set(script "${script}export ${ONE_ENV}\n")
243273 endforeach()
244− set(script "${script}export UNITY_TESTING_DATADIR=\"${CMAKE_INSTALL_PREFIX}/${SHELL_APP_DIR}/\"\n")
274+ set(script "${script}export UNITY_TESTING_DATADIR=\"${CMAKE_INSTALL_PREFIX}/${SHELL_APP_DIR}\"\n")
275+ set(script "${script}export UNITY_TESTING_LIBDIR=\"${CMAKE_INSTALL_PREFIX}/${SHELL_PRIVATE_LIBDIR}\"\n")
245276 set(script "${script}\n")
246277 foreach(ONE_CMD ${TEST_COMMAND})
247278 if (NOT ONE_CMD MATCHES "\\$\\(")
@@ -251,26 +282,44 @@ function(add_test_target TARGET_NAME)
251282 endforeach()
252283 set(script "${script}$@")
253284
254− # Now some replacements...
255− # replace build/source roots with their install paths
256− string(REPLACE "${CMAKE_BINARY_DIR}/tests/mocks" "${CMAKE_INSTALL_PREFIX}/${SHELL_PRIVATE_LIBDIR}/qml/mocks" script "${script}")
257− string(REPLACE "${CMAKE_BINARY_DIR}/tests/uqmlscene" "${CMAKE_INSTALL_PREFIX}/${SHELL_PRIVATE_LIBDIR}" script "${script}")
258− string(REPLACE "${CMAKE_BINARY_DIR}/tests/utils/modules" "${CMAKE_INSTALL_PREFIX}/${SHELL_PRIVATE_LIBDIR}/qml/utils" script "${script}")
259− string(REPLACE "${CMAKE_BINARY_DIR}/plugins" "${CMAKE_INSTALL_PREFIX}/${SHELL_PRIVATE_LIBDIR}/qml" script "${script}")
260− string(REPLACE "${CMAKE_SOURCE_DIR}/tests/qmltests" "${CMAKE_INSTALL_PREFIX}/${SHELL_APP_DIR}/tests/qmltests" script "${script}")
261− # tests like to write xml output to our builddir; we don't need that
262− string(REGEX REPLACE "( '--parameter')? '-o'( '--parameter')? '[^ ]*,xunitxml' " " " script "${script}")
285+ set(filename "${CMAKE_BINARY_DIR}/tests/scripts/${TARGET_NAME}.sh")
263286
287+ # Generate script to file then read it back to resolve any generator
288+ # expressions before we try to replace paths.
264289 file(GENERATE
265− OUTPUT "${CMAKE_BINARY_DIR}/tests/scripts/${TARGET_NAME}.sh"
290+ OUTPUT "${filename}"
266291 CONTENT "${script}"
267292 )
268293
269− install(FILES "${CMAKE_BINARY_DIR}/tests/scripts/${TARGET_NAME}.sh"
294+ # Do replacement at install time to save needless work and to make sure
295+ # we are modifying file after generate step above (which doesn't happen
296+ # immediately). We can't use a custom-defined function or macro here...
297+ # So instead we use a giant ugly code block.
298+
299+ # START OF CODE BLOCK --------------------------------------------------
300+ install(CODE "
301+ file(READ \"${filename}\" replacestr)
302+
303+ # Now some replacements...
304+ # replace build/source roots with their install paths
305+ string(REPLACE \"${CMAKE_BINARY_DIR}/plugins\" \"${CMAKE_INSTALL_PREFIX}/${SHELL_INSTALL_QML}\" replacestr \"\${replacestr}\")
306+ string(REPLACE \"${CMAKE_BINARY_DIR}/tests/mocks\" \"${CMAKE_INSTALL_PREFIX}/${SHELL_INSTALL_QML}/mocks\" replacestr \"\${replacestr}\")
307+ string(REPLACE \"${CMAKE_BINARY_DIR}/tests/plugins\" \"${CMAKE_INSTALL_PREFIX}/${SHELL_PRIVATE_LIBDIR}/tests/plugins\" replacestr \"\${replacestr}\")
308+ string(REPLACE \"${CMAKE_BINARY_DIR}/tests/uqmlscene\" \"${CMAKE_INSTALL_PREFIX}/${SHELL_PRIVATE_LIBDIR}\" replacestr \"\${replacestr}\")
309+ string(REPLACE \"${CMAKE_BINARY_DIR}/tests/utils/modules\" \"${CMAKE_INSTALL_PREFIX}/${SHELL_INSTALL_QML}/utils\" replacestr \"\${replacestr}\")
310+ string(REPLACE \"${CMAKE_SOURCE_DIR}/tests/qmltests\" \"${CMAKE_INSTALL_PREFIX}/${SHELL_APP_DIR}/tests/qmltests\" replacestr \"\${replacestr}\")
311+ # tests like to write xml output to our builddir; we don't need that
312+ string(REGEX REPLACE \"( '--parameter')? '-o'( '--parameter')? '[^ ]*,xunitxml' \" \" \" replacestr \"\${replacestr}\")
313+
314+ file(WRITE \"${filename}\" \"\${replacestr}\")
315+ ")
316+ # END OF CODE BLOCK --------------------------------------------------
317+
318+ install(FILES "${filename}"
270319 PERMISSIONS OWNER_EXECUTE OWNER_READ
271320 GROUP_EXECUTE GROUP_READ
272321 WORLD_EXECUTE WORLD_READ
273− DESTINATION "${SHELL_PRIVATE_LIBDIR}/tests"
322+ DESTINATION "${SHELL_PRIVATE_LIBDIR}/tests/scripts"
274323 )
275324endfunction()
276325