diff options
author | Arjen Hiemstra <ahiemstra@heimr.nl> | 2021-08-02 15:01:13 +0200 |
---|---|---|
committer | Arjen Hiemstra <ahiemstra@heimr.nl> | 2022-01-18 12:09:57 +0000 |
commit | 3813fd1bc97fa6bb2189cc9586f77be4c30478d6 (patch) | |
tree | a579dccf4ba1e0bccc58da42c3c39a97a569303b /tests | |
parent | f4049c5429afc3e195a60984922b7cb7276d908f (diff) | |
download | extra-cmake-modules-3813fd1bc97fa6bb2189cc9586f77be4c30478d6.tar.gz extra-cmake-modules-3813fd1bc97fa6bb2189cc9586f77be4c30478d6.tar.bz2 |
Introduce ECMQmlModule.cmake
This contains some helper functions to make it easier to create QML
modules through CMake. It takes care of several things that currently
need to be done manually.
It adds four tests for the four primary ways that it can be used,
either as shared/static library and with or without C++ plugin.
Diffstat (limited to 'tests')
-rw-r--r-- | tests/CMakeLists.txt | 44 | ||||
-rw-r--r-- | tests/ECMQmlModuleTest/CMakeLists.txt | 32 | ||||
-rw-r--r-- | tests/ECMQmlModuleTest/QmlModule.qml | 11 | ||||
-rw-r--r-- | tests/ECMQmlModuleTest/check.cmake.in | 64 | ||||
-rw-r--r-- | tests/ECMQmlModuleTest/qmldir_expected_depends | 6 | ||||
-rw-r--r-- | tests/ECMQmlModuleTest/qmldir_expected_depends.license | 2 | ||||
-rw-r--r-- | tests/ECMQmlModuleTest/qmldir_expected_full | 5 | ||||
-rw-r--r-- | tests/ECMQmlModuleTest/qmldir_expected_full.license | 2 | ||||
-rw-r--r-- | tests/ECMQmlModuleTest/qmldir_expected_qmlonly | 3 | ||||
-rw-r--r-- | tests/ECMQmlModuleTest/qmldir_expected_qmlonly.license | 2 | ||||
-rw-r--r-- | tests/ECMQmlModuleTest/qmlmodule.cpp | 14 | ||||
-rw-r--r-- | tests/ECMQmlModuleTest/qmlmodule.h | 21 |
12 files changed, 206 insertions, 0 deletions
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index b2143ec9..7ffcfd03 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -209,6 +209,50 @@ set_package_properties( ) if (TARGET Qt5::Quick) add_test_macro(ECMQMLModules dummy) + + set(ECMQmlModuleTest.static_full_EXTRA_OPTIONS + --build-target install + --build-options -DCMAKE_INSTALL_PREFIX:PATH=${CMAKE_CURRENT_BINARY_DIR}/ECMQmlModuleTest/static_full/install + -DBUILD_SHARED_LIBS=OFF + ) + add_test_variant(ECMQmlModuleTest.static_full ECMQmlModuleTest + ${CMAKE_COMMAND} -P "${CMAKE_CURRENT_BINARY_DIR}/ECMQmlModuleTest/static_full/check.cmake" + ) + set(ECMQmlModuleTest.shared_full_EXTRA_OPTIONS + --build-target install + --build-options -DCMAKE_INSTALL_PREFIX:PATH=${CMAKE_CURRENT_BINARY_DIR}/ECMQmlModuleTest/shared_full/install + -DBUILD_SHARED_LIBS=ON + ) + add_test_variant(ECMQmlModuleTest.shared_full ECMQmlModuleTest + ${CMAKE_COMMAND} -P "${CMAKE_CURRENT_BINARY_DIR}/ECMQmlModuleTest/shared_full/check.cmake" + ) + set(ECMQmlModuleTest.static_qmlonly_EXTRA_OPTIONS + --build-target install + --build-options -DCMAKE_INSTALL_PREFIX:PATH=${CMAKE_CURRENT_BINARY_DIR}/ECMQmlModuleTest/static_qmlonly/install + -DBUILD_SHARED_LIBS=OFF + -DQML_ONLY=ON + ) + add_test_variant(ECMQmlModuleTest.static_qmlonly ECMQmlModuleTest + ${CMAKE_COMMAND} -P "${CMAKE_CURRENT_BINARY_DIR}/ECMQmlModuleTest/static_qmlonly/check.cmake" + ) + set(ECMQmlModuleTest.shared_qmlonly_EXTRA_OPTIONS + --build-target install + --build-options -DCMAKE_INSTALL_PREFIX:PATH=${CMAKE_CURRENT_BINARY_DIR}/ECMQmlModuleTest/shared_qmlonly/install + -DBUILD_SHARED_LIBS=ON + -DQML_ONLY=ON + ) + add_test_variant(ECMQmlModuleTest.shared_qmlonly ECMQmlModuleTest + ${CMAKE_COMMAND} -P "${CMAKE_CURRENT_BINARY_DIR}/ECMQmlModuleTest/shared_qmlonly/check.cmake" + ) + set(ECMQmlModuleTest.shared_depends_EXTRA_OPTIONS + --build-target install + --build-options -DCMAKE_INSTALL_PREFIX:PATH=${CMAKE_CURRENT_BINARY_DIR}/ECMQmlModuleTest/shared_depends/install + -DBUILD_SHARED_LIBS=ON + -DDEPENDS=ON + ) + add_test_variant(ECMQmlModuleTest.shared_depends ECMQmlModuleTest + ${CMAKE_COMMAND} -P "${CMAKE_CURRENT_BINARY_DIR}/ECMQmlModuleTest/shared_depends/check.cmake" + ) endif() set(ECMConfiguredInstallTest_EXTRA_OPTIONS diff --git a/tests/ECMQmlModuleTest/CMakeLists.txt b/tests/ECMQmlModuleTest/CMakeLists.txt new file mode 100644 index 00000000..49d76594 --- /dev/null +++ b/tests/ECMQmlModuleTest/CMakeLists.txt @@ -0,0 +1,32 @@ +# +# SPDX-FileCopyrightText: 2021 Arjen Hiemstra <ahiemstra@heimr.nl> +# +# SPDX-License-Identifier: BSD-3-Clause + +project(extra-cmake-modules) +cmake_minimum_required(VERSION 3.5) + +set(ECM_MODULE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../../modules) +set(CMAKE_MODULE_PATH "${ECM_FIND_MODULE_DIR}" "${ECM_MODULE_DIR}") + +find_package(Qt5 REQUIRED COMPONENTS Qml) +include(ECMQmlModule) + +if(QML_ONLY) + ecm_add_qml_module(TestModule URI Test NO_PLUGIN) +else() + ecm_add_qml_module(TestModule URI Test) + target_sources(TestModule PRIVATE qmlmodule.cpp) + target_link_libraries(TestModule Qt5::Qml) +endif() + +if (DEPENDS) + ecm_add_qml_module_dependencies(TestModule DEPENDS OtherTest) +endif() + +ecm_target_qml_sources(TestModule SOURCES QmlModule.qml) + +ecm_finalize_qml_module(TestModule DESTINATION "test") + +# this will be run by CTest +configure_file(check.cmake.in "${CMAKE_CURRENT_BINARY_DIR}/check.cmake" @ONLY) diff --git a/tests/ECMQmlModuleTest/QmlModule.qml b/tests/ECMQmlModuleTest/QmlModule.qml new file mode 100644 index 00000000..ce16c9db --- /dev/null +++ b/tests/ECMQmlModuleTest/QmlModule.qml @@ -0,0 +1,11 @@ +/** + * SPDX-FileCopyrightText: 2021 Arjen Hiemstra <ahiemstra@heimr.nl> + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +import QtQuick 2.15 + +Item { + +} diff --git a/tests/ECMQmlModuleTest/check.cmake.in b/tests/ECMQmlModuleTest/check.cmake.in new file mode 100644 index 00000000..af64a120 --- /dev/null +++ b/tests/ECMQmlModuleTest/check.cmake.in @@ -0,0 +1,64 @@ +# +# SPDX-FileCopyrightText: 2021 Arjen Hiemstra <ahiemstra@heimr.nl> +# +# SPDX-License-Identifier: BSD-3-Clause + +set(SOURCE_DIR "@CMAKE_CURRENT_SOURCE_DIR@") +set(INSTALL_DIR "@CMAKE_INSTALL_PREFIX@/test") +set(SHARED "@BUILD_SHARED_LIBS@") +set(QML_ONLY "@QML_ONLY@") +set(DEPENDS "@DEPENDS@") + +function(check_file_exists file) + if (NOT EXISTS ${file}) + message(FATAL_ERROR "File \"${file}\" does not exist") + endif() +endfunction() + +function (check_file_contents) + cmake_parse_arguments(ARGS "" "GENERATED;EXPECTED" "" ${ARGN}) + + if (NOT EXISTS "${ARGS_GENERATED}") + message(FATAL_ERROR "${ARGS_GENERATED} was not generated") + endif() + file(READ "${ARGS_GENERATED}" generated_contents) + if (NOT EXISTS "${ARGS_EXPECTED}") + message(FATAL_ERROR "Original ${ARGS_EXPECTED} was not found") + endif() + file(READ "${ARGS_EXPECTED}" original_contents) + if (NOT "${generated_contents}" STREQUAL "${original_contents}") + message(FATAL_ERROR "${generated_file} contains '${generated_contents}' instead of '${original_contents}'") + endif() +endfunction() + +if (SHARED) + check_file_contents( + GENERATED "${INSTALL_DIR}/Test/QmlModule.qml" + EXPECTED "${SOURCE_DIR}/QmlModule.qml" + ) + + if (NOT QML_ONLY AND NOT DEPENDS) + check_file_exists("${INSTALL_DIR}/Test/libTestModule.so") + + check_file_contents( + GENERATED "${INSTALL_DIR}/Test/qmldir" + EXPECTED "${SOURCE_DIR}/qmldir_expected_full" + ) + endif() + + if (QML_ONLY AND NOT DEPENDS) + check_file_contents( + GENERATED "${INSTALL_DIR}/Test/qmldir" + EXPECTED "${SOURCE_DIR}/qmldir_expected_qmlonly" + ) + endif() + + if (DEPENDS) + check_file_contents( + GENERATED "${INSTALL_DIR}/Test/qmldir" + EXPECTED "${SOURCE_DIR}/qmldir_expected_depends" + ) + endif() +else() + check_file_exists("${INSTALL_DIR}/Test/libTestModule.a") +endif() diff --git a/tests/ECMQmlModuleTest/qmldir_expected_depends b/tests/ECMQmlModuleTest/qmldir_expected_depends new file mode 100644 index 00000000..2f373e2f --- /dev/null +++ b/tests/ECMQmlModuleTest/qmldir_expected_depends @@ -0,0 +1,6 @@ +# This file was automatically generated by ECMQmlModule and should not be modified +module Test +plugin TestModule +classname TestModule +depends OtherTest +QmlModule 1.0 QmlModule.qml diff --git a/tests/ECMQmlModuleTest/qmldir_expected_depends.license b/tests/ECMQmlModuleTest/qmldir_expected_depends.license new file mode 100644 index 00000000..8ebd85e2 --- /dev/null +++ b/tests/ECMQmlModuleTest/qmldir_expected_depends.license @@ -0,0 +1,2 @@ +SPDX-FileCopyrightText: 2021 Arjen Hiemstra <ahiemstra@heimr.nl> +SPDX-License-Identifier: CC0 diff --git a/tests/ECMQmlModuleTest/qmldir_expected_full b/tests/ECMQmlModuleTest/qmldir_expected_full new file mode 100644 index 00000000..9a13246c --- /dev/null +++ b/tests/ECMQmlModuleTest/qmldir_expected_full @@ -0,0 +1,5 @@ +# This file was automatically generated by ECMQmlModule and should not be modified +module Test +plugin TestModule +classname TestModule +QmlModule 1.0 QmlModule.qml diff --git a/tests/ECMQmlModuleTest/qmldir_expected_full.license b/tests/ECMQmlModuleTest/qmldir_expected_full.license new file mode 100644 index 00000000..8ebd85e2 --- /dev/null +++ b/tests/ECMQmlModuleTest/qmldir_expected_full.license @@ -0,0 +1,2 @@ +SPDX-FileCopyrightText: 2021 Arjen Hiemstra <ahiemstra@heimr.nl> +SPDX-License-Identifier: CC0 diff --git a/tests/ECMQmlModuleTest/qmldir_expected_qmlonly b/tests/ECMQmlModuleTest/qmldir_expected_qmlonly new file mode 100644 index 00000000..01823063 --- /dev/null +++ b/tests/ECMQmlModuleTest/qmldir_expected_qmlonly @@ -0,0 +1,3 @@ +# This file was automatically generated by ECMQmlModule and should not be modified +module Test +QmlModule 1.0 QmlModule.qml diff --git a/tests/ECMQmlModuleTest/qmldir_expected_qmlonly.license b/tests/ECMQmlModuleTest/qmldir_expected_qmlonly.license new file mode 100644 index 00000000..8ebd85e2 --- /dev/null +++ b/tests/ECMQmlModuleTest/qmldir_expected_qmlonly.license @@ -0,0 +1,2 @@ +SPDX-FileCopyrightText: 2021 Arjen Hiemstra <ahiemstra@heimr.nl> +SPDX-License-Identifier: CC0 diff --git a/tests/ECMQmlModuleTest/qmlmodule.cpp b/tests/ECMQmlModuleTest/qmlmodule.cpp new file mode 100644 index 00000000..a1552a86 --- /dev/null +++ b/tests/ECMQmlModuleTest/qmlmodule.cpp @@ -0,0 +1,14 @@ +/** + * SPDX-FileCopyrightText: 2021 Arjen Hiemstra <ahiemstra@heimr.nl> + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +#include "qmlmodule.h" + +#include <QtQml/QQmlEngine> + +void QmlModule::registerTypes(const char* uri) +{ + Q_ASSERT(QLatin1String(uri) == QLatin1String("Test")); +} diff --git a/tests/ECMQmlModuleTest/qmlmodule.h b/tests/ECMQmlModuleTest/qmlmodule.h new file mode 100644 index 00000000..49cd83a9 --- /dev/null +++ b/tests/ECMQmlModuleTest/qmlmodule.h @@ -0,0 +1,21 @@ +/** + * SPDX-FileCopyrightText: 2021 Arjen Hiemstra <ahiemstra@heimr.nl> + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +#ifndef QMLMODULE_H +#define QMLMODULE_H + +#include <QtQml/QQmlExtensionPlugin> + +class QmlModule : public QQmlExtensionPlugin +{ + Q_OBJECT + Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QQmlExtensionInterface") + +public: + void registerTypes(const char* uri) override; +}; + +#endif |