@@ -71,6 +71,8 @@ function(add_qml_unittest PATH COMPONENT_NAME)
7171 ${ARGN}
7272 ARGS -input ${CMAKE_CURRENT_SOURCE_DIR}/${PATH}/tst_${COMPONENT_NAME}.qml ${QMLTEST_ARGS}
7373 )
74+
75+ install_qmltest("${PATH}" "${COMPONENT_NAME}")
7476endfunction()
7577
7678
@@ -91,6 +93,8 @@ function(add_manual_qml_test PATH COMPONENT_NAME)
9193 ${ARGN}
9294 ARGS ${CMAKE_CURRENT_SOURCE_DIR}/${PATH}/tst_${COMPONENT_NAME}.qml ${QMLTEST_ARGS}
9395 )
96+
97+ install_qmltest("${PATH}" "${COMPONENT_NAME}")
9498endfunction()
9599
96100
@@ -209,6 +213,67 @@ endfunction()
209213
210214################### INTERNAL ####################
211215
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+
229+function(add_test_target TARGET_NAME)
230+ cmake_parse_arguments(TEST "" "" "COMMAND;ENVIRONMENT;DEPENDS" ${ARGN})
231+
232+ add_custom_target(${TARGET_NAME}
233+ env ${TEST_ENVIRONMENT}
234+ ${TEST_COMMAND}
235+ DEPENDS ${TEST_DEPENDS}
236+ )
237+
238+ # Now write the above test into a shell script that we can run on an
239+ # installed system.
240+ set(script "#!/bin/sh\n\n")
241+ foreach(ONE_ENV ${TEST_ENVIRONMENT})
242+ set(script "${script}export ${ONE_ENV}\n")
243+ endforeach()
244+ set(script "${script}export UNITY_TESTING_DATADIR=\"${CMAKE_INSTALL_PREFIX}/${SHELL_APP_DIR}/\"\n")
245+ set(script "${script}\n")
246+ foreach(ONE_CMD ${TEST_COMMAND})
247+ if (NOT ONE_CMD MATCHES "\\$\\(")
248+ # skip variables that look like subcommands like $(FUNCTION)
249+ set(script "${script}'${ONE_CMD}' ")
250+ endif()
251+ endforeach()
252+ set(script "${script}$@")
253+
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}")
263+
264+ file(GENERATE
265+ OUTPUT "${CMAKE_BINARY_DIR}/tests/scripts/${TARGET_NAME}.sh"
266+ CONTENT "${script}"
267+ )
268+
269+ install(FILES "${CMAKE_BINARY_DIR}/tests/scripts/${TARGET_NAME}.sh"
270+ PERMISSIONS OWNER_EXECUTE OWNER_READ
271+ GROUP_EXECUTE GROUP_READ
272+ WORLD_EXECUTE WORLD_READ
273+ DESTINATION "${SHELL_PRIVATE_LIBDIR}/tests"
274+ )
275+endfunction()
276+
212277# add_qmltest_target(target_name target
213278# COMMAND test_exe [arg1 [...]] # execute this test with arguments
214279# [...] # see above for available arguments:
@@ -225,9 +290,9 @@ function(add_qmltest_target TARGET_NAME TARGET)
225290 set(function "$(FUNCTION)")
226291 endif()
227292
228− add_custom_target(${TARGET_NAME}
229− env ${QMLTEST_ENVIRONMENT}
230− ${QMLTEST_COMMAND} ${function}
293+ add_test_target(${TARGET_NAME}
294+ ENVIRONMENT ${QMLTEST_ENVIRONMENT}
295+ COMMAND ${QMLTEST_COMMAND} ${function}
231296 DEPENDS ${TARGET} ${QMLTEST_DEPENDS}
232297 )
233298