aboutsummaryrefslogtreecommitdiff
path: root/tests/ECMQmlModuleTest/check.cmake.in
diff options
context:
space:
mode:
authorArjen Hiemstra <ahiemstra@heimr.nl>2021-08-02 15:01:13 +0200
committerArjen Hiemstra <ahiemstra@heimr.nl>2022-01-18 12:09:57 +0000
commit3813fd1bc97fa6bb2189cc9586f77be4c30478d6 (patch)
treea579dccf4ba1e0bccc58da42c3c39a97a569303b /tests/ECMQmlModuleTest/check.cmake.in
parentf4049c5429afc3e195a60984922b7cb7276d908f (diff)
downloadextra-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/ECMQmlModuleTest/check.cmake.in')
-rw-r--r--tests/ECMQmlModuleTest/check.cmake.in64
1 files changed, 64 insertions, 0 deletions
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()