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>
This commit is contained in:
parent
c2ae0350a7
commit
4416a6bd4f
|
@ -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)
|
||||
|
|
|
@ -8,3 +8,4 @@ find_package(Qt6 REQUIRED COMPONENTS Qml)
|
|||
set(CMAKE_AUTOMOC TRUE)
|
||||
|
||||
add_subdirectory(My/Things)
|
||||
add_subdirectory(My/OtherThings)
|
||||
|
|
|
@ -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}" "")
|
|
@ -0,0 +1,3 @@
|
|||
#include "test.h"
|
||||
|
||||
Test::Test() {}
|
|
@ -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
|
Loading…
Reference in New Issue