Added very basic vs2015 support

This commit is contained in:
Sam Surtees 2015-10-15 23:05:33 +10:00
parent 9c5dd76db0
commit 7d499b812f
7 changed files with 607 additions and 139 deletions

View File

@ -2,4 +2,7 @@ return {
"_preload.lua",
"android.lua",
"vsandroid_vcxproj.lua",
"vsandroid_sln2005.lua",
"vsandroid_vstudio.lua",
"vsandroid_androidproj.lua",
}

View File

@ -13,11 +13,13 @@
--
p.ANDROID = "android"
p.ANDROIDPROJ = "androidproj"
api.addAllowed("system", p.ANDROID)
api.addAllowed("architecture", { "armv5", "armv7", "aarach64", "mips", "mips64" })
api.addAllowed("architecture", { "armv5", "armv7", "aarach64", "mips", "mips64", "arm" })
api.addAllowed("vectorextensions", { "NEON", "MXU" })
api.addAllowed("flags", { "Thumb" })
api.addAllowed("kind", p.ANDROIDPROJ)
-- TODO: can I api.addAllowed() a key-value pair?
local os = p.fields["os"];
@ -47,27 +49,70 @@
kind = "integer",
}
api.register {
name = "toolchainversion",
scope = "config",
kind = "string",
allowed = {
"4.6", -- NDK GCC versions
"4.8",
"4.9",
"3.4", -- NDK clang versions
"3.5",
},
}
if _ACTION >= "vs2015" then
api.register {
name = "toolchainversion",
scope = "config",
kind = "string",
allowed = {
"4.9", -- NDK GCC versions
"3.6", -- NDK clang versions
},
}
else
api.register {
name = "toolchainversion",
scope = "config",
kind = "string",
allowed = {
"4.6", -- NDK GCC versions
"4.8",
"4.9",
"3.4", -- NDK clang versions
"3.5",
"3.6",
},
}
end
if _ACTION >= "vs2015" then
api.register {
name = "stl",
scope = "config",
kind = "string",
allowed = {
"minimal c++ (system)",
"c++ static",
"c++ shared",
"stlport static",
"stlport shared",
"gnu stl static",
"gnu stl shared",
"llvm libc++ static",
"llvm libc++ shared",
},
}
else
api.register {
name = "stl",
scope = "config",
kind = "string",
allowed = {
"none",
"minimal",
"stdc++",
"stlport",
},
}
end
api.register {
name = "stl",
name = "thumbmode",
scope = "config",
kind = "string",
allowed = {
"none",
"minimal",
"stdc++",
"stlport",
"thumb",
"arm",
"disabled",
},
}

View File

@ -8,12 +8,17 @@
include("_preload.lua")
configuration { "Android" }
system "android"
toolset "gcc"
if _ACTION < "vs2015" then
configuration { "Android" }
system "android"
toolset "gcc"
end
-- TODO: configure Android debug environment...
include("vsandroid_vcxproj.lua")
include("vsandroid_sln2005.lua")
include("vsandroid_vstudio.lua")
include("vsandroid_androidproj.lua")
return android

245
vsandroid_androidproj.lua Normal file
View File

@ -0,0 +1,245 @@
--
-- 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 {
vc2010.outDir,
}
else
return oldfn(cfg)
end
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)
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 "AndroidManifest"
elseif filename == "build.xml" then
return "AntBuildXml"
elseif filename == "project.properties" then
return "AntProjectPropertiesFile"
else
return "Content"
end
end)
premake.override(vc2010.elements, "files", function(base, prj, groups)
local elements = base(prj, groups)
elements = table.join(elements, {
android.androidmanifestFiles,
android.antbuildxmlFiles,
android.antprojectpropertiesfileFiles,
android.contentFiles,
})
return elements
end)
function android.androidmanifestFiles(prj, groups)
vc2010.emitFiles(prj, groups, "AndroidManifest")
end
function vc2010.elements.AndroidManifestFile(cfg, file)
return {
android.manifestSubType,
}
end
function vc2010.elements.AndroidManifestFileCfg(fcfg, condition)
return {}
end
function android.manifestSubType(cfg, file)
vc2010.element("SubType", nil, "Designer")
end
function android.antbuildxmlFiles(prj, groups)
vc2010.emitFiles(prj, groups, "AntBuildXml")
end
function vc2010.elements.AntBuildXmlFile(cfg, file)
return {}
end
function vc2010.elements.AntBuildXmlFileCfg(fcfg, condition)
return {}
end
function android.antprojectpropertiesfileFiles(prj, groups)
vc2010.emitFiles(prj, groups, "AntProjectPropertiesFile")
end
function vc2010.elements.AntProjectPropertiesFileFile(cfg, file)
return {}
end
function vc2010.elements.AntProjectPropertiesFileFileCfg(fcfg, condition)
return {}
end
function android.contentFiles(prj, groups)
vc2010.emitFiles(prj, groups, "Content")
end
function vc2010.elements.ContentFile(cfg, file)
return {}
end
function vc2010.elements.ContentFileCfg(fcfg, condition)
return {}
end

