forked from premake/premake-android
-
Notifications
You must be signed in to change notification settings - Fork 3
/
vsandroid_androidproj.lua
249 lines (194 loc) · 5.95 KB
/
vsandroid_androidproj.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
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
--
-- android/vsandroid_androidproj.lua
-- vs-android integration for vstudio.
-- Copyright (c) 2012-2015 Manu Evans and the Premake project
--
local p = premake
local android = p.modules.android
local vsandroid = p.modules.vsandroid
local vc2010 = p.vstudio.vc2010
local vstudio = p.vstudio
local project = p.project
--
-- Add android tools to vstudio actions.
--
premake.override(vstudio.vs2010, "generateProject", function(oldfn, prj)
if prj.kind == p.ANDROIDPROJ then
p.eol("\r\n")
p.indent(" ")
p.escaper(vstudio.vs2010.esc)
if project.iscpp(prj) then
p.generate(prj, ".androidproj", vc2010.generate)
-- Skip generation of empty user files
local user = p.capture(function() vc2010.generateUser(prj) end)
if #user > 0 then
p.generate(prj, ".androidproj.user", function() p.outln(user) end)
end
end
else
oldfn(prj)
end
end)
premake.override(vstudio, "projectfile", function(oldfn, prj)
if prj.kind == p.ANDROIDPROJ then
return premake.filename(prj, ".androidproj")
else
return oldfn(prj)
end
end)
premake.override(vstudio, "tool", function(oldfn, prj)
if prj.kind == p.ANDROIDPROJ then
return "39E2626F-3545-4960-A6E8-258AD8476CE5"
else
return oldfn(prj)
end
end)
premake.override(vc2010.elements, "globals", function (oldfn, cfg)
local elements = oldfn(cfg)
if cfg.kind == premake.ANDROIDPROJ then
-- Remove "IgnoreWarnCompileDuplicatedFilename".
local pos = table.indexof(elements, vc2010.ignoreWarnDuplicateFilename)
table.remove(elements, pos)
elements = table.join(elements, {
android.projectVersion
})
end
return elements
end)
function android.projectVersion(cfg)
_p(2, "<RootNamespace>%s</RootNamespace>", cfg.project.name)
_p(2, "<MinimumVisualStudioVersion>14.0</MinimumVisualStudioVersion>")
_p(2, "<ProjectVersion>1.0</ProjectVersion>")
end
premake.override(vc2010.elements, "configurationProperties", function(oldfn, cfg)
local elements = oldfn(cfg)
if cfg.kind == p.ANDROIDPROJ then
elements = {
vc2010.useDebugLibraries,
}
end
return elements
end)
premake.override(vc2010.elements, "itemDefinitionGroup", function(oldfn, cfg)
local elements = oldfn(cfg)
if cfg.kind == p.ANDROIDPROJ then
elements = {
android.antPackage,
}
end
return elements
end)
premake.override(vc2010, "importDefaultProps", function(oldfn, prj)
if prj.kind == p.ANDROIDPROJ then
p.w('<Import Project="$(AndroidTargetsPath)\\Android.Default.props" />')
else
oldfn(prj)
end
end)
premake.override(vc2010, "importLanguageSettings", function(oldfn, prj)
if prj.kind == p.ANDROIDPROJ then
p.w('<Import Project="$(AndroidTargetsPath)\\Android.props" />')
else
oldfn(prj)
end
end)
premake.override(vc2010, "propertySheets", function(oldfn, cfg)
if cfg.kind ~= p.ANDROIDPROJ then
oldfn(cfg)
end
end)
premake.override(vc2010.elements, "outputProperties", function(oldfn, cfg)
if cfg.kind == p.ANDROIDPROJ then
return {
android.outDir,
}
else
return oldfn(cfg)
end
end)
function android.outDir(cfg)
vc2010.element("OutDir", nil, "%s\\", cfg.buildtarget.directory)
end
premake.override(vc2010, "importLanguageTargets", function(oldfn, prj)
if prj.kind == p.ANDROIDPROJ then
p.w('<Import Project="$(AndroidTargetsPath)\\Android.targets" />')
else
oldfn(prj)
end
end)
function android.link(cfg, file)
local fname = path.translate(file.relpath)
-- Files that live outside of the project tree need to be "linked"
-- and provided with a project relative pseudo-path. Check for any
-- leading "../" sequences and, if found, remove them and mark this
-- path as external.
local link, count = fname:gsub("%.%.%/", "")
local external = (count > 0) or fname:find(':', 1, true)
-- Try to provide a little bit of flexibility by allowing virtual
-- paths for external files. Would be great to support them for all
-- files but Visual Studio chokes if file is already in project area.
if external and file.vpath ~= file.relpath then
link = file.vpath
end
if external then
vc2010.element("Link", nil, path.translate(link))
end
end
vc2010.categories.AndroidManifest = {
name = "AndroidManifest",
priority = 99,
emitFiles = function(prj, group)
vc2010.emitFiles(prj, group, "AndroidManifest", {vc2010.generatedFile, android.link, android.manifestSubType})
end,
emitFilter = function(prj, group)
vc2010.filterGroup(prj, group, "AndroidManifest")
end
}
function android.manifestSubType(cfg, file)
vc2010.element("SubType", nil, "Designer")
end
vc2010.categories.AntBuildXml = {
name = "AntBuildXml",
priority = 99,
emitFiles = function(prj, group)
vc2010.emitFiles(prj, group, "AntBuildXml", {vc2010.generatedFile, android.link})
end,
emitFilter = function(prj, group)
vc2010.filterGroup(prj, group, "AntBuildXml")
end
}
vc2010.categories.AntProjectPropertiesFile = {
name = "AntProjectPropertiesFile",
priority = 99,
emitFiles = function(prj, group)
vc2010.emitFiles(prj, group, "AntProjectPropertiesFile", {vc2010.generatedFile, android.link})
end,
emitFilter = function(prj, group)
vc2010.filterGroup(prj, group, "AntProjectPropertiesFile")
end
}
vc2010.categories.Content = {
name = "Content",
priority = 99,
emitFiles = function(prj, group)
vc2010.emitFiles(prj, group, "Content", {vc2010.generatedFile, android.link})
end,
emitFilter = function(prj, group)
vc2010.filterGroup(prj, group, "Content")
end
}
premake.override(vc2010, "categorizeFile", function(base, prj, file)
if prj.kind ~= p.ANDROIDPROJ then
return base(prj, file)
end
local filename = path.getname(file.name):lower()
if filename == "androidmanifest.xml" then
return vc2010.categories.AndroidManifest
elseif filename == "build.xml" then
return vc2010.categories.AntBuildXml
elseif filename == "project.properties" then
return vc2010.categories.AntProjectPropertiesFile
else
return vc2010.categories.Content
end
end)