aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/cmake/CMakeLists.txt
blob: 1dc26bbde9d51ca2f9a6b920ea0f1668dd80563f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# This is an automatic test for the CMake configuration files.
# To run it manually,
# 1) mkdir build   # Create a build directory
# 2) cd build
# 3) # Run cmake on this directory
#    `$qt_prefix/bin/qt-cmake ..` or `cmake -DCMAKE_PREFIX_PATH=/path/to/qt ..`
# 4) ctest         # Run ctest

cmake_minimum_required(VERSION 3.16)
project(qtdeclarative_cmake_tests)
enable_testing()

set(required_packages Core)
set(optional_packages Qml Quick)

# Setup the test when called as a completely standalone project.
if(TARGET Qt6::Core)
    # Tests are built as part of the qtsensors build tree.
    # Setup paths so that the Qt packages are found.
    qt_internal_set_up_build_dir_package_paths()
endif()

find_package(Qt6 REQUIRED COMPONENTS ${required_packages})
find_package(Qt6 OPTIONAL_COMPONENTS ${optional_packages})

# Setup common test variables which were previously set by ctest_testcase_common.prf.
set(CMAKE_MODULES_UNDER_TEST "${required_packages}" "${optional_packages}")

foreach(qt_package ${CMAKE_MODULES_UNDER_TEST})
    set(package_name "${QT_CMAKE_EXPORT_NAMESPACE}${qt_package}")
    if(${package_name}_FOUND)
        set(CMAKE_${qt_package}_MODULE_MAJOR_VERSION "${${package_name}_VERSION_MAJOR}")
        set(CMAKE_${qt_package}_MODULE_MINOR_VERSION "${${package_name}_VERSION_MINOR}")
        set(CMAKE_${qt_package}_MODULE_PATCH_VERSION "${${package_name}_VERSION_PATCH}")
    endif()
endforeach()

include("${_Qt6CTestMacros}")

set(module_includes "")

if(TARGET Qt::Qml)
    list(APPEND module_includes
        Qml QQmlEngine
    )
endif()

if(TARGET Qt::Quick)
    list(APPEND module_includes
        Quick QQuickWindow
    )
endif()

_qt_internal_test_module_includes(${module_includes})

if(TARGET Qt::Qml)
    if(NOT CMAKE_CROSSCOMPILING)
        _qt_internal_test_expect_pass(tooling_imports TESTNAME cmake_tooling_imports BINARY cmake_test)
        set_tests_properties(cmake_tooling_imports PROPERTIES
            FAIL_REGULAR_EXPRESSION "(Info|Warning|Error): [a-zA-Z]*\\.qml:[0-9]"
        )
    endif()
    # TODO: Plugin targets are not available in shared builds at the moment QTBUG-94066
    if(NOT QT6_IS_SHARED_LIBS_BUILD)
        _qt_internal_test_expect_pass(test_plugins)
    endif()
    _qt_internal_test_expect_pass(empty_qmldir)
    If(NOT ANDROID) # QML only project cannot run on Android with C++ enty point
        _qt_internal_test_expect_pass(qmlquery)
    endif()
endif()

if(TARGET Qt::Quick)
    if(NOT CMAKE_CROSSCOMPILING)
        _qt_internal_test_expect_pass(qtquickcompiler BINARY qqc_test)
    endif()
    if(NOT QT6_IS_SHARED_LIBS_BUILD)
        _qt_internal_test_expect_pass(test_import_static_shapes_plugin_resources
            BINARY "${CMAKE_CTEST_COMMAND}"
            BINARY_ARGS "-V"
        )
        if(CMAKE_VERSION VERSION_GREATER_EQUAL "3.21")
            _qt_internal_test_expect_pass(qmlimportscanner
                TESTNAME cmake_qmlimportscanner
                BINARY qis_test
            )
        endif()
    endif()

    set(deploy_args
        test_qml_app_deployment
        BINARY "${CMAKE_CTEST_COMMAND}"
        BINARY_ARGS "-V"
        # Need to explicitly specify a writable install prefix.
        BUILD_OPTIONS
            -DCMAKE_INSTALL_PREFIX=${CMAKE_CURRENT_BINARY_DIR}/test_qml_app_deployment_installed
    )

    # For now, the test should only pass on Windows and macOS shared and static builds and fail on
    # other platforms, because there is no support for runtime dependency deployment
    # on those platforms.
    # With static builds the runtime dependencies are just skipped, but the test should
    # still pass.
    if((WIN32 OR (APPLE AND NOT IOS)))
        _qt_internal_test_expect_pass(${deploy_args})
    else()
        _qt_internal_test_expect_fail(${deploy_args})
    endif()
endif()