Skip to content

Commit 0e8157f

Browse files
committed
define QT_DEBUG or QT_NO_DEBUG depending on build type
to mimick what qmake does. Fixes: #15059
1 parent 62a5e3a commit 0e8157f

File tree

5 files changed

+28
-0
lines changed

5 files changed

+28
-0
lines changed

mesonbuild/dependencies/qt.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,9 @@ def get_exe_args(self, compiler: 'Compiler') -> T.List[str]:
166166
def log_details(self) -> str:
167167
return f'modules: {", ".join(sorted(self.requested_modules))}'
168168

169+
def _get_common_defines(self) -> T.List[str]:
170+
is_debug = self.env.coredata.optstore.get_value_for('debug')
171+
return ['-DQT_DEBUG' if is_debug else '-DQT_NO_DEBUG']
169172

170173
class QtPkgConfigDependency(_QtBase, PkgConfigDependency, metaclass=abc.ABCMeta):
171174

@@ -225,6 +228,8 @@ def __init__(self, name: str, env: 'Environment', kwargs: T.Dict[str, T.Any]):
225228

226229
self.libexecdir = self.get_pkgconfig_host_libexecs(self)
227230

231+
self.compile_args += self._get_common_defines()
232+
228233
@staticmethod
229234
@abc.abstractmethod
230235
def get_pkgconfig_host_bins(core: PkgConfigDependency) -> T.Optional[str]:
@@ -268,6 +273,8 @@ def __init__(self, name: str, env: 'Environment', kwargs: T.Dict[str, T.Any]):
268273
if not self.found():
269274
return
270275

276+
self.compile_args += self._get_common_defines()
277+
271278
# Query library path, header path, and binary path
272279
stdo = self.get_config_value(['-query'], 'args')
273280
qvars: T.Dict[str, str] = {}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#ifndef QT_DEBUG
2+
#error QT_DEBUG is not defined
3+
#endif
4+
5+
int main() { return 0; }
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#ifndef QT_NO_DEBUG
2+
#error QT_NO_DEBUG is not defined
3+
#endif
4+
5+
int main() { return 0; }

test cases/frameworks/4 qt/meson.build

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,5 +177,12 @@ foreach qt : ['qt4', 'qt5', 'qt6']
177177
accept_versions = ['>=@0@'.format(qtdep.version()), '<@0@'.format(qtdep.version()[0].to_int() + 1)]
178178
dependency(qt, modules: qt_modules, version: accept_versions, method : get_option('method'))
179179

180+
# check that QT_DEBUG is correctly defined depending on whether this is a debug build
181+
if get_option('debug')
182+
assert_source = 'assert_qt_debug.cpp'
183+
else
184+
assert_source = 'assert_qt_no_debug.cpp'
185+
endif
186+
executable(qt + 'assert_debug', sources: [ assert_source ], dependencies: [ qtdep ])
180187
endif
181188
endforeach

test cases/frameworks/4 qt/test.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@
55
{ "val": "config-tool" },
66
{ "val": "qmake" },
77
{ "val": "pkg-config" }
8+
],
9+
"debug": [
10+
{ "val": "true" },
11+
{ "val": "false" }
812
]
913
}
1014
},

0 commit comments

Comments
 (0)