2015-10-15 13:05:33 +00:00
|
|
|
--
|
|
|
|
-- 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)
|
2016-11-25 08:20:32 +00:00
|
|
|
_p(2, "<MinimumVisualStudioVersion>14.0</MinimumVisualStudioVersion>")
|
2015-10-15 13:05:33 +00:00
|
|
|
_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 = {
|
2019-01-09 22:37:06 +00:00
|
|
|
android.androidAPILevel,
|
2015-10-15 13:05:33 +00:00
|
|
|
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 {
|
2016-11-25 08:20:32 +00:00
|
|
|
android.outDir,
|
2015-10-15 13:05:33 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
return oldfn(cfg)
|
|
|
|
end
|
|
|
|
end)
|
|
|
|
|
|
|
|
|
2016-11-25 08:20:32 +00:00
|
|
|
function android.outDir(cfg)
|
|
|
|
vc2010.element("OutDir", nil, "%s\\", cfg.buildtarget.directory)
|
|
|
|
end
|
|
|
|
|
|
|
|
|
2015-10-15 13:05:33 +00:00
|
|
|
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)
|
|
|
|
|
2017-11-01 19:51:35 +00:00
|
|
|
function android.link(cfg, file)
|
2018-06-21 22:14:17 +00:00
|
|
|
-- default the seperator to '/' as that is what is searched for
|
|
|
|
-- below. Otherwise the function will use target seperator which
|
|
|
|
-- could be '\\' and result in failure to create links.
|
|
|
|
local fname = path.translate(file.relpath, '/')
|
2019-01-09 22:37:06 +00:00
|
|
|
|
2017-11-01 19:51:35 +00:00
|
|
|
-- 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("%.%.%/", "")
|
2018-06-21 22:14:17 +00:00
|
|
|
local external = (count > 0) or fname:find(':', 1, true) or (file.vpath and file.vpath ~= file.relpath)
|
2017-11-01 19:51:35 +00:00
|
|
|
|
|
|
|
-- 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
|
|
|
|
|
2015-10-15 13:05:33 +00:00
|
|
|
|
2016-11-15 10:57:43 +00:00
|
|
|
vc2010.categories.AndroidManifest = {
|
|
|
|
name = "AndroidManifest",
|
|
|
|
priority = 99,
|
2015-10-15 13:05:33 +00:00
|
|
|
|
2016-11-15 10:57:43 +00:00
|
|
|
emitFiles = function(prj, group)
|
2017-11-01 19:51:35 +00:00
|
|
|
vc2010.emitFiles(prj, group, "AndroidManifest", {vc2010.generatedFile, android.link, android.manifestSubType})
|
2016-11-15 10:57:43 +00:00
|
|
|
end,
|
2015-10-15 13:05:33 +00:00
|
|
|
|
2016-11-15 10:57:43 +00:00
|
|
|
emitFilter = function(prj, group)
|
|
|
|
vc2010.filterGroup(prj, group, "AndroidManifest")
|
|
|
|
end
|
|
|
|
}
|
2015-10-15 13:05:33 +00:00
|
|
|
|
|
|
|
function android.manifestSubType(cfg, file)
|
|
|
|
vc2010.element("SubType", nil, "Designer")
|
|
|
|
end
|
|
|
|
|
2016-11-15 10:57:43 +00:00
|
|
|
vc2010.categories.AntBuildXml = {
|
|
|
|
name = "AntBuildXml",
|
|
|
|
priority = 99,
|
2015-10-15 13:05:33 +00:00
|
|
|
|
2016-11-15 10:57:43 +00:00
|
|
|
emitFiles = function(prj, group)
|
2017-11-01 19:51:35 +00:00
|
|
|
vc2010.emitFiles(prj, group, "AntBuildXml", {vc2010.generatedFile, android.link})
|
2016-11-15 10:57:43 +00:00
|
|
|
end,
|
2015-10-15 13:05:33 +00:00
|
|
|
|
2016-11-15 10:57:43 +00:00
|
|
|
emitFilter = function(prj, group)
|
|
|
|
vc2010.filterGroup(prj, group, "AntBuildXml")
|
|
|
|
end
|
|
|
|
}
|
2015-10-15 13:05:33 +00:00
|
|
|
|
2016-11-15 10:57:43 +00:00
|
|
|
vc2010.categories.AntProjectPropertiesFile = {
|
|
|
|
name = "AntProjectPropertiesFile",
|
|
|
|
priority = 99,
|
2015-10-15 13:05:33 +00:00
|
|
|
|
2016-11-15 10:57:43 +00:00
|
|
|
emitFiles = function(prj, group)
|
2017-11-01 19:51:35 +00:00
|
|
|
vc2010.emitFiles(prj, group, "AntProjectPropertiesFile", {vc2010.generatedFile, android.link})
|
2016-11-15 10:57:43 +00:00
|
|
|
end,
|
2015-10-15 13:05:33 +00:00
|
|
|
|
2016-11-15 10:57:43 +00:00
|
|
|
emitFilter = function(prj, group)
|
|
|
|
vc2010.filterGroup(prj, group, "AntProjectPropertiesFile")
|
|
|
|
end
|
|
|
|
}
|
2015-10-15 13:05:33 +00:00
|
|
|
|
2018-12-06 07:47:55 +00:00
|
|
|
vc2010.categories.JavaCompile = {
|
|
|
|
name = "JavaCompile",
|
|
|
|
priority = 99,
|
|
|
|
|
|
|
|
emitFiles = function(prj, group)
|
|
|
|
vc2010.emitFiles(prj, group, "JavaCompile", {vc2010.generatedFile, android.link})
|
|
|
|
end,
|
|
|
|
|
|
|
|
emitFilter = function(prj, group)
|
|
|
|
vc2010.filterGroup(prj, group, "JavaCompile")
|
|
|
|
end
|
|
|
|
}
|
|
|
|
|
2016-11-15 10:57:43 +00:00
|
|
|
vc2010.categories.Content = {
|
|
|
|
name = "Content",
|
|
|
|
priority = 99,
|
2015-10-15 13:05:33 +00:00
|
|
|
|
2016-11-15 10:57:43 +00:00
|
|
|
emitFiles = function(prj, group)
|
2017-11-01 19:51:35 +00:00
|
|
|
vc2010.emitFiles(prj, group, "Content", {vc2010.generatedFile, android.link})
|
2016-11-15 10:57:43 +00:00
|
|
|
end,
|
2015-10-15 13:05:33 +00:00
|
|
|
|
2016-11-15 10:57:43 +00:00
|
|
|
emitFilter = function(prj, group)
|
|
|
|
vc2010.filterGroup(prj, group, "Content")
|
|
|
|
end
|
|
|
|
}
|
2015-10-15 13:05:33 +00:00
|
|
|
|
2016-11-15 10:57:43 +00:00
|
|
|
premake.override(vc2010, "categorizeFile", function(base, prj, file)
|
|
|
|
if prj.kind ~= p.ANDROIDPROJ then
|
|
|
|
return base(prj, file)
|
|
|
|
end
|
2015-10-15 13:05:33 +00:00
|
|
|
|
2016-11-15 10:57:43 +00:00
|
|
|
local filename = path.getname(file.name):lower()
|
2018-12-06 07:47:55 +00:00
|
|
|
local extension = path.getextension(filename)
|
2015-10-15 13:05:33 +00:00
|
|
|
|
2016-11-15 10:57:43 +00:00
|
|
|
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
|
2018-12-06 07:47:55 +00:00
|
|
|
elseif extension == ".java" then
|
|
|
|
return vc2010.categories.JavaCompile
|
2016-11-15 10:57:43 +00:00
|
|
|
else
|
|
|
|
return vc2010.categories.Content
|
|
|
|
end
|
|
|
|
end)
|