Debian Codegraph @

tests/auto/cmake/test_qt_add_ui_5/CMakeLists.txt

raw
1 # Copyright (C) 2024 The Qt Company Ltd.
2 # SPDX-License-Identifier: BSD-3-Clause
3
4 cmake_minimum_required(VERSION 3.16)
5 project(test)
6
7 include(../test_qt_add_ui_common/RunCMake.cmake)
8 include(../test_qt_add_ui_common/functions.cmake)
9
10 get_generators(generators)
11
12 foreach(generator IN ITEMS ${generators})
13 message(STATUS "Running tests for generator: ${generator}")
14 is_multi_config(${generator} multi_config_out)
15 if(multi_config_out)
16 set(configs "Debug" "Release")
17 else()
18 set(configs "single_config")
19 endif()
20
21 foreach(config IN ITEMS ${configs})
22 if("${config}" STREQUAL "single_config")
23 set(config_path "")
24 set(config_arg "")
25 else()
26 set(config_path "_${config}")
27 set(config_arg "${config}")
28 endif()
29
30
31 if("${generator}" MATCHES "Ninja")
32 # Test case: Add a new ui file to CMakeLists.txt after the first
33 # build.
34 # Expect 1: Expect ${target}_autogen/prefix_info.cmake to be
35 # generated as expected.
36 string(CONCAT test_source_dir "${CMAKE_CURRENT_SOURCE_DIR}/../"
37 "test_qt_add_ui_common/uic_test")
38 string(CONCAT test_build_dir "${CMAKE_CURRENT_BINARY_DIR}/"
39 "uic_prefix_info_cmake_test${config_path}-build")
40 run_cmake_configure(SOURCE_DIR "${test_source_dir}"
41 BUILD_DIR "${test_build_dir}"
42 GENERATOR "${generator}"
43 CLEAN_FIRST
44 ADDITIONAL_ARGS "-DMAINWINDOW_UI_PATH=sub1/sub2/sub3/"
45 OUTPUT_VARIABLE cmake_output
46 ERROR_VARIABLE cmake_error
47 RESULT_VARIABLE cmake_result)
48
49 if(NOT cmake_result EQUAL 0)
50 message(FATAL_ERROR "cmake_output: ${cmake_output}\ncmake_error"
51 ":${cmake_error}\nFAIL: \"uic_prefix_info_cmake_test\" test"
52 " in ${CMAKE_CURRENT_BINARY_DIR}/uic_prefix_info_cmake_test"
53 "${config_path}-build failed to configure")
54 else()
55 message(STATUS "PASS: \"uic_prefix_info_cmake_test\" test in"
56 "${CMAKE_CURRENT_BINARY_DIR}/uic_prefix_info_cmake_test"
57 "${config_path}-build was configured successfully")
58 endif()
59
60 string(CONCAT test_ui_file "${CMAKE_CURRENT_SOURCE_DIR}/../"
61 "test_qt_add_ui_common/uic_test/mainwindow.ui")
62 generate_hash_folder("example" "${test_ui_file}"
63 hash_folder_mainwindow)
64 string(CONCAT expected_prefix_info_cmake_content
65 "include_guard()\nset(${hash_folder_mainwindow}_prefix \""
66 "sub1/sub2/sub3\")")
67 # read the content of the prefix_info.cmake file
68 string(CONCAT "${CMAKE_CURRENT_BINARY_DIR}/"
69 "uic_prefix_info_cmake_test${config_path}-build")
70 file(READ
71 "${test_build_dir}/example_autogen/prefix_info.cmake"
72 prefix_info_cmake_content)
73
74 if("${prefix_info_cmake_content}" STREQUAL
75 "${expected_prefix_info_cmake_content}")
76 message(STATUS "PASS: \"uic_prefix_info_cmake_test\" test in "
77 "${CMAKE_CURRENT_BINARY_DIR}/uic_prefix_info_cmake_test"
78 "${config_path}-build has the expected content in "
79 "prefix_info.cmake")
80 else()
81 message(FATAL_ERROR "FAIL: \"uic_prefix_info_cmake_test\" test "
82 "in ${CMAKE_CURRENT_BINARY_DIR}/uic_prefix_info_cmake_test"
83 "${config_path}-build does not have the expected content in"
84 " prefix_info.cmake")
85 endif()
86
87 string(CONCAT test_build_dir "${CMAKE_CURRENT_BINARY_DIR}/"
88 "uic_prefix_info_cmake_test${config_path}-build")
89 run_cmake_build(
90 BUILD_DIR "${test_build_dir}"
91 VERBOSE ON
92 CONFIG "${config_arg}"
93 OUTPUT_VARIABLE cmake_build_output
94 ERROR_VARIABLE cmake_build_error
95 RESULT_VARIABLE cmake_build_result)
96
97 if(NOT cmake_build_result EQUAL 0)
98 message(FATAL_ERROR "cmake_build_output: ${cmake_build_output}"
99 "\ncmake_build_error: ${cmake_build_error}\n"
100 "FAIL: \"uic_prefix_info_cmake_test\" test in "
101 "${CMAKE_CURRENT_BINARY_DIR}/uic_prefix_info_cmake_test"
102 "${config_path}-build failed to build in the first build")
103 else()
104 message(STATUS "PASS: \"uic_prefix_info_cmake_test\" test in "
105 "${CMAKE_CURRENT_BINARY_DIR}/uic_prefix_info_cmake_test"
106 "${config_path}-build was built successfully in the first "
107 "build")
108 endif()
109
110 string(CONCAT test_source_dir "${CMAKE_CURRENT_SOURCE_DIR}/../"
111 "test_qt_add_ui_common/uic_test")
112 string(CONCAT test_build_dir "${CMAKE_CURRENT_BINARY_DIR}/"
113 "uic_prefix_info_cmake_test${config_path}-build")
114 run_cmake_configure(SOURCE_DIR "${test_source_dir}"
115 BUILD_DIR "${test_build_dir}"
116 GENERATOR "${generator}"
117 ADDITIONAL_ARGS "-DMAINWINDOW_UI_PATH=sub1/sub2/sub3/"
118 "-DNEW_UI_PATH=sub5/sub6/sub7/ " "-DADD_NEW_UI=ON"
119 OUTPUT_VARIABLE cmake_output
120 ERROR_VARIABLE cmake_error
121 RESULT_VARIABLE cmake_result)
122
123 if(NOT cmake_result EQUAL 0)
124 message(FATAL_ERROR "cmake_output: ${cmake_output}\ncmake_error"
125 ": ${cmake_error}\nFAIL: \"uic_prefix_info_cmake_test\" "
126 "test in ${CMAKE_CURRENT_BINARY_DIR}/uic_prefix_info_cmake_"
127 "test ${config_path}-build failed to configure in the"
128 "second build")
129 else()
130 message(STATUS "PASS: \"uic_prefix_info_cmake_test\" test in"
131 " ${CMAKE_CURRENT_BINARY_DIR}/uic_prefix_info_cmake_test"
132 "${config_path}-build was configured successfully in the "
133 "second build")
134 endif()
135
136 string(CONCAT test_ui_file "${CMAKE_CURRENT_SOURCE_DIR}/../"
137 "test_qt_add_ui_common/uic_test/subdir/mainwindow.ui")
138 generate_hash_folder("example" "${test_ui_file}"
139 hash_folder_subdir_mainwindow)
140 set(expected_prefix_info_cmake_content
141 "include_guard()\nset(${hash_folder_subdir_mainwindow}_prefix \
142 \"sub5/sub6/sub7\")")
143 string(CONCAT test_build_dir "${CMAKE_CURRENT_BINARY_DIR}/"
144 "uic_prefix_info_cmake_test${config_path}-build")
145 file(READ
146 "${test_build_dir}/example_autogen/prefix_info.cmake"
147 prefix_info_cmake_content)
148
149 if("${prefix_info_cmake_content}" STREQUAL
150 "${expected_prefix_info_cmake_content}")
151 message(STATUS "PASS: \"uic_prefix_info_cmake_test\" test in "
152 "${CMAKE_CURRENT_BINARY_DIR}/uic_prefix_info_cmake_test"
153 "${config_path}-build has the expected content in "
154 "prefix_info.cmake")
155 else()
156 message(FATAL_ERROR "FAIL: \"uic_prefix_info_cmake_test\" test "
157 "in ${CMAKE_CURRENT_BINARY_DIR}/uic_prefix_info_cmake_test"
158 "${config_path}-build does not have the expected content "
159 "in prefix_info.cmake")
160 endif()
161 endif()
162 endforeach()
163 endforeach()
164