dependencies: add sysroot path to Qt include and library paths Meson probes the build-host filesystem for Qt private headers when resolving a Qt dependency during a cross-build. This can cause build-host include paths (e.g. /usr/include/6.11.0 and Qt subdirs) to be injected into the cross-compiler command line, which breaks strict cross-compilation (GCC errors with "unsafe for cross-compilation"). This actually happens only for freedesktop.org pkg-config, because pkgconf instead adds the sysroot automatically. Fix by doing it by hand in qt.py. Fixes: #15456
diff --git a/mesonbuild/dependencies/qt.py b/mesonbuild/dependencies/qt.py index 0dc5d52..a235471 100644 --- a/mesonbuild/dependencies/qt.py +++ b/mesonbuild/dependencies/qt.py
@@ -193,7 +193,9 @@ self.is_found = False return if self.private_headers: + # fd.o pkg-config does not apply PKG_CONFIG_SYSROOT_DIR to variables. qt_inc_dir = mod.get_variable(pkgconfig='includedir') + qt_inc_dir = self.env.get_sys_root_path(self.for_machine, qt_inc_dir) mod_private_dir = os.path.join(qt_inc_dir, 'Qt' + m) if not os.path.isdir(mod_private_dir): if self.env.machines[self.for_machine].is_darwin(): @@ -203,6 +205,7 @@ # headers; both public and private headers live under # <libdir>/Qt<Module>.framework/Headers. libdir = mod.get_variable(pkgconfig='libdir', default_value='') + libdir = self.env.get_sys_root_path(self.for_machine, libdir) framework_inc = os.path.join(libdir, f'Qt{m}.framework', 'Headers') if libdir and os.path.isdir(framework_inc): mod_private_dir = framework_inc