36
vsandroid_sln2005.lua Normal file
View File

@ -0,0 +1,36 @@
--
-- android/vsandroid_sln2005.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 sln2005 = p.vstudio.sln2005
--
-- Add android tools to vstudio actions.
--
premake.override(sln2005.elements, "projectConfigurationPlatforms", function(oldfn, cfg, context)
local elements = oldfn(cfg, context)
if cfg.system == premake.ANDROID and _ACTION >= "vs2015" then
elements = table.join(elements, {
android.deployProject
})
end
return elements
end)
function android.deployProject(cfg, context)
if context.prjCfg.kind == p.ANDROIDPROJ and _ACTION >= "vs2015" then
p.w('{%s}.%s.Deploy.0 = %s|%s', context.prj.uuid, context.descriptor, context.platform, context.architecture)
end
end

View File

@ -10,7 +10,6 @@
local android = p.modules.android
local vsandroid = p.modules.vsandroid
local sln2005 = p.vstudio.sln2005
local vc2010 = p.vstudio.vc2010
local vstudio = p.vstudio
local project = p.project
@ -22,9 +21,38 @@
--
if vstudio.vs2010_architectures ~= nil then
vstudio.vs2010_architectures.android = "Android"
if _ACTION >= "vs2015" then
vstudio.vs2010_architectures.arm = "ARM"
else
vstudio.vs2010_architectures.android = "Android"
end
end
--
-- Extend global properties
--
premake.override(vc2010.elements, "globals", function (oldfn, cfg)
local elements = oldfn(cfg)
if cfg.system == premake.ANDROID and cfg.kind ~= premake.ANDROIDPROJ then
-- Remove "IgnoreWarnCompileDuplicatedFilename".
local pos = table.indexof(elements, vc2010.ignoreWarnDuplicateFilename)
table.remove(elements, pos)
elements = table.join(elements, {
android.androidApplicationType
})
end
return elements
end)
function android.androidApplicationType(cfg)
_p(2, "<Keyword>Android</Keyword>")
_p(2, "<RootNamespace>%s</RootNamespace>", cfg.project.name)
_p(2, "<MinimumVisualStudioVersion>14.0</MinimumVisualStudioVersion>")
_p(2, "<ApplicationType>Android</ApplicationType>")
_p(2, "<ApplicationTypeRevision>1.0</ApplicationTypeRevision>")
end
--
-- Extend configurationProperties.
@ -32,11 +60,17 @@
premake.override(vc2010.elements, "configurationProperties", function(oldfn, cfg)
local elements = oldfn(cfg)
if cfg.kind ~= p.UTILITY and cfg.system == premake.ANDROID then
if cfg.kind ~= p.UTILITY and cfg.kind ~= p.ANDROIDPROJ and cfg.system == premake.ANDROID then
elements = table.join(elements, {
android.androidAPILevel,
android.androidStlType,
})
if _ACTION >= "vs2015" then
elements = table.join(elements, {
android.thumbMode,
})
end
end
return elements
end)
@ -49,59 +83,92 @@
function android.androidStlType(cfg)
if cfg.stl ~= nil then
local static = {
none = "none",
minimal = "system",
["stdc++"] = "gnustl_static",
stlport = "stlport_static",
if _ACTION >= "vs2015" then
local stlType = {
["minimal c++ (system)"] = "system",
["c++ static"] = "gabi++_static",
["c++ shared"] = "gabi++_shared",
["stlport static"] = "stlport_static",
["stlport shared"] = "stlport_shared",
["gnu stl static"] = "gnustl_static",
["gnu stl shared"] = "gnustl_shared",
["llvm libc++ static"] = "c++_static",
["llvm libc++ shared"] = "c++_shared",
}
_p(2,'<UseOfStl>%s</UseOfStl>', stlType[cfg.stl])
else
local static = {
none = "none",
minimal = "system",
["stdc++"] = "gnustl_static",
stlport = "stlport_static",
}
local dynamic = {
none = "none",
minimal = "system",
["stdc++"] = "gnustl_dynamic",
stlport = "stlport_dynamic",
}
local stl = iif(cfg.flags.StaticRuntime, static, dynamic);
_p(2,'<AndroidStlType>%s</AndroidStlType>', stl[cfg.stl])
end
end
end
function android.thumbMode(cfg)
if cfg.thumbmode then
local thumbMode =
{
thumb = "Thumb",
arm = "ARM",
disabled = "Disabled",
}
local dynamic = {
none = "none",
minimal = "system",
["stdc++"] = "gnustl_dynamic",
stlport = "stlport_dynamic",
}
local stl = iif(cfg.flags.StaticRuntime, static, dynamic);
_p(2,'<AndroidStlType>%s</AndroidStlType>', stl[cfg.stl])
_p(2,"<ThumbMode>%s</ThumbMode>", thumbMode[cfg.thumbmode])
end
end
-- Note: this function is already patched in by vs2012...
premake.override(vc2010, "platformToolset", function(oldfn, cfg)
if cfg.system == premake.ANDROID then
local archMap = {
arm = "armv5te", -- should arm5 be default? vs-android thinks so...
arm5 = "armv5te",
arm7 = "armv7-a",
mips = "mips",
x86 = "x86",
}
local arch = cfg.architecture or "arm"
if (cfg.architecture ~= nil or cfg.toolchainversion ~= nil) and archMap[arch] ~= nil then
local defaultToolsetMap = {
arm = "arm-linux-androideabi-",
armv5 = "arm-linux-androideabi-",
armv7 = "arm-linux-androideabi-",
aarch64 = "aarch64-linux-android-",
mips = "mipsel-linux-android-",
mips64 = "mips64el-linux-android-",
x86 = "x86-",
x86_64 = "x86_64-",
}
local toolset = defaultToolsetMap[arch]
if cfg.toolset == "clang" then
error("The clang toolset is not yet supported by vs-android", 2)
toolset = toolset .. "clang"
elseif cfg.toolset and cfg.toolset ~= "gcc" then
error("Toolset not supported by the android NDK: " .. cfg.toolset, 2)
if _ACTION >= "vs2015" then
if cfg.toolchainversion ~= nil then
_p(2,'<PlatformToolset>%s_%s</PlatformToolset>', iif(cfg.toolset == "clang", "Clang", "GCC"), string.gsub(cfg.toolchainversion, "%.", "_"))
end
else
local archMap = {
arm = "armv5te", -- should arm5 be default? vs-android thinks so...
arm5 = "armv5te",
arm7 = "armv7-a",
mips = "mips",
x86 = "x86",
}
local arch = cfg.architecture or "arm"
local version = cfg.toolchainversion or iif(cfg.toolset == "clang", "3.5", "4.9")
if (cfg.architecture ~= nil or cfg.toolchainversion ~= nil) and archMap[arch] ~= nil then
local defaultToolsetMap = {
arm = "arm-linux-androideabi-",
armv5 = "arm-linux-androideabi-",
armv7 = "arm-linux-androideabi-",
aarch64 = "aarch64-linux-android-",
mips = "mipsel-linux-android-",
mips64 = "mips64el-linux-android-",
x86 = "x86-",
x86_64 = "x86_64-",
}
local toolset = defaultToolsetMap[arch]
_p(2,'<PlatformToolset>%s</PlatformToolset>', toolset .. version)
_p(2,'<AndroidArch>%s</AndroidArch>', archMap[arch])
if cfg.toolset == "clang" then
error("The clang toolset is not yet supported by vs-android", 2)
toolset = toolset .. "clang"
elseif cfg.toolset and cfg.toolset ~= "gcc" then
error("Toolset not supported by the android NDK: " .. cfg.toolset, 2)
end
local version = cfg.toolchainversion or iif(cfg.toolset == "clang", "3.5", "4.9")
_p(2,'<PlatformToolset>%s</PlatformToolset>', toolset .. version)
_p(2,'<AndroidArch>%s</AndroidArch>', archMap[arch])
end
end
else
oldfn(cfg)
@ -124,6 +191,13 @@
android.pic,
-- android.ShortEnums,
})
if _ACTION >= "vs2015" then
table.remove(elements, table.indexof(elements, vc2010.debugInformationFormat))
table.remove(elements, table.indexof(elements, android.thumbMode))
elements = table.join(elements, {
android.cppStandard,
})
end
end
return elements
end)
@ -160,6 +234,12 @@
-- end
end
function android.cppStandard(cfg)
if cfg.flags["C++11"] then
_p(3, '<CppLanguageStandard>c++11</CppLanguageStandard>')
end
end
premake.override(vc2010, "exceptionHandling", function(oldfn, cfg)
if cfg.system == premake.ANDROID then
-- Note: Android defaults to 'off'
@ -201,7 +281,7 @@
premake.override(vc2010.elements, "itemDefinitionGroup", function(oldfn, cfg)
local elements = oldfn(cfg)
if cfg.system == premake.ANDROID then
if cfg.system == premake.ANDROID and _ACTION < "vs2015" then
elements = table.join(elements, {
android.antBuild,
})
@ -209,6 +289,12 @@
return elements
end)
function android.antPackage(cfg)
_p(2,'<AntPackage>')
_p(3,'<AndroidAppLibName>$(RootNamespace)</AndroidAppLibName>')
_p(2,'</AntPackage>')
end
function android.antBuild(cfg)
if cfg.kind == premake.STATICLIB or cfg.kind == premake.SHAREDLIB then
return
@ -226,98 +312,108 @@
return oldfn(cfg, condition)
end)
premake.override(vc2010.elements, "user", function(oldfn, cfg)
if cfg.system == p.ANDROID then
return {}
else
return oldfn(cfg)
end
end)
--
-- Add options unsupported by vs-android UI to <AdvancedOptions>.
--
function vsandroid.additionalOptions(cfg)
if _ACTION >= "vs2015" then
local function alreadyHas(t, key)
for _, k in ipairs(t) do
if string.find(k, key) then
return true
else
local function alreadyHas(t, key)
for _, k in ipairs(t) do
if string.find(k, key) then
return true
end
end
return false
end
return false
end
if not cfg.architecture or string.startswith(cfg.architecture, "arm") then
-- we might want to define the arch to generate better code
-- if not alreadyHas(cfg.buildoptions, "-march=") then
-- if cfg.architecture == "armv6" then
-- table.insert(cfg.buildoptions, "-march=armv6")
-- elseif cfg.architecture == "armv7" then
-- table.insert(cfg.buildoptions, "-march=armv7")
if not cfg.architecture or string.startswith(cfg.architecture, "arm") then
-- we might want to define the arch to generate better code
-- if not alreadyHas(cfg.buildoptions, "-march=") then
-- if cfg.architecture == "armv6" then
-- table.insert(cfg.buildoptions, "-march=armv6")
-- elseif cfg.architecture == "armv7" then
-- table.insert(cfg.buildoptions, "-march=armv7")
-- end
-- end
-- end
-- ARM has a comprehensive set of floating point options
if cfg.fpu ~= "Software" and cfg.floatabi ~= "soft" then
-- ARM has a comprehensive set of floating point options
if cfg.fpu ~= "Software" and cfg.floatabi ~= "soft" then
if cfg.architecture == "armv7" then
if cfg.architecture == "armv7" then
-- armv7 always has VFP, may not have NEON
-- armv7 always has VFP, may not have NEON
if not alreadyHas(cfg.buildoptions, "-mfpu=") then
if cfg.vectorextensions == "NEON" then
table.insert(cfg.buildoptions, "-mfpu=neon")
elseif cfg.fpu == "Hardware" or cfg.floatabi == "softfp" or cfg.floatabi == "hard" then
table.insert(cfg.buildoptions, "-mfpu=vfpv3-d16") -- d16 is the lowest common denominator
if not alreadyHas(cfg.buildoptions, "-mfpu=") then
if cfg.vectorextensions == "NEON" then
table.insert(cfg.buildoptions, "-mfpu=neon")
elseif cfg.fpu == "Hardware" or cfg.floatabi == "softfp" or cfg.floatabi == "hard" then
table.insert(cfg.buildoptions, "-mfpu=vfpv3-d16") -- d16 is the lowest common denominator
end
end
if not alreadyHas(cfg.buildoptions, "-mfloat-abi=") then
if cfg.floatabi == "hard" then
table.insert(cfg.buildoptions, "-mfloat-abi=hard")
else
-- Android should probably use softfp by default for compatibility
table.insert(cfg.buildoptions, "-mfloat-abi=softfp")
end
end
else
-- armv5/6 may not have VFP
if not alreadyHas(cfg.buildoptions, "-mfpu=") then
if cfg.fpu == "Hardware" or cfg.floatabi == "softfp" or cfg.floatabi == "hard" then
table.insert(cfg.buildoptions, "-mfpu=vfp")
end
end
if not alreadyHas(cfg.buildoptions, "-mfloat-abi=") then
if cfg.floatabi == "softfp" then
table.insert(cfg.buildoptions, "-mfloat-abi=softfp")
elseif cfg.floatabi == "hard" then
table.insert(cfg.buildoptions, "-mfloat-abi=hard")
end
end
end
if not alreadyHas(cfg.buildoptions, "-mfloat-abi=") then
if cfg.floatabi == "hard" then
table.insert(cfg.buildoptions, "-mfloat-abi=hard")
else
-- Android should probably use softfp by default for compatibility
table.insert(cfg.buildoptions, "-mfloat-abi=softfp")
end
end
elseif cfg.floatabi == "soft" then
else
-- armv5/6 may not have VFP
if not alreadyHas(cfg.buildoptions, "-mfpu=") then
if cfg.fpu == "Hardware" or cfg.floatabi == "softfp" or cfg.floatabi == "hard" then
table.insert(cfg.buildoptions, "-mfpu=vfp")
end
end
if not alreadyHas(cfg.buildoptions, "-mfloat-abi=") then
if cfg.floatabi == "softfp" then
table.insert(cfg.buildoptions, "-mfloat-abi=softfp")
elseif cfg.floatabi == "hard" then
table.insert(cfg.buildoptions, "-mfloat-abi=hard")
end
end
table.insert(cfg.buildoptions, "-mfloat-abi=soft")
end
elseif cfg.floatabi == "soft" then
if cfg.endian == "Little" then
table.insert(cfg.buildoptions, "-mlittle-endian")
elseif cfg.endian == "Big" then
table.insert(cfg.buildoptions, "-mbig-endian")
end
table.insert(cfg.buildoptions, "-mfloat-abi=soft")
elseif cfg.architecture == "mips" then
-- TODO...
if cfg.vectorextensions == "MXU" then
table.insert(cfg.buildoptions, "-mmxu")
end
elseif cfg.architecture == "x86" then
-- TODO...
end
if cfg.endian == "Little" then
table.insert(cfg.buildoptions, "-mlittle-endian")
elseif cfg.endian == "Big" then
table.insert(cfg.buildoptions, "-mbig-endian")
end
elseif cfg.architecture == "mips" then
-- TODO...
if cfg.vectorextensions == "MXU" then
table.insert(cfg.buildoptions, "-mmxu")
end
elseif cfg.architecture == "x86" then
-- TODO...
end
end

38
vsandroid_vstudio.lua Normal file
View File

@ -0,0 +1,38 @@
--
-- android/vsandroid_vstudio.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 vstudio = p.vstudio
--
-- Add android tools to vstudio actions.
--
premake.override(vstudio, "solutionPlatform", function (oldfn, cfg)
local platform = oldfn(cfg)
-- Bypass that pesky Win32 hack
if cfg.system == premake.ANDROID and _ACTION >= "vs2015" then
if cfg.platform == "x86" then
platform = "x86"
end
end
return platform
end)
premake.override(vstudio, "archFromConfig", function (oldfn, cfg, win32)
-- Bypass that pesky Win32 hack by not passing win32 down
if cfg.system == premake.ANDROID and _ACTION >= "vs2015" then
return oldfn(cfg)
end
return oldfn(cfg, win32)
end)