forked from Gaztin/premake-qmake
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathqmake_project.lua
More file actions
297 lines (259 loc) · 5.01 KB
/
qmake_project.lua
File metadata and controls
297 lines (259 loc) · 5.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
local p = premake
local project = p.project
local qmake = p.extensions.qmake
qmake.project = {}
local m = qmake.project
m.configs = {}
--
-- Generate a qmake project
--
function m.generate(prj)
-- Subdir subprojects need to live in their own subdirectories
prj.location = prj.location .. "/" .. prj.name
m.template(prj)
for cfg in qmake.eachconfig(prj) do
p.outln('')
p.push('CONFIG(%s, debug|release) {', qmake.configName(cfg))
m.destdir(cfg)
m.target(cfg)
m.mocDir(cfg)
m.rccDir(cfg)
m.uiDir(cfg)
m.objDir(cfg)
m.qt(cfg)
m.config(cfg)
m.defines(cfg)
m.forms(cfg)
m.resources(cfg)
m.headers(cfg)
m.sources(cfg)
m.includepath(cfg)
m.pchheader(cfg)
m.libs(cfg)
p.pop('}')
end
end
--
-- Template
--
function m.template(prj)
local templates = {
['ConsoleApp'] = 'app',
['WindowedApp'] = 'app',
['SharedLib'] = 'lib',
['StaticLib'] = 'lib',
}
p.w('TEMPLATE = %s', templates[prj.kind] or '')
end
--
-- Configs
--
m.configs.funcs = function(cfg)
return {
m.configs.kind,
m.configs.rtti,
m.configs.cppdialect,
}
end
function m.configs.kind(cfg)
local configs = {
['ConsoleApp'] = 'console',
['WindowedApp'] = 'windows',
['SharedLib'] = 'shared',
['StaticLib'] = 'static',
}
if configs[cfg.kind] then
p.w(configs[cfg.kind])
end
end
function m.configs.rtti(cfg)
if cfg.rtti == "On" then
p.w('rtti')
elseif cfg.rtti == "Off" then
p.w('rtti_off')
end
end
function m.configs.cppdialect(cfg)
local dialects = {
["C++11"] = "c++11",
["C++14"] = "c++14",
["C++17"] = "c++17",
["gnu++11"] = "c++11",
["gnu++14"] = "c++14",
["gnu++17"] = "c++17",
}
if dialects[cfg.cppdialect] then
p.w(dialects[cfg.cppdialect])
end
end
--
-- Destination directory
--
function m.destdir(cfg)
if cfg.buildtarget.directory then
p.w('DESTDIR = %s', cfg.buildtarget.directory)
end
end
--
-- Target
--
function m.target(cfg)
if cfg.targetname then
p.w('TARGET = %s', cfg.targetname)
end
end
--
-- MOC directory
--
function m.mocDir(cfg)
if cfg.objdir then
p.w('MOC_DIR = "%s"', p.project.getrelative(cfg.project, cfg.objdir))
end
end
--
-- RCC directory
--
function m.rccDir(cfg)
if cfg.objdir then
p.w('RCC_DIR = "%s"', p.project.getrelative(cfg.project, cfg.objdir))
end
end
--
-- UI directory
--
function m.uiDir(cfg)
if cfg.objdir then
p.w('UI_DIR = "%s"', p.project.getrelative(cfg.project, cfg.objdir))
end
end
--
-- Objects directory
--
function m.objDir(cfg)
if cfg.objdir then
p.w('OBJECTS_DIR = "%s"', p.project.getrelative(cfg.project, cfg.objdir))
end
end
--
-- Qt modules
--
function m.qt(cfg)
if #cfg.qtmodules > 0 then
qmake.pushVariable("QT")
for _, qtmodule in ipairs(cfg.qtmodules) do
p.w(qtmodule)
end
qmake.popVariable()
end
end
--
-- Config
--
function m.config(cfg)
p.eol(" \\\n")
p.push('CONFIG +=')
p.callArray(m.configs.funcs, cfg)
p.pop()
p.eol("\n")
p.outln('')
end
--
-- Defines
--
function m.defines(cfg)
if #cfg.defines > 0 then
qmake.pushVariable("DEFINES")
for _, define in ipairs(cfg.defines) do
p.w(define)
end
qmake.popVariable()
end
end
--
-- Files
--
function m.files(cfg, var, exts)
local fconfigs = qmake.fileConfigs(cfg, exts)
if #fconfigs > 0 then
qmake.pushVariable(var)
for _, fcfg in ipairs(fconfigs) do
p.w(fcfg.path)
end
qmake.popVariable()
end
end
function m.forms(cfg)
m.files(cfg, "FORMS", {".ui"})
end
function m.resources(cfg)
m.files(cfg, "RESOURCES", {".qrc"})
end
function m.headers(cfg)
m.files(cfg, "HEADERS", {".h", ".hh", ".hpp", ".hxx", ".inl"})
end
function m.sources(cfg)
m.files(cfg, "SOURCES", {".c", ".cc", ".cpp", ".cxx"})
end
--
-- Include path
--
function m.includepath(cfg)
if #cfg.includedirs > 0 then
qmake.pushVariable("INCLUDEPATH")
for _, includedir in ipairs(cfg.includedirs) do
p.w('"%s"', p.project.getrelative(cfg.project, includedir))
end
qmake.popVariable()
end
end
--
-- Precompiled header
--
function m.pchheader(cfg)
-- copied from gmake2_cpp.lua
if not cfg.pchheader or cfg.flags.NoPCH then
return
end
p.w('CONFIG += precompile_header')
local pch = cfg.pchheader
local found = false
-- test locally in the project folder first (this is the most likely location)
local testname = path.join(cfg.project.basedir, pch)
if os.isfile(testname) then
pch = project.getrelative(cfg.project, testname)
found = true
else
-- else scan in all include dirs.
for _, incdir in ipairs(cfg.includedirs) do
testname = path.join(incdir, pch)
if os.isfile(testname) then
pch = project.getrelative(cfg.project, testname)
found = true
break
end
end
end
if not found then
pch = project.getrelative(cfg.project, path.getabsolute(pch))
end
p.w('PRECOMPILED_HEADER = "%s"', pch)
end
--
-- Libs
--
function m.libs(cfg)
local links
local toolset = p.config.toolset(cfg)
if toolset then
links = toolset.getlinks(cfg)
else
links = p.config.getlinks(cfg)
end
if #links > 0 then
qmake.pushVariable("LIBS")
for _, link in ipairs(links) do
p.w('"%s"', link)
end
qmake.popVariable()
end
end