38
38
39
39
-- get macdeployqt tool for Qt applications
40
40
function _get_macdeployqt ()
41
- local macdeployqt = find_tool (" macdeployqt" )
42
- if not macdeployqt then
43
- -- Try to find it in Qt installation
44
- local qt = find_qt ()
45
- if qt and qt .bindir then
46
- local macdeployqt_path = path .join (qt .bindir , " macdeployqt" )
47
- if os .isfile (macdeployqt_path ) then
48
- macdeployqt = {program = macdeployqt_path }
49
- end
50
- end
51
-
52
- if not macdeployqt then
53
- return nil
54
- end
55
- end
41
+ local macdeployqt = assert (find_tool (" macdeployqt" ), " macdeployqt not found!" )
56
42
return macdeployqt
57
43
end
58
44
59
45
-- detect if this is a Qt project
60
46
function _is_qt_project (package )
61
- -- Method 1: Check for Qt libraries in links
62
- local links = package :get (" links" )
63
- if links then
64
- for _ , link in ipairs (links ) do
65
- if link :lower ():find (" qt" ) then
47
+ -- method 1: check Qt rules
48
+ local rules = package :rules ()
49
+ if rules then
50
+ for _ , rule in ipairs (rules ) do
51
+ local rule_name = rule :name ()
52
+ if rule_name and (rule_name :find (" qt" , 1 , true ) or
53
+ rule_name :find (" qt6" , 1 , true ) or
54
+ rule_name :find (" qt5" , 1 , true )) then
66
55
return true
67
56
end
68
57
end
69
58
end
70
59
71
- -- Method 2: Check executable for Qt dependencies using otool
72
- local app_source , _ = _find_app_bundle (package )
73
- if app_source then
74
- local macos_dir = path .join (app_source , " Contents" , " MacOS" )
75
- if os .isdir (macos_dir ) then
76
- local executables = os .files (path .join (macos_dir , " *" ))
77
- for _ , executable in ipairs (executables ) do
78
- if os .isfile (executable ) then
79
- local otool_output = os .iorunv (" otool" , {" -L" , executable })
80
- if otool_output then
81
- -- Check for Qt frameworks in otool output
82
- if otool_output :lower ():find (" qt" ) or
83
- otool_output :find (" QtCore" ) or
84
- otool_output :find (" QtGui" ) or
85
- otool_output :find (" QtWidgets" ) then
86
- return true
87
- end
88
- end
89
- end
90
- end
91
- end
60
+ -- method 2: check target's Qt data
61
+ local qt_data = package :data (" qt" )
62
+ if qt_data then
63
+ return true
92
64
end
93
-
94
- -- Method 3: Check source files for Qt headers/includes
95
- local srcfiles , _ = package :sourcefiles ()
96
- for _ , srcfile in ipairs (srcfiles or {}) do
97
- if srcfile :endswith (" .cpp" ) or srcfile :endswith (" .cc" ) or srcfile :endswith (" .cxx" ) or srcfile :endswith (" .mm" ) then
98
- if os .isfile (srcfile ) then
99
- local content = io .readfile (srcfile )
100
- if content and (content :find (" #include.*[Qq][Tt]" ) or
101
- content :find (" #include.*<Q" ) or
102
- content :find (" QApplication" ) or
103
- content :find (" QWidget" ) or
104
- content :find (" QMainWindow" )) then
105
- return true
106
- end
107
- end
108
- end
65
+
66
+ -- method 3: check Qt environment variables
67
+ local qt_env = os.getenv (" QTDIR" ) or os.getenv (" QT_DIR" ) or os.getenv (" Qt6_DIR" ) or os.getenv (" Qt5_DIR" )
68
+ if qt_env then
69
+ return true
109
70
end
110
-
71
+ print ( " Not a Qt project " )
111
72
return false
112
73
end
113
74
114
- function _check_qml_usage (package , app_source )
115
- -- Method 1: Check for QML-related libraries in links
116
- local links = package :get (" links" )
117
- if links then
118
- for _ , link in ipairs (links ) do
119
- if link :lower ():find (" qml" ) or link :lower ():find (" quick" ) then
75
+ function _check_qml_usage (package )
76
+ -- method 1: check Qt rules
77
+ local rules = package :rules ()
78
+ if rules then
79
+ for _ , rule in ipairs (rules ) do
80
+ local rule_name = rule :name ()
81
+ if rule_name and (rule_name :find (" qml" , 1 , true ) or rule_name :find (" quick" , 1 , true )) then
120
82
return true
121
83
end
122
84
end
123
85
end
124
-
125
- -- Method 2: Check executable for QML/Quick dependencies
126
- local macos_dir = path .join (app_source , " Contents" , " MacOS" )
127
- if os .isdir (macos_dir ) then
128
- local executables = os .files (path .join (macos_dir , " *" ))
129
- for _ , executable in ipairs (executables ) do
130
- if os .isfile (executable ) then
131
- local otool_output = os .iorunv (" otool" , {" -L" , executable })
132
- if otool_output then
133
- if otool_output :find (" QtQml" ) or otool_output :find (" QtQuick" ) then
134
- return true
135
- end
136
- end
137
- end
138
- end
86
+
87
+ -- method 2: check Qt data for QML
88
+ local qml_data = package :data (" qml" )
89
+ if qml_data then
90
+ return true
139
91
end
140
-
141
- -- Method 3: Check for .qml files in project
92
+
93
+ -- method 3: check for .qml files
142
94
local qml_files = os .files (" **.qml" )
143
95
if qml_files and # qml_files > 0 then
144
96
return true
145
97
end
146
-
147
- -- Method 4: Check source files for QML-related includes
148
- local srcfiles , _ = package :sourcefiles ()
149
- for _ , srcfile in ipairs (srcfiles or {}) do
150
- if srcfile :endswith (" .cpp" ) or srcfile :endswith (" .cc" ) or srcfile :endswith (" .cxx" ) or srcfile :endswith (" .mm" ) then
151
- if os .isfile (srcfile ) then
152
- local content = io .readfile (srcfile )
153
- if content and (content :find (" #include.*QQml" ) or
154
- content :find (" #include.*QQuick" ) or
155
- content :find (" QQmlEngine" ) or
156
- content :find (" QQuickView" )) then
157
- return true
158
- end
159
- end
160
- end
161
- end
162
-
98
+ print (" No QML usage detected" )
163
99
return false
164
100
end
165
101
@@ -557,10 +493,8 @@ function _pack_dmg(package)
557
493
print (" Warning: macdeployqt not available, Qt dependencies may not be properly bundled" )
558
494
end
559
495
end
560
-
561
- -- find background image (optional)
496
+ -- find background image
562
497
local bg_image = _find_background_image (package )
563
-
564
498
-- get output dmg path
565
499
local dmg_file = package :outputfile () or _get_dmg_file (package )
566
500
dmg_file = dmg_file :gsub (" %.dmg+$" , " .dmg" ) -- clean up extension
@@ -569,15 +503,12 @@ function _pack_dmg(package)
569
503
if not staging_dir then
570
504
return false
571
505
end
572
-
573
506
-- create dmg
574
507
local success = _create_dmg_with_create_dmg (create_dmg , package , staging_dir , dmg_file , appbundle_name , bg_image )
575
-
576
508
if success then
577
509
-- verify the result
578
510
success = _verify_dmg (dmg_file )
579
511
end
580
-
581
512
-- cleanup staging directory
582
513
os .tryrm (staging_dir )
583
514
return success
587
518
function main (package )
588
519
-- only for macOS
589
520
if not is_host (" macosx" ) then
590
- print (" DMG packaging is only supported on macOS" )
591
521
return
592
522
end
593
523
@@ -599,7 +529,5 @@ function main(package)
599
529
local success = _pack_dmg (package )
600
530
if success then
601
531
print (" Final DMG file:" , dmg_file )
602
- else
603
- os.exit (1 )
604
532
end
605
533
end
0 commit comments