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