Add 'modules/android/' from premake-android

- Additional changes to get tests working
This commit is contained in:
Sam Surtees 2018-04-05 20:56:55 +10:00
commit f7626d4e2a
12 changed files with 1157 additions and 0 deletions

View File

@ -0,0 +1,27 @@
Copyright (c) 2013-2015 Manu Evans and individual contributors.
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. Neither the name of Premake nor the names of its contributors may be
used to endorse or promote products derived from this software without
specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

View File

@ -0,0 +1,9 @@
# Premake Extension to support Android NDK projects
Supported features:
* VisualStudio support through [vs-android](https://code.google.com/p/vs-android/)
Todo:
* gmake support

View File

@ -0,0 +1,8 @@
return {
"_preload.lua",
"android.lua",
"vsandroid_vcxproj.lua",
"vsandroid_sln2005.lua",
"vsandroid_vstudio.lua",
"vsandroid_androidproj.lua",
}

View File

@ -0,0 +1,108 @@
--
-- Name: android/_preload.lua
-- Purpose: Define the Android API's.
-- Author: Manu Evans
-- Copyright: (c) 2013-2015 Manu Evans and the Premake project
--
local p = premake
local api = p.api
--
-- Register the Android extension
--
p.ANDROID = "android"
p.ANDROIDPROJ = "androidproj"
api.addAllowed("system", p.ANDROID)
api.addAllowed("architecture", { "armv5", "armv7", "aarach64", "mips", "mips64", "arm" })
api.addAllowed("vectorextensions", { "NEON", "MXU" })
api.addAllowed("flags", { "Thumb" })
api.addAllowed("kind", p.ANDROIDPROJ)
premake.action._list["vs2015"].valid_kinds = table.join(premake.action._list["vs2015"].valid_kinds, { p.ANDROIDPROJ })
premake.action._list["vs2017"].valid_kinds = table.join(premake.action._list["vs2017"].valid_kinds, { p.ANDROIDPROJ })
local osoption = p.option.get("os")
if osoption ~= nil then
table.insert(osoption.allowed, { "android", "Android" })
end
-- add system tags for android.
os.systemTags[p.ANDROID] = { "android", "mobile" }
--
-- Register Android properties
--
api.register {
name = "floatabi",
scope = "config",
kind = "string",
allowed = {
"soft",
"softfp",
"hard",
},
}
api.register {
name = "androidapilevel",
scope = "config",
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",
"3.6",
"3.8",
},
}
api.register {
name = "stl",
scope = "config",
kind = "string",
allowed = {
"none",
"minimal c++ (system)",
"c++ static",
"c++ shared",
"stlport static",
"stlport shared",
"gnu stl static",
"gnu stl shared",
"llvm libc++ static",
"llvm libc++ shared",
},
}
api.register {
name = "thumbmode",
scope = "config",
kind = "string",
allowed = {
"thumb",
"arm",
"disabled",
},
}
api.register {
name = "androidapplibname",
scope = "config",
kind = "string"
}
return function(cfg)
return (cfg.system == p.ANDROID)
end

View File

@ -0,0 +1,25 @@
--
-- Create an android namespace to isolate the additions
--
local p = premake
if not p.modules.android then
require ("vstudio")
p.modules.android = {}
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")
end
return p.modules.android

View File

@ -0,0 +1,5 @@
require ("android")
return {
"test_android_project.lua"
}

View File

