-
Notifications
You must be signed in to change notification settings - Fork 1
/
qt.lua
135 lines (123 loc) · 5.06 KB
/
qt.lua
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
local qt = {}
local os_to_default_configuration = {
bsd = {
},
linux = {
moc = '/usr/lib/x86_64-linux-gnu/qt5/bin/moc',
moc_includedirs = {
'/usr/include/qt5/QtQml',
'/usr/include/x86_64-linux-gnu/qt5/QtQml'},
includedirs = {
'/usr/include/qt5/',
'/usr/include/qt5/QtQml',
'/usr/include/x86_64-linux-gnu/qt5',
'/usr/include/x86_64-linux-gnu/qt5/QtQml'},
libdirs = {'/usr/lib/x86_64-linux-gnu'},
links = {'Qt5Core', 'Qt5Gui', 'Qt5Qml', 'Qt5Quick'},
buildoptions = {'-fPIC'},
linkoptions = {},
},
macosx = {
moc = '/usr/local/opt/qt/bin/moc',
moc_includedirs = {'/usr/local/opt/qt/include/QtQml'},
includedirs = {
'/usr/local/opt/qt/include',
'/usr/local/opt/qt/include/QtQml'},
libdirs = {},
links = {},
buildoptions = {'-Wno-comma'},
linkoptions = {
'-F /usr/local/opt/qt/lib',
'-framework QtCore',
'-framework QtGui',
'-framework QtQml',
'-framework QtQuick',
'-framework QtQuickControls2'},
},
solaris = {
},
windows = {
moc = 'c:\\Qt\\opt\\bin\\moc.exe',
moc_includedirs = {'c:\\Qt\\opt\\include\\QtQml'},
includedirs = {
'c:\\Qt\\opt\\include',
'c:\\Qt\\opt\\include\\QtQml'},
libdirs = {'c:\\Qt\\opt\\lib'},
links = {'Qt5Core', 'Qt5Gui', 'Qt5Qml', 'Qt5Quick'},
buildoptions = {},
linkoptions = {},
},
}
-- generate_configuration merges the given configuration map with the default one.
-- The current os configuration is extracted with premake's os.get().
function generate_configuration(os_to_configuration)
if os_to_configuration == nil then
os_to_configuration = {}
end
setmetatable(os_to_configuration, {__index = os_to_default_configuration})
local configuration = os_to_configuration[os.get()]
setmetatable(configuration, {__index = os_to_default_configuration[os.get()]})
return configuration
end
-- moc calls Qt's moc on each file, and writes the result to target_directory.
-- os_to_configuration can be used to override os-specific configurations.
-- Only parameters different from the default need to be specified.
function qt.moc(files, target_directory, os_to_configuration)
local configuration = generate_configuration(os_to_configuration)
os.mkdir(target_directory)
local generated_files = {}
local moc_includes = {}
for index, includedir in ipairs(configuration.moc_includedirs) do
moc_includes[index] = '-I"' .. includedir .. '"'
end
for index, file in pairs(files) do
local target_file = target_directory .. '/' .. path.getname(file) .. '.cpp'
if os.execute(
configuration.moc
.. ' ' .. table.concat(moc_includes, ' ')
.. ' -o "' .. target_file .. '" '
.. ' "' .. path.translate(path.getabsolute(file)) .. '"'
) ~= 0 then
print('Qt error: running moc on "' .. path.translate(path.getabsolute(file)) .. '" failed')
os.exit(1)
end
generated_files[index] = target_file
end
return generated_files
end
-- includedirs returns a list to be passed to premake's includedirs function.
-- os_to_configuration can be used to override os-specific configurations.
-- Only parameters different from the default need to be specified.
function qt.includedirs(os_to_configuration)
local configuration = generate_configuration(os_to_configuration)
return configuration.includedirs
end
-- libdirs returns a list to be passed to premake's libdirs function.
-- os_to_configuration can be used to override os-specific configurations.
-- Only parameters different from the default need to be specified.
function qt.libdirs(os_to_configuration)
local configuration = generate_configuration(os_to_configuration)
return configuration.libdirs
end
-- links returns a list to be passed to premake's links function.
-- os_to_configuration can be used to override os-specific configurations.
-- Only parameters different from the default need to be specified.
function qt.links(os_to_configuration)
local configuration = generate_configuration(os_to_configuration)
return configuration.links
end
-- buildoptions returns a list to be passed to premake's buildoptions function.
-- os_to_configuration can be used to override os-specific configurations.
-- Only parameters different from the default need to be specified.
function qt.buildoptions(os_to_configuration)
local configuration = generate_configuration(os_to_configuration)
return configuration.buildoptions
end
-- linkoptions returns a list to be passed to premake's linkoptions function.
-- os_to_configuration can be used to override os-specific configurations.
-- Only parameters different from the default need to be specified.
function qt.linkoptions(os_to_configuration)
local configuration = generate_configuration(os_to_configuration)
return configuration.linkoptions
end
return qt