@@ -190,11 +190,21 @@ function _find_qmake(sdkdir, sdkver)
190
190
end
191
191
192
192
-- get qt environment
193
- function _get_qtenvs (qmake )
193
+ function _get_qtenvs (qmake , sdkdir )
194
194
local envs = {}
195
+ local run_args = {" -query" }
196
+ if sdkdir then
197
+ local conf_paths = {path .join (sdkdir , " bin" , " target_qt.conf" ), path .join (sdkdir , " bin" , " qt.conf" )}
198
+ for _ , conf_path in ipairs (conf_paths ) do
199
+ if os .isfile (conf_path ) then
200
+ table .join2 (run_args , {" -qtconf" , conf_path })
201
+ break
202
+ end
203
+ end
204
+ end
195
205
local results = try {
196
206
function ()
197
- return os .iorunv (qmake , { " -query " } )
207
+ return os .iorunv (qmake , run_args )
198
208
end ,
199
209
catch {
200
210
function (errors )
@@ -215,24 +225,44 @@ function _get_qtenvs(qmake)
215
225
end
216
226
end
217
227
228
+ -- Verify and correct the Qt SDK version for cross-compiling.
229
+ -- qmake reports its own version (QT_VERSION), not the version specified in the SDK's configuration files.
230
+ function _tryfix_sdkver_for_cross (sdkdir , sdkver )
231
+ local qconfig_path = sdkdir and path .join (sdkdir , " mkspecs" , " qconfig.pri" )
232
+ if not sdkver or not os .isfile (qconfig_path ) then
233
+ return sdkver
234
+ end
235
+ -- Extract the actual SDK version from qconfig.pri
236
+ local qconfig = io .readfile (qconfig_path )
237
+ local actual_sdkver = qconfig and qconfig :match (" QT_VERSION%s*=%s*(%S+)" ) -- Expected format: QT_VERSION = x.y.z
238
+ if not actual_sdkver then
239
+ return sdkver
240
+ end
241
+ if sdkver ~= actual_sdkver then
242
+ wprint (" Host Qt SDK version (%s) differs from Target Qt SDK version (%s). To prevent build issues, please ensure both use the same version." , sdkver , actual_sdkver );
243
+ end
244
+ return actual_sdkver
245
+ end
246
+
218
247
-- find qt sdk toolchains
219
- function _find_qt (sdkdir , sdkver )
248
+ function _find_qt (sdkdir , sdkver , sdkdir_host )
220
249
221
250
-- find qmake
222
- local qmake = _find_qmake (sdkdir , sdkver )
251
+ local qmake = _find_qmake (sdkdir_host or sdkdir , sdkver )
223
252
if not qmake then
224
253
return
225
254
end
226
255
227
256
-- get qt environments
228
- local qtenvs = _get_qtenvs (qmake )
257
+ local located_sdkdir = sdkdir and _find_sdkdir (sdkdir , sdkver )
258
+ local qtenvs = _get_qtenvs (qmake , located_sdkdir or sdkdir )
229
259
if not qtenvs then
230
260
return
231
261
end
232
262
233
263
-- get qt toolchains
234
264
sdkdir = qtenvs .QT_INSTALL_PREFIX
235
- local sdkver = qtenvs .QT_VERSION
265
+ local sdkver = _tryfix_sdkver_for_cross ( sdkdir , qtenvs .QT_VERSION )
236
266
local bindir = qtenvs .QT_INSTALL_BINS
237
267
local libexecdir = qtenvs .QT_INSTALL_LIBEXECS
238
268
local qmldir = qtenvs .QT_INSTALL_QML
@@ -259,6 +289,16 @@ function _find_qt(sdkdir, sdkver)
259
289
-- TODO
260
290
end
261
291
end
292
+
293
+ if sdkdir_host then
294
+ local located_sdkdir_host = _find_sdkdir (sdkdir_host , sdkver )
295
+ local qtenvs_host = _get_qtenvs (qmake , located_sdkdir_host or sdkdir_host )
296
+ if qtenvs_host then
297
+ bindir_host = qtenvs_host .QT_HOST_BINS or qtenvs_host .QT_INSTALL_BINS or bindir_host
298
+ libexecdir_host = qtenvs_host .QT_HOST_LIBEXECS or qtenvs_host .QT_INSTALL_LIBEXECS or libexecdir_host
299
+ end
300
+ end
301
+
262
302
return {sdkdir = sdkdir , bindir = bindir , bindir_host = bindir_host , libexecdir = libexecdir , libexecdir_host = libexecdir_host , libdir = libdir , includedir = includedir , qmldir = qmldir , pluginsdir = pluginsdir , mkspecsdir = mkspecsdir , sdkver = sdkver }
263
303
end
264
304
@@ -282,13 +322,16 @@ function main(sdkdir, opt)
282
322
283
323
-- attempt to load cache first
284
324
local key = " detect.sdks.find_qt"
285
- local cacheinfo = detectcache :get (key ) or {}
325
+ local cacheinfo = ( sdkdir and detectcache : get2 ( key , sdkdir )) or detectcache :get (key ) or {}
286
326
if not opt .force and cacheinfo .qt and cacheinfo .qt .sdkdir and os .isdir (cacheinfo .qt .sdkdir ) then
287
327
return cacheinfo .qt
288
328
end
289
329
290
330
-- find qt
291
- local qt = _find_qt (sdkdir or config .get (" qt" ) or global .get (" qt" ) or config .get (" sdk" ), opt .version or config .get (" qt_sdkver" ))
331
+ local sdkdir = sdkdir or config .get (" qt" ) or global .get (" qt" ) or config .get (" sdk" )
332
+ local sdkver = opt .version or config .get (" qt_sdkver" )
333
+ local sdkdir_host = opt .sdkdir_host or config .get (" qt_host" ) or global .get (" qt_host" )
334
+ local qt = _find_qt (sdkdir , sdkver , sdkdir_host )
292
335
if qt then
293
336
294
337
-- save to config
@@ -314,7 +357,11 @@ function main(sdkdir, opt)
314
357
315
358
-- save to cache
316
359
cacheinfo .qt = qt or false
317
- detectcache :set (key , cacheinfo )
360
+ if sdkdir then
361
+ detectcache :set2 (key , sdkdir , cacheinfo )
362
+ else
363
+ detectcache :set (key , cacheinfo )
364
+ end
318
365
detectcache :save ()
319
366
return qt
320
367
end
0 commit comments