CMake: Handle subdirectory test data installation

The qt_install() calls in qt_internal_add_test() did not re-create
subdirectories that are part of the input test data.

Make sure that the subdirectories are created upon installation by
ensuring we specify a relative installation path that includes all the
path parts except for the file name.
That works the same for directories.

Amends ec1546afc4a5e417d37c6a14e2909b063045bf39
Amends 540bd6cf203969363e641027b66fb044d9ccb1f6
Amends 1307736c7db1ff24e3b8282f4a7b14d24866feba
Amends 0a1256a52d8c6c1b85a10f7dc94dfc34e3540040

Task-number: QTBUG-117098
Change-Id: Ia80f4e7e1ec531264864bcde3ac192ce79b65746
Reviewed-by: Alexey Edelev <alexey.edelev@qt.io>
This commit is contained in:
Alexandru Croitor 2023-09-15 16:48:48 +02:00
parent 1d89f6602a
commit d3c6d40d5d

View File

@ -782,15 +782,27 @@ function(qt_internal_add_test name)
endif()
endif()
else()
# Install test data
file(RELATIVE_PATH relative_path_to_test_project
"${QT_TOP_LEVEL_SOURCE_DIR}"
"${CMAKE_CURRENT_SOURCE_DIR}")
qt_path_join(testdata_install_dir ${QT_INSTALL_DIR}
"${relative_path_to_test_project}")
if (testdata_install_dir)
# Install test data, when tests are built in-tree or as standalone tests, but not as a
# single standalone test, which is checked by the existence of the QT_TOP_LEVEL_SOURCE_DIR
# variable.
# TODO: Shouldn't we also handle the single standalone test case?
# TODO: Does installing even makes sense, given where QFINDTESTDATA looks for installed
# test data, and where we end up installing it? See QTBUG-117098.
if(QT_TOP_LEVEL_SOURCE_DIR)
foreach(testdata IN LISTS arg_TESTDATA)
set(testdata "${CMAKE_CURRENT_SOURCE_DIR}/${testdata}")
# Get the relative source dir for each test data entry, because it might contain a
# subdirectory.
file(RELATIVE_PATH relative_path_to_test_project
"${QT_TOP_LEVEL_SOURCE_DIR}"
"${testdata}")
get_filename_component(relative_path_to_test_project
"${relative_path_to_test_project}" DIRECTORY)
qt_path_join(testdata_install_dir ${QT_INSTALL_DIR}
"${relative_path_to_test_project}")
if (IS_DIRECTORY "${testdata}")
qt_install(
DIRECTORY "${testdata}"