Debian Codegraph @

test cases/frameworks/4 qt/meson.build

raw
1 project('qt4, qt5, and qt6 build test', 'cpp',
2 # Qt6 requires C++ 17 support
3 default_options : ['cpp_std=c++17'])
4
5 # Visit the subdir before entering the loop
6 subdir('mocdep')
7
8 fs = import('fs')
9 qt5_modules = ['Widgets']
10 qt6_modules = ['Widgets']
11
12 copyfile = find_program('copyfile.py')
13 copyfile_gen = generator(copyfile,
14 output: '@[email protected]',
15 arguments : ['@INPUT@', '@OUTPUT@'])
16
17 manualinclude_cpp_gen = copyfile_gen.process('manualinclude.cpp')
18
19 manualinclude_cpp = fs.copyfile('manualinclude.cpp')
20 manualinclude_h = fs.copyfile('manualinclude.h')
21
22 foreach qt : ['qt4', 'qt5', 'qt6']
23 qt_modules = ['Core', 'Gui']
24 if qt == 'qt5'
25 qt_modules += qt5_modules
26 elif qt == 'qt6'
27 qt_modules += qt6_modules
28 endif
29
30 # Test that invalid modules are indeed not found
31 fakeqtdep = dependency(qt, modules : ['DefinitelyNotFound'], required : false, method : get_option('method'))
32 if fakeqtdep.found()
33 error('Invalid qt dep incorrectly found!')
34 endif
35
36 # Test that partially-invalid modules are indeed not found
37 fakeqtdep = dependency(qt, modules : ['Core', 'DefinitelyNotFound'], required : false, method : get_option('method'))
38 if fakeqtdep.found()
39 error('Invalid qt dep incorrectly found!')
40 endif
41
42 # This test should be skipped if the required version of Qt isn't found
43 #
44 # (In the CI environment, the specified version of Qt is definitely present.
45 # An unexpected skip here is treated as a failure, so we are testing that the
46 # detection mechanism is able to find Qt.)
47 needed_qt = get_option('required').to_lower()
48 required = (qt == needed_qt)
49 if required
50 dep = dependency(qt, modules : ['Core'], required : false, method : get_option('method'))
51 if not dep.found()
52 error('MESON_SKIP_TEST @0@ not found.'.format(needed_qt))
53 endif
54 endif
55
56 # Ensure that the "no-Core-module-specified" code branch is hit
57 nocoredep = dependency(qt, modules : ['Gui'], required : required, method : get_option('method'))
58
59 # If 'qt' modules are found, test that.
60 qtdep = dependency(qt, modules : qt_modules, main : true, private_headers: true, required : required, method : get_option('method'))
61 if qtdep.found()
62 qtmodule = import(qt)
63 assert(qtmodule.has_tools(tools: ['moc'], method: get_option('method'), version: '>=4'))
64 if get_option('expect_lrelease')
65 assert(qtmodule.has_tools(), 'You may be missing a devel package. (qttools5-dev-tools on Debian based systems)')
66 else
67 assert(not qtmodule.has_tools(), 'Unexpectedly found lrelease')
68 assert(not qtmodule.has_tools(tools: ['lrelease']), 'Unexpectedly found lrelease')
69 assert(qtmodule.has_tools(tools: ['moc', 'uic', 'rcc']), 'You may be missing a devel package. (qttools5-dev-tools on Debian based systems)')
70 endif
71
72 # Test that fetching a variable works and yields a non-empty value
73 assert(qtdep.get_variable('prefix', configtool: 'QT_INSTALL_PREFIX') != '')
74
75 # The following has two resource files because having two in one target
76 # requires you to do it properly or you get linker symbol clashes.
77
78 prep = qtmodule.preprocess(
79 moc_headers : ['mainWindow.h'], # These need to be fed through the moc tool before use.
80 method : get_option('method')
81 )
82 # XML files that need to be compiled with the uic tol.
83 prep += qtmodule.compile_ui(
84 sources : 'ui/mainWindow.ui',
85 method: get_option('method'),
86 preserve_paths: true)
87
88 qtmodule.preprocess(
89 ui_files : 'ui/mainWindow.ui',
90 method: get_option('method'),
91 preserve_paths: true)
92
93 # Resource file(s) for rcc compiler
94 extra_cpp_args = []
95 if meson.is_unity()
96 extra_cpp_args += '-DUNITY_BUILD'
97 prep_rcc = qtmodule.preprocess(qt + '_unity_resource', qresources : ['stuff.qrc', 'stuff2.qrc'], method : get_option('method'))
98 else
99 prep_rcc = qtmodule.preprocess(qresources : ['stuff.qrc', 'stuff2.qrc'], method : get_option('method'))
100 endif
101
102 # Test that setting a unique name with a positional argument works
103 qtmodule.compile_resources(
104 name : qt + 'teststuff',
105 sources : files(['stuff.qrc', 'stuff2.qrc']),
106 method : get_option('method')
107 )
108
109 # Test that passing extra arguments to rcc works
110 # qt4-rcc and qt5-rcc take different arguments, for example qt4: ['-compress', '3']; qt5: '--compress=3'
111 qtmodule.preprocess(qt + 'testrccarg', qresources : files(['stuff.qrc', 'stuff2.qrc']), rcc_extra_arguments : '--compress=3', method : get_option('method'))
112
113 if get_option('expect_lrelease')
114 translations_cpp = qtmodule.compile_translations(qresource: qt+'_lang.qrc')
115 # unity builds suck and definitely cannot handle two qrc embeds in one compilation unit
116 unityproof_translations = static_library(qt+'unityproof_translations', translations_cpp, dependencies: qtdep)
117
118 extra_cpp_args += '-DQT="@0@"'.format(qt)
119 qexe = executable(qt + 'app',
120 sources : ['main.cpp', 'mainWindow.cpp', # Sources that don't need preprocessing.
121 prep, prep_rcc],
122 dependencies : qtdep,
123 link_with: unityproof_translations,
124 cpp_args: extra_cpp_args,
125 gui_app : true)
126
127 # We need a console test application because some test environments
128 # do not have an X server.
129
130 translations = qtmodule.compile_translations(ts_files : qt+'core_fr.ts', build_by_default : true)
131 endif
132
133 qtcore = dependency(qt, modules : 'Core', method : get_option('method'))
134
135 qtcoreapp = executable(qt + 'core', 'q5core.cpp',
136 cpp_args: '-DQT="@0@"'.format(qt),
137 dependencies : qtcore)
138
139 test(qt + 'test', qtcoreapp)
140
141 # The build system needs to include the cpp files from
142 # headers but the user must manually include moc
143 # files from sources.
144 qtmodule.preprocess(
145 moc_extra_arguments : ['-DMOC_EXTRA_FLAG'], # This is just a random macro to test `extra_arguments`
146 moc_sources : manualinclude_cpp,
147 moc_headers : manualinclude_h[0],
148 method : get_option('method'),
149 dependencies: mocdep,
150 )
151
152 manpreprocessed = qtmodule.compile_moc(
153 extra_args : ['-DMOC_EXTRA_FLAG'], # This is just a random macro to test `extra_arguments`
154 sources : manualinclude_cpp_gen,
155 headers : 'manualinclude.h',
156 method : get_option('method'),
157 dependencies: mocdep,
158 )
159
160 qtmaninclude = executable(qt + 'maninclude',
161 sources : ['manualinclude.cpp', manpreprocessed],
162 dependencies : [qtcore, mocdep])
163
164 test(qt + 'maninclude', qtmaninclude)
165
166 # building Qt plugins implies to give include path to moc
167 plugin_includes = include_directories('pluginInterface', 'plugin')
168 pluginpreprocess = qtmodule.preprocess(
169 moc_headers : 'plugin/plugin.h',
170 include_directories : plugin_includes
171 )
172 plugin = library(qt + 'plugin', 'plugin/plugin.cpp', pluginpreprocess,
173 include_directories : plugin_includes,
174 dependencies : qtcore)
175
176 # implementing Qt interfaces requires passing Qt include paths to moc
177 qtinterfacepreprocess = qtmodule.preprocess(
178 moc_sources : 'qtinterface.cpp',
179 dependencies : qtdep
180 )
181 qtinterface = library(qt + 'qtinterface',
182 sources : ['qtinterface.cpp', qtinterfacepreprocess],
183 dependencies : qtdep)
184
185 if qt == 'qt5'
186 subdir('subfolder')
187 endif
188
189 # Check we can apply a version constraint
190 accept_versions = ['>=@0@'.format(qtdep.version()), '<@0@'.format(qtdep.version()[0].to_int() + 1)]
191 dependency(qt, modules: qt_modules, version: accept_versions, method : get_option('method'))
192
193 # check that QT_DEBUG is correctly defined depending on whether this is a debug build
194 if get_option('debug')
195 assert_source = 'assert_qt_debug.cpp'
196 else
197 assert_source = 'assert_qt_no_debug.cpp'
198 endif
199 executable(qt + 'assert_debug', sources: [ assert_source ], dependencies: [ qtdep ])
200 endif
201 endforeach