@ -0,0 +1,114 @@
local p = premake
local suite = test.declare("test_android_project")
local vc2010 = p.vstudio.vc2010
--
-- Setup
--
local wks, prj
function suite.setup()
p.action.set("vs2015")
wks, prj = test.createWorkspace()
end
local function prepare()
system "android"
local cfg = test.getconfig(prj, "Debug", platform)
vc2010.clCompile(cfg)
end
function suite.noOptions()
prepare()
test.capture [[
<ClCompile>
<PrecompiledHeader>NotUsing</PrecompiledHeader>
<Optimization>Disabled</Optimization>
</ClCompile>]]
end
function suite.rttiOff()
rtti "Off"
prepare()
test.capture [[
<ClCompile>
<PrecompiledHeader>NotUsing</PrecompiledHeader>
<Optimization>Disabled</Optimization>
<ExceptionHandling>Enabled</ExceptionHandling>
</ClCompile>]]
end
function suite.rttiOn()
rtti "On"
prepare()
test.capture [[
<ClCompile>
<PrecompiledHeader>NotUsing</PrecompiledHeader>
<Optimization>Disabled</Optimization>
<ExceptionHandling>Enabled</ExceptionHandling>
<RuntimeTypeInfo>true</RuntimeTypeInfo>
]]
end
function suite.exceptionHandlingOff()
exceptionhandling "Off"
prepare()
test.capture [[
<ClCompile>
<PrecompiledHeader>NotUsing</PrecompiledHeader>
<Optimization>Disabled</Optimization>
</ClCompile>]]
end
function suite.exceptionHandlingOn()
exceptionhandling "On"
prepare()
test.capture [[
<ClCompile>
<PrecompiledHeader>NotUsing</PrecompiledHeader>
<Optimization>Disabled</Optimization>
<ExceptionHandling>Enabled</ExceptionHandling>
<RuntimeTypeInfo>true</RuntimeTypeInfo>
]]
end
function suite.cppdialect_cpp11()
cppdialect "C++11"
prepare()
test.capture [[
<ClCompile>
<PrecompiledHeader>NotUsing</PrecompiledHeader>
<Optimization>Disabled</Optimization>
<ExceptionHandling>Enabled</ExceptionHandling>
<RuntimeTypeInfo>true</RuntimeTypeInfo>
<CppLanguageStandard>c++11</CppLanguageStandard>
]]
end
function suite.cppdialect_cpp14()
cppdialect "C++14"
prepare()
test.capture [[
<ClCompile>
<PrecompiledHeader>NotUsing</PrecompiledHeader>
<Optimization>Disabled</Optimization>
<ExceptionHandling>Enabled</ExceptionHandling>
<RuntimeTypeInfo>true</RuntimeTypeInfo>
<CppLanguageStandard>c++1y</CppLanguageStandard>
]]
end
function suite.cppdialect_cpp17()
cppdialect "C++17"
prepare()
test.capture [[
<ClCompile>
<PrecompiledHeader>NotUsing</PrecompiledHeader>
<Optimization>Disabled</Optimization>
<ExceptionHandling>Enabled</ExceptionHandling>
<RuntimeTypeInfo>true</RuntimeTypeInfo>
<AdditionalOptions>-std=c++1z %(AdditionalOptions)</AdditionalOptions>
]]
end

View File

@ -0,0 +1,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)

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

@ -0,0 +1,537 @@
--
-- android/vsandroid_vcxproj.lua
-- vs-android integration for vstudio.
-- Copyright (c) 2012-2015 Manu Evans and the Premake project
--
local p = premake
p.modules.vsandroid = { }
local android = p.modules.android
local vsandroid = p.modules.vsandroid
local vc2010 = p.vstudio.vc2010
local vstudio = p.vstudio
local project = p.project
local config = p.config
--
-- Add android tools to vstudio actions.
--
if vstudio.vs2010_architectures ~= nil then
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, prj)
local elements = oldfn(prj)
if prj.system == premake.ANDROID and prj.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>")
if _ACTION >= "vs2017" then
_p(2, "<ApplicationTypeRevision>3.0</ApplicationTypeRevision>")
elseif _ACTION >= "vs2015" then
_p(2, "<ApplicationTypeRevision>2.0</ApplicationTypeRevision>")
else
_p(2, "<ApplicationTypeRevision>1.0</ApplicationTypeRevision>")
end
end
--
-- Extend configurationProperties.
--
premake.override(vc2010.elements, "configurationProperties", function(oldfn, cfg)
local elements = oldfn(cfg)
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)
function android.androidAPILevel(cfg)
if cfg.androidapilevel ~= nil then
_p(2,'<AndroidAPILevel>android-%d</AndroidAPILevel>', cfg.androidapilevel)
end
end
function android.androidStlType(cfg)
if cfg.stl ~= nil then
local stlType = {
["none"] = "none",
["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",
}
if _ACTION >= "vs2015" then
_p(2,'<UseOfStl>%s</UseOfStl>', stlType[cfg.stl])
else
_p(2,'<AndroidStlType>%s</AndroidStlType>', stlType[cfg.stl])
end
end
end
function android.thumbMode(cfg)
if cfg.thumbmode then
local thumbMode =
{
thumb = "Thumb",
arm = "ARM",
disabled = "Disabled",
}
_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
return oldfn(cfg)
end
if _ACTION >= "vs2015" then
local gcc_map = {
["_"] = "GCC_4_9", -- default
["4.6"] = "GCC_4_6",
["4.8"] = "GCC_4_8",
["4.9"] = "GCC_4_9",
}
local clang_map = {
["_"] = "Clang_3_8", -- default
["3.4"] = "Clang_3_4",
["3.5"] = "Clang_3_5",
["3.6"] = "Clang_3_6",
["3.8"] = "Clang_3_8",
}
local map = iif(cfg.toolset == "gcc", gcc_map, clang_map)
local ts = map[cfg.toolchainversion or "_"]
if ts == nil then
p.error('Invalid toolchainversion for the selected toolset (%s).', cfg.toolset or "clang")
end
_p(2, "<PlatformToolset>%s</PlatformToolset>", ts)
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"
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)
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
end)
--
-- Extend clCompile.
--
premake.override(vc2010.elements, "clCompile", function(oldfn, cfg)
local elements = oldfn(cfg)
if cfg.system == premake.ANDROID then
elements = table.join(elements, {
android.debugInformation,
android.strictAliasing,
android.thumbMode,
android.fpu,
android.pic,
-- android.ShortEnums,
})
if _ACTION >= "vs2015" then
table.remove(elements, table.indexof(elements, vc2010.debugInformationFormat))
table.remove(elements, table.indexof(elements, android.thumbMode))
end
end
return elements
end)
function android.debugInformation(cfg)
if cfg.flags.Symbols then
_p(3,'<GenerateDebugInformation>true</GenerateDebugInformation>')
end
end
function android.strictAliasing(cfg)
if cfg.strictaliasing ~= nil then
_p(3,'<StrictAliasing>%s</StrictAliasing>', iif(cfg.strictaliasing == "Off", "false", "true"))
end
end
function android.thumbMode(cfg)
if cfg.flags.Thumb then
_p(3,'<ThumbMode>true</ThumbMode>')
end
end
function android.fpu(cfg)
if cfg.fpu ~= nil then
_p(3,'<SoftFloat>true</SoftFloat>', iif(cfg.fpu == "Software", "true", "false"))
end
end
function android.pic(cfg)
-- TODO: We only have a flag to turn it on, but android is on by default
-- it seems we would rather have a flag to turn it off...
-- if cfg.pic ~= nil then
-- _p(3,'<PositionIndependentCode>%s</PositionIndependentCode>', iif(cfg.pic == "On", "true", "false"))
-- end
end
p.override(vc2010, "languageStandard", function(oldfn, cfg)
if cfg.system == p.ANDROID then
local cpp_langmap = {
["C++98"] = "c++98",
["C++11"] = "c++11",
["C++14"] = "c++1y",
["gnu++98"] = "gnu++98",
["gnu++11"] = "gnu++11",
["gnu++14"] = "gnu++1y",
}
if cpp_langmap[cfg.cppdialect] ~= nil then
vc2010.element("CppLanguageStandard", nil, cpp_langmap[cfg.cppdialect])
end
else
oldfn(cfg)
end
end)
p.override(vc2010, "additionalCompileOptions", function(oldfn, cfg, condition)
if cfg.system == p.ANDROID then
local opts = cfg.buildoptions
local cpp_langmap = {
["C++17"] = "-std=c++1z",
["gnu++17"] = "-std=gnu++1z",
}
if cpp_langmap[cfg.cppdialect] ~= nil then
table.insert(opts, cpp_langmap[cfg.cppdialect])
end
if #opts > 0 then
opts = table.concat(opts, " ")
vc2010.element("AdditionalOptions", condition, '%s %%(AdditionalOptions)', opts)
end
else
oldfn(cfg, condition)
end
end)
p.override(p.vstudio.vc2010, "warningLevel", function(oldfn, cfg)
if _ACTION >= "vs2015" and cfg.system == p.ANDROID and cfg.warnings and cfg.warnings ~= "Off" then
p.vstudio.vc2010.element("WarningLevel", nil, "EnableAllWarnings")
elseif (_ACTION >= "vs2015" and cfg.system == p.ANDROID and cfg.warnings) or not (_ACTION >= "vs2015" and cfg.system == p.ANDROID) then
oldfn(cfg)
end
end)
premake.override(vc2010, "clCompilePreprocessorDefinitions", function(oldfn, cfg, condition)
if cfg.system == p.ANDROID then
vc2010.preprocessorDefinitions(cfg, cfg.defines, false, condition)
else
oldfn(cfg, condition)
end
end)
premake.override(vc2010, "exceptionHandling", function(oldfn, cfg, condition)
if cfg.system == p.ANDROID then
-- Note: Android defaults to 'off'
if cfg.exceptionhandling then
if _ACTION >= "vs2015" then
vc2010.element("ExceptionHandling", condition, "Enabled")
else
vc2010.element("GccExceptionHandling", condition, "true")
end
end
else
oldfn(cfg, condition)
end
end)
premake.override(vc2010, "runtimeTypeInfo", function(oldfn, cfg, condition)
if cfg.system == premake.ANDROID then
-- Note: Android defaults to 'off'
if cfg.rtti then
vc2010.element("RuntimeTypeInfo", condition, "true")
end
else
oldfn(cfg, condition)
end
end)
--
-- Extend Link.
--
premake.override(vc2010, "generateDebugInformation", function(oldfn, cfg)
-- Note: Android specifies the debug info in the clCompile section
if cfg.system ~= premake.ANDROID then
oldfn(cfg)
end
end)
--
-- Add android tools to vstudio actions.
--
premake.override(vc2010.elements, "itemDefinitionGroup", function(oldfn, cfg)
local elements = oldfn(cfg)
if cfg.system == premake.ANDROID and _ACTION < "vs2015" then
elements = table.join(elements, {
android.antBuild,
})
end
return elements
end)
function android.antPackage(cfg)
p.push('<AntPackage>')
if cfg.androidapplibname ~= nil then
vc2010.element("AndroidAppLibName", nil, cfg.androidapplibname)
else
vc2010.element("AndroidAppLibName", nil, "$(RootNamespace)")
end
p.pop('</AntPackage>')
end
function android.antBuild(cfg)
if cfg.kind == premake.STATICLIB or cfg.kind == premake.SHAREDLIB then
return
end
_p(2,'<AntBuild>')
_p(3,'<AntBuildType>%s</AntBuildType>', iif(premake.config.isDebugBuild(cfg), "Debug", "Release"))
_p(2,'</AntBuild>')
end
premake.override(vc2010, "additionalCompileOptions", function(oldfn, cfg, condition)
if cfg.system == premake.ANDROID then
vsandroid.additionalOptions(cfg, condition)
end
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
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
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
-- ARM has a comprehensive set of floating point options
if cfg.fpu ~= "Software" and cfg.floatabi ~= "soft" then
if cfg.architecture == "armv7" then
-- 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
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
elseif cfg.floatabi == "soft" then
table.insert(cfg.buildoptions, "-mfloat-abi=soft")
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
end
--
-- Disable subsystem.
--
p.override(vc2010, "subSystem", function(oldfn, cfg)
if cfg.system ~= p.ANDROID then
return oldfn(cfg)
end
end)
--
-- Remove .lib and list in LibraryDependencies instead of AdditionalDependencies.
--
p.override(vc2010, "additionalDependencies", function(oldfn, cfg, explicit)
if cfg.system == p.ANDROID then
local links = {}
-- If we need sibling projects to be listed explicitly, grab them first
if explicit then
links = config.getlinks(cfg, "siblings", "fullpath")
end
-- Then the system libraries, which come undecorated
local system = config.getlinks(cfg, "system", "name")
for i = 1, #system do
local link = system[i]
table.insert(links, link)
end
-- TODO: When to use LibraryDependencies vs AdditionalDependencies
if #links > 0 then
links = path.translate(table.concat(links, ";"))
vc2010.element("LibraryDependencies", nil, "%%(LibraryDependencies);%s", links)
end
else
return oldfn(cfg, explicit)
end
end)
--
-- Disable override of OutDir. This is breaking deployment.
--
p.override(vc2010, "outDir", function(oldfn, cfg)
if cfg.system ~= p.ANDROID then
return oldfn(cfg)
end
end)

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)

View File

@ -11,4 +11,5 @@
"codelite",
"gmake2",
"d",
"android",
}