diff options
author | Ulf Hermann <ulf.hermann@qt.io> | 2022-04-27 15:39:54 +0200 |
---|---|---|
committer | Ulf Hermann <ulf.hermann@qt.io> | 2022-06-16 13:32:40 +0200 |
commit | 89b62c13b54d5b27f5c1981411e9e82e0441f64e (patch) | |
tree | 4b5ccb6fbd5409b57f3da7724a8c557c0abac128 /tests/auto/cmake | |
parent | 175dfd25c25fedee490c0578d34c2467cef83b00 (diff) |
CMake: Automatically find import path a module belongs to
If the output directory ends in the URI of the module converted to a
path, we can be pretty sure that the base directory is meant to be an
import path. Just add that automatically.
Fixes: QTBUG-101220
Change-Id: I83117d8997f3213356d5bf1d5b04c4ed377f90f7
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Reviewed-by: Maximilian Goldstein <max.goldstein@qt.io>
Reviewed-by: Andrei Golubev <andrei.golubev@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Diffstat (limited to 'tests/auto/cmake')
10 files changed, 162 insertions, 0 deletions
diff --git a/tests/auto/cmake/CMakeLists.txt b/tests/auto/cmake/CMakeLists.txt index 1dc26bbde9..45b753b897 100644 --- a/tests/auto/cmake/CMakeLists.txt +++ b/tests/auto/cmake/CMakeLists.txt @@ -73,6 +73,12 @@ endif() if(TARGET Qt::Quick) if(NOT CMAKE_CROSSCOMPILING) _qt_internal_test_expect_pass(qtquickcompiler BINARY qqc_test) + if(CMAKE_VERSION VERSION_GREATER_EQUAL "3.21") + _qt_internal_test_expect_pass(test_common_import_path + TESTNAME cmake_test_common_import_path + BINARY cmake_test + ) + endif() endif() if(NOT QT6_IS_SHARED_LIBS_BUILD) _qt_internal_test_expect_pass(test_import_static_shapes_plugin_resources diff --git a/tests/auto/cmake/test_common_import_path/CMakeLists.txt b/tests/auto/cmake/test_common_import_path/CMakeLists.txt new file mode 100644 index 0000000000..f79997e06c --- /dev/null +++ b/tests/auto/cmake/test_common_import_path/CMakeLists.txt @@ -0,0 +1,28 @@ +cmake_minimum_required(VERSION 3.16) + +project(cmake_test) + +find_package(Qt6 ${CMAKE_Core_MODULE_MAJOR_VERSION}.${CMAKE_Core_MODULE_MINOR_VERSION} + REQUIRED COMPONENTS Qml Quick Test) + +set(CMAKE_AUTOMOC ON) + +# Simplify finding the backing targets' DLLs on Windows +if(WIN32) + set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) +endif() + +add_subdirectory(duck/tick) +add_subdirectory(duck/trick) +add_subdirectory(duck/track) + +qt_add_executable(cmake_test main.cpp) +target_link_libraries(cmake_test + PRIVATE Qt6::Quick Qt6::Test Qt6::Gui duck_tickplugin duck_trickplugin duck_trackplugin) + +qt_add_qml_module(cmake_test + URI duck + VERSION 1.0 + QML_FILES main.qml +) + diff --git a/tests/auto/cmake/test_common_import_path/duck/tick/CMakeLists.txt b/tests/auto/cmake/test_common_import_path/duck/tick/CMakeLists.txt new file mode 100644 index 0000000000..8ed7872a5f --- /dev/null +++ b/tests/auto/cmake/test_common_import_path/duck/tick/CMakeLists.txt @@ -0,0 +1,9 @@ +qt_add_library(duck_tick STATIC) + +qt_add_qml_module(duck_tick + URI duck.tick + VERSION 1.0 + QML_FILES + Tick.qml +) + diff --git a/tests/auto/cmake/test_common_import_path/duck/tick/Tick.qml b/tests/auto/cmake/test_common_import_path/duck/tick/Tick.qml new file mode 100644 index 0000000000..facb37f89e --- /dev/null +++ b/tests/auto/cmake/test_common_import_path/duck/tick/Tick.qml @@ -0,0 +1,7 @@ +pragma Strict + +import QtQuick + +Rectangle { + x: 2 + 3 +} diff --git a/tests/auto/cmake/test_common_import_path/duck/track/CMakeLists.txt b/tests/auto/cmake/test_common_import_path/duck/track/CMakeLists.txt new file mode 100644 index 0000000000..845f2f4f80 --- /dev/null +++ b/tests/auto/cmake/test_common_import_path/duck/track/CMakeLists.txt @@ -0,0 +1,10 @@ +qt_add_library(duck_track STATIC) + +qt_add_qml_module(duck_track + URI duck.track + VERSION 1.0 + QML_FILES + Track.qml +) + +add_dependencies(duck_track duck_trick) diff --git a/tests/auto/cmake/test_common_import_path/duck/track/Track.qml b/tests/auto/cmake/test_common_import_path/duck/track/Track.qml new file mode 100644 index 0000000000..d0a3ef2fd8 --- /dev/null +++ b/tests/auto/cmake/test_common_import_path/duck/track/Track.qml @@ -0,0 +1,8 @@ +pragma Strict + +import QtQuick +import duck.trick + +Trick { + x: 5 + 5 +} diff --git a/tests/auto/cmake/test_common_import_path/duck/trick/CMakeLists.txt b/tests/auto/cmake/test_common_import_path/duck/trick/CMakeLists.txt new file mode 100644 index 0000000000..b3f7c5e707 --- /dev/null +++ b/tests/auto/cmake/test_common_import_path/duck/trick/CMakeLists.txt @@ -0,0 +1,9 @@ +qt_add_library(duck_trick STATIC) + +qt_add_qml_module(duck_trick + URI duck.trick + VERSION 1.0 + QML_FILES + Trick.qml +) + diff --git a/tests/auto/cmake/test_common_import_path/duck/trick/Trick.qml b/tests/auto/cmake/test_common_import_path/duck/trick/Trick.qml new file mode 100644 index 0000000000..b8dec05d24 --- /dev/null +++ b/tests/auto/cmake/test_common_import_path/duck/trick/Trick.qml @@ -0,0 +1,7 @@ +pragma Strict + +import QtQuick + +Rectangle { + x: 7 + 8 +} diff --git a/tests/auto/cmake/test_common_import_path/main.cpp b/tests/auto/cmake/test_common_import_path/main.cpp new file mode 100644 index 0000000000..bc8a442822 --- /dev/null +++ b/tests/auto/cmake/test_common_import_path/main.cpp @@ -0,0 +1,60 @@ +/**************************************************************************** +** +** Copyright (C) 2022 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:GPL-EXCEPT$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 as published by the Free Software +** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + + +#include <QtQml/qqmlengine.h> +#include <QtQml/qqmlcomponent.h> +#include <QtQml/qqmlextensionplugin.h> +#include <QtTest> + +Q_IMPORT_QML_PLUGIN(duck_tickPlugin) +Q_IMPORT_QML_PLUGIN(duck_trickPlugin) +Q_IMPORT_QML_PLUGIN(duck_trackPlugin) + +class test : public QObject +{ + Q_OBJECT +private slots: + void test_loadable(); +}; + +void test::test_loadable() +{ + QQmlEngine engine; + engine.addImportPath(QStringLiteral(":/")); + QQmlComponent c(&engine, QUrl(u"qrc:/duck/main.qml"_qs)); + QVERIFY2(c.isReady(), qPrintable(c.errorString())); + QScopedPointer<QObject> o(c.create()); + QVERIFY(!o.isNull()); + QCOMPARE(o->property("x1").toInt(), 5); + QCOMPARE(o->property("x2").toInt(), 10); +} + +QTEST_MAIN(test) + +#include "main.moc" diff --git a/tests/auto/cmake/test_common_import_path/main.qml b/tests/auto/cmake/test_common_import_path/main.qml new file mode 100644 index 0000000000..6a42a5206e --- /dev/null +++ b/tests/auto/cmake/test_common_import_path/main.qml @@ -0,0 +1,18 @@ +pragma Strict + +import QtQuick +import duck.tick +import duck.track + +Item { + property int x1: tick.x + property int x2: track.x + + Tick { + id: tick + } + + Track { + id: track + } +} |