Debian Codegraph @

tests/auto/cmake/CMakeLists.txt

raw
1 # Copyright (C) 2022 The Qt Company Ltd.
2 # SPDX-License-Identifier: BSD-3-Clause
3
4 # This is an automatic test for the CMake configuration files.
5 # To run it manually,
6 # 1) mkdir build # Create a build directory
7 # 2) cd build
8 # 3) # Run cmake on this directory
9 # `$qt_prefix/bin/qt-cmake ..` or `cmake -DCMAKE_PREFIX_PATH=/path/to/qt ..`
10 # 4) ctest # Run ctest
11 # 5) ctest -V -R test_add_translation_macro # Run single test
12 #
13 # The expected output is something like:
14 #
15 # 1/2 Test #1: test_uiplugin_module ............. Passed 6.33 sec
16 # Start 4: test_uiplugin_via_designer
17 # 2/2 Test #2: test_uiplugin_via_designer ....... Passed 9.32 sec
18 #
19 #
20 # Note that if Qt is not installed, or if it is installed to a
21 # non-standard prefix, the environment variable CMAKE_PREFIX_PATH
22 # needs to be set to the installation prefix or build prefix of Qt
23 # before running these tests.
24
25 cmake_minimum_required(VERSION 3.16)
26
27 project(qttools_cmake_tests)
28
29 enable_testing()
30
31 set(required_packages Core)
32 set(optional_packages Widgets LinguistTools)
33
34 # Setup the test when called as a completely standalone project.
35 if(TARGET Qt6::Core)
36 # Tests are built as part of the qtbase build tree.
37 # Setup paths so that the Qt packages are found, similar to examples.
38 qt_internal_set_up_build_dir_package_paths()
39 endif()
40
41 find_package(Qt6 REQUIRED COMPONENTS ${required_packages})
42 find_package(Qt6 OPTIONAL_COMPONENTS ${optional_packages})
43
44 # Setup common test variables which were previously set by ctest_testcase_common.prf.
45 set(CMAKE_MODULES_UNDER_TEST "${required_packages}")
46 foreach(qt_package ${optional_packages})
47 set(package_name "${QT_CMAKE_EXPORT_NAMESPACE}${qt_package}")
48 list(APPEND CMAKE_MODULES_UNDER_TEST "${qt_package}")
49 endforeach()
50
51 foreach(qt_package ${CMAKE_MODULES_UNDER_TEST})
52 if(${package_name}_FOUND)
53 set(CMAKE_${qt_package}_MODULE_MAJOR_VERSION "${${package_name}_VERSION_MAJOR}")
54 set(CMAKE_${qt_package}_MODULE_MINOR_VERSION "${${package_name}_VERSION_MINOR}")
55 set(CMAKE_${qt_package}_MODULE_PATCH_VERSION "${${package_name}_VERSION_PATCH}")
56 endif()
57 endforeach()
58
59 include("${_Qt6CTestMacros}")
60
61 if (TARGET Qt6::Widgets)
62 _qt_internal_test_expect_pass(test_uiplugin_module)
63 _qt_internal_test_expect_pass(test_uiplugin_via_designer)
64 endif()
65
66 if(TARGET Qt6::lupdate)
67 add_subdirectory(linguist)
68 endif()