diff options
author | Fabian Kosmale <fabian.kosmale@qt.io> | 2023-05-15 16:55:16 +0200 |
---|---|---|
committer | Fabian Kosmale <fabian.kosmale@qt.io> | 2023-05-16 13:50:52 +0200 |
commit | 4416a6bd4fb1cd1cb9d9225f3183431b37d6c948 (patch) | |
tree | 782d6a6c08f5f4c2ee13569176d3ec6c5be5d887 | |
parent | c2ae0350a741cb49879a15e23f178c7e392e1710 (diff) | |
download | qtdeclarative-4416a6bd4fb1cd1cb9d9225f3183431b37d6c948.tar.gz |
qt_add_qml_module: Set QT_QML_MODULE_QML_FILES correctly
A QML module might not actually contain any QML files at all (in case of
a pure C++ module). In such a case, we so far ended up with
QT_QML_MODULE_QML_FILES being set to "-NOTOUND", which later is
problematic for qt_query_qml_module.
We already have code in place to cover that issue for some variables,
just not for QML_FILES. The code is now amended to handle it, too.
Moreover, the code block is moved to the end of the function. This
ensures that the code for setting a variable always comes before the
code ensuring that it is set – which would not have been the case for
QML_FILES if it had stayed at its old position.
Pick-to: 6.5
Task-number: QTBUG-111946
Change-Id: Ib4501bb4a617b2174ad89e116588aa51353cb17f
Reviewed-by: Alexey Edelev <alexey.edelev@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
-rw-r--r-- | src/qml/Qt6QmlMacros.cmake | 32 | ||||
-rw-r--r-- | tests/auto/cmake/qmlquery/CMakeLists.txt | 1 | ||||
-rw-r--r-- | tests/auto/cmake/qmlquery/My/OtherThings/CMakeLists.txt | 28 | ||||
-rw-r--r-- | tests/auto/cmake/qmlquery/My/OtherThings/test.cpp | 3 | ||||
-rw-r--r-- | tests/auto/cmake/qmlquery/My/OtherThings/test.h | 18 |
5 files changed, 67 insertions, 15 deletions
diff --git a/src/qml/Qt6QmlMacros.cmake b/src/qml/Qt6QmlMacros.cmake index 4caaa888c1..f21c192732 100644 --- a/src/qml/Qt6QmlMacros.cmake +++ b/src/qml/Qt6QmlMacros.cmake @@ -532,21 +532,6 @@ Check https://doc.qt.io/qt-6/qt-cmake-policy-qtp0001.html for policy details." ) endif() - set(ensure_set_properties - QT_QML_MODULE_PLUGIN_TYPES_FILE - QT_QML_MODULE_RESOURCES # Original files as provided by the project (absolute) - QT_QML_MODULE_RESOURCE_PATHS # By qmlcachegen (resource paths) - QT_QMLCACHEGEN_DIRECT_CALLS - QT_QMLCACHEGEN_EXECUTABLE - QT_QMLCACHEGEN_ARGUMENTS - ) - foreach(prop IN LISTS ensure_set_properties) - get_target_property(val ${target} ${prop}) - if("${val}" MATCHES "-NOTFOUND$") - set_target_properties(${target} PROPERTIES ${prop} "") - endif() - endforeach() - if(NOT arg_NO_GENERATE_QMLTYPES) set(type_registration_extra_args "") if(arg_NAMESPACE) @@ -707,6 +692,23 @@ Check https://doc.qt.io/qt-6/qt-cmake-policy-qtp0001.html for policy details." set(${arg_OUTPUT_TARGETS} ${output_targets} PARENT_SCOPE) endif() + + set(ensure_set_properties + QT_QML_MODULE_PLUGIN_TYPES_FILE + QT_QML_MODULE_QML_FILES + QT_QML_MODULE_RESOURCES # Original files as provided by the project (absolute) + QT_QML_MODULE_RESOURCE_PATHS # By qmlcachegen (resource paths) + QT_QMLCACHEGEN_DIRECT_CALLS + QT_QMLCACHEGEN_EXECUTABLE + QT_QMLCACHEGEN_ARGUMENTS + ) + foreach(prop IN LISTS ensure_set_properties) + get_target_property(val ${target} ${prop}) + if("${val}" MATCHES "-NOTFOUND$") + set_target_properties(${target} PROPERTIES ${prop} "") + endif() + endforeach() + endfunction() if(NOT QT_NO_CREATE_VERSIONLESS_FUNCTIONS) diff --git a/tests/auto/cmake/qmlquery/CMakeLists.txt b/tests/auto/cmake/qmlquery/CMakeLists.txt index 5baac4f967..bafabe70f2 100644 --- a/tests/auto/cmake/qmlquery/CMakeLists.txt +++ b/tests/auto/cmake/qmlquery/CMakeLists.txt @@ -8,3 +8,4 @@ find_package(Qt6 REQUIRED COMPONENTS Qml) set(CMAKE_AUTOMOC TRUE) add_subdirectory(My/Things) +add_subdirectory(My/OtherThings) diff --git a/tests/auto/cmake/qmlquery/My/OtherThings/CMakeLists.txt b/tests/auto/cmake/qmlquery/My/OtherThings/CMakeLists.txt new file mode 100644 index 0000000000..5d2bbc4fdd --- /dev/null +++ b/tests/auto/cmake/qmlquery/My/OtherThings/CMakeLists.txt @@ -0,0 +1,28 @@ +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause + +qt_policy(SET QTP0001 NEW) + +function(verify_result keyword expected actual) + if(NOT "${actual}" STREQUAL "${expected}") + message(SEND_ERROR + " Expected ${keyword}: ${expected}\n" + " Actual ${keyword}: ${actual}" + ) + endif() +endfunction() + +qt_add_qml_module(MyOtherThings + URI My.OtherThings + SOURCES + test.h test.cpp +) + +qt_query_qml_module(MyOtherThings + QML_FILES qml_files2 + RESOURCES resources2 +) + +# empty resources and files +verify_result(RESOURCES "${resources2}" "") +verify_result(QML_FILES "${qml_files2}" "") diff --git a/tests/auto/cmake/qmlquery/My/OtherThings/test.cpp b/tests/auto/cmake/qmlquery/My/OtherThings/test.cpp new file mode 100644 index 0000000000..b9dde77775 --- /dev/null +++ b/tests/auto/cmake/qmlquery/My/OtherThings/test.cpp @@ -0,0 +1,3 @@ +#include "test.h" + +Test::Test() {} diff --git a/tests/auto/cmake/qmlquery/My/OtherThings/test.h b/tests/auto/cmake/qmlquery/My/OtherThings/test.h new file mode 100644 index 0000000000..274de043a1 --- /dev/null +++ b/tests/auto/cmake/qmlquery/My/OtherThings/test.h @@ -0,0 +1,18 @@ +// Copyright (C) 2023 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause + +#ifndef TEST_H +#define TEST_H + +#include <QtQml/qqml.h> +#include <QObject> + +class Test : public QObject +{ + Q_OBJECT + QML_ELEMENT +public: + Test(); +}; + +#endif // TEST_H |