From 568a84b1dcdfe5fa10b0ca2511a342ba7b24ea44 Mon Sep 17 00:00:00 2001 From: Patrick Doane Date: Wed, 5 Jul 2017 14:42:50 -0700 Subject: [PATCH 01/20] Update to current conventions (#1) --- _preload.lua | 4 ++++ android.lua | 10 +++++----- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/_preload.lua b/_preload.lua index 63f22d31..2e305413 100644 --- a/_preload.lua +++ b/_preload.lua @@ -118,3 +118,7 @@ "disabled", }, } + + return function(cfg) + return true + end diff --git a/android.lua b/android.lua index fd650684..632459b1 100644 --- a/android.lua +++ b/android.lua @@ -2,11 +2,10 @@ -- -- Create an android namespace to isolate the additions -- - premake.modules.android = {} +local p = premake - local android = premake.modules.android - - include("_preload.lua") +if not p.modules.android then + p.modules.android = {} if _ACTION < "vs2015" then configuration { "Android" } @@ -20,5 +19,6 @@ include("vsandroid_sln2005.lua") include("vsandroid_vstudio.lua") include("vsandroid_androidproj.lua") +end - return android +return p.modules.android From 109f2477d6468c3308d91e7a3f6ea8c5ba5be365 Mon Sep 17 00:00:00 2001 From: Patrick Doane Date: Wed, 5 Jul 2017 14:43:03 -0700 Subject: [PATCH 02/20] Add VS2017 support (#2) --- _preload.lua | 1 + vsandroid_vcxproj.lua | 6 +++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/_preload.lua b/_preload.lua index 2e305413..30f8f940 100644 --- a/_preload.lua +++ b/_preload.lua @@ -22,6 +22,7 @@ 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 }) -- TODO: can I api.addAllowed() a key-value pair? local os = p.fields["os"]; diff --git a/vsandroid_vcxproj.lua b/vsandroid_vcxproj.lua index e48e2de3..330fc4c1 100644 --- a/vsandroid_vcxproj.lua +++ b/vsandroid_vcxproj.lua @@ -51,7 +51,11 @@ _p(2, "%s", cfg.project.name) _p(2, "14.0") _p(2, "Android") - _p(2, "1.0") + if _ACTION >= "vs2017" then + _p(2, "3.0") + else + _p(2, "1.0") + end end -- From 02e0e973ca5992fde83d45b83caac5ca80b7cdc2 Mon Sep 17 00:00:00 2001 From: Patrick Doane Date: Wed, 5 Jul 2017 14:43:11 -0700 Subject: [PATCH 03/20] Fix linker issues (#3) --- vsandroid_vcxproj.lua | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/vsandroid_vcxproj.lua b/vsandroid_vcxproj.lua index 330fc4c1..3e5758f6 100644 --- a/vsandroid_vcxproj.lua +++ b/vsandroid_vcxproj.lua @@ -429,3 +429,44 @@ 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) From f7605c290338ba8cf7566d0ee2d92a2c4e44fccf Mon Sep 17 00:00:00 2001 From: Patrick Doane Date: Wed, 5 Jul 2017 15:54:31 -0700 Subject: [PATCH 04/20] Update RTTI override (#4) - Add missing condition parameter - Use cfg.rtti instead of cfg.flags.NoRTTI --- vsandroid_vcxproj.lua | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/vsandroid_vcxproj.lua b/vsandroid_vcxproj.lua index 3e5758f6..18423195 100644 --- a/vsandroid_vcxproj.lua +++ b/vsandroid_vcxproj.lua @@ -263,14 +263,14 @@ end end) - premake.override(vc2010, "runtimeTypeInfo", function(oldfn, cfg) + premake.override(vc2010, "runtimeTypeInfo", function(oldfn, cfg, condition) if cfg.system == premake.ANDROID then -- Note: Android defaults to 'off' - if not cfg.flags.NoRTTI then - _p(3,'true') + if cfg.rtti then + vc2010.element("RuntimeTypeInfo", condition, "true") end else - oldfn(cfg) + oldfn(cfg, condition) end end) From c30b1cd1bea63870d2eb4465db3200878c0fa866 Mon Sep 17 00:00:00 2001 From: Patrick Doane Date: Wed, 5 Jul 2017 15:54:42 -0700 Subject: [PATCH 05/20] Start of test cases (#5) --- tests/_tests.lua | 5 ++++ tests/test_android_project.lua | 44 ++++++++++++++++++++++++++++++++++ vsandroid_vcxproj.lua | 2 +- 3 files changed, 50 insertions(+), 1 deletion(-) create mode 100644 tests/_tests.lua create mode 100644 tests/test_android_project.lua diff --git a/tests/_tests.lua b/tests/_tests.lua new file mode 100644 index 00000000..3216e962 --- /dev/null +++ b/tests/_tests.lua @@ -0,0 +1,5 @@ +require ("android") + +return { + "test_android_project.lua" +} diff --git a/tests/test_android_project.lua b/tests/test_android_project.lua new file mode 100644 index 00000000..3d094736 --- /dev/null +++ b/tests/test_android_project.lua @@ -0,0 +1,44 @@ + 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.rttiOff() + rtti "Off" + prepare() + test.capture [[ + + NotUsing + Disabled + true +]] + end + + function suite.rttiOn() + rtti "On" + prepare() + test.capture [[ + + NotUsing + Disabled + true + true +]] + end diff --git a/vsandroid_vcxproj.lua b/vsandroid_vcxproj.lua index 18423195..5475037c 100644 --- a/vsandroid_vcxproj.lua +++ b/vsandroid_vcxproj.lua @@ -256,7 +256,7 @@ if cfg.system == premake.ANDROID then -- Note: Android defaults to 'off' if not cfg.flags.NoExceptions then - _p(3,'true') + vc2010.element("GccExceptionHandling", nil, "true") end else oldfn(cfg) From aacdaac0adcfbab7041c159d9a13a8738c27e6bc Mon Sep 17 00:00:00 2001 From: Patrick Doane Date: Mon, 10 Jul 2017 11:29:30 -0700 Subject: [PATCH 06/20] Update Clang version for VS2015 (#6) Clang 3.6 is not installed as part of VS2015 but might have been from an older VS2013 install. --- _preload.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/_preload.lua b/_preload.lua index 30f8f940..5393901a 100644 --- a/_preload.lua +++ b/_preload.lua @@ -59,7 +59,7 @@ kind = "string", allowed = { "4.9", -- NDK GCC versions - "3.6", -- NDK clang versions + "3.8", -- NDK clang versions }, } else From 091794fe6f3363001928de517b964f18b9542f29 Mon Sep 17 00:00:00 2001 From: Patrick Doane Date: Mon, 10 Jul 2017 11:29:40 -0700 Subject: [PATCH 07/20] Fix ApplicationTypeRevision for VS2015 (#7) --- vsandroid_vcxproj.lua | 2 ++ 1 file changed, 2 insertions(+) diff --git a/vsandroid_vcxproj.lua b/vsandroid_vcxproj.lua index 5475037c..6b7a184b 100644 --- a/vsandroid_vcxproj.lua +++ b/vsandroid_vcxproj.lua @@ -53,6 +53,8 @@ _p(2, "Android") if _ACTION >= "vs2017" then _p(2, "3.0") + elseif _ACTION >= "vs2015" then + _p(2, "2.0") else _p(2, "1.0") end From dc3da067004a29cfb86f3b60349018d681819240 Mon Sep 17 00:00:00 2001 From: Patrick Doane Date: Mon, 10 Jul 2017 11:29:59 -0700 Subject: [PATCH 08/20] Add configuration for AndroidAppLibName (#8) Either RootNamespace of AndroidAppLibName needs to be configurable to set up the package. May want to add RootNamespace configuration later as well. --- _preload.lua | 6 ++++++ vsandroid_vcxproj.lua | 10 +++++++--- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/_preload.lua b/_preload.lua index 5393901a..9973f704 100644 --- a/_preload.lua +++ b/_preload.lua @@ -120,6 +120,12 @@ }, } + api.register { + name = "androidapplibname", + scope = "config", + kind = "string" + } + return function(cfg) return true end diff --git a/vsandroid_vcxproj.lua b/vsandroid_vcxproj.lua index 6b7a184b..148182ac 100644 --- a/vsandroid_vcxproj.lua +++ b/vsandroid_vcxproj.lua @@ -304,9 +304,13 @@ end) function android.antPackage(cfg) - _p(2,'') - _p(3,'$(RootNamespace)') - _p(2,'') + p.push('') + if cfg.androidapplibname ~= nil then + vc2010.element("AndroidAppLibName", nil, cfg.androidapplibname) + else + vc2010.element("AndroidAppLibName", nil, "$(RootNamespace)") + end + p.pop('') end function android.antBuild(cfg) From c1a247bd81d8ba23be4ca5534e064664712a99c2 Mon Sep 17 00:00:00 2001 From: Patrick Doane Date: Tue, 11 Jul 2017 09:40:50 -0700 Subject: [PATCH 09/20] Disable override of OutDir to fix deployment (#9) --- vsandroid_vcxproj.lua | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/vsandroid_vcxproj.lua b/vsandroid_vcxproj.lua index 148182ac..55e6fb40 100644 --- a/vsandroid_vcxproj.lua +++ b/vsandroid_vcxproj.lua @@ -476,3 +476,13 @@ 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) From 92e512ab6ab3d5e9051c81127f6717611fc74bfb Mon Sep 17 00:00:00 2001 From: Patrick Doane Date: Tue, 25 Jul 2017 11:39:11 -0700 Subject: [PATCH 10/20] Add cppdialect support --- tests/test_android_project.lua | 39 ++++++++++++++++++++++++++++++ vsandroid_vcxproj.lua | 44 ++++++++++++++++++++++++++++------ 2 files changed, 76 insertions(+), 7 deletions(-) diff --git a/tests/test_android_project.lua b/tests/test_android_project.lua index 3d094736..063ec4d3 100644 --- a/tests/test_android_project.lua +++ b/tests/test_android_project.lua @@ -42,3 +42,42 @@ true ]] end + + function suite.cppdialect_cpp11() + cppdialect "C++11" + prepare() + test.capture [[ + + NotUsing + Disabled + true + true + c++11 +]] + end + + function suite.cppdialect_cpp14() + cppdialect "C++14" + prepare() + test.capture [[ + + NotUsing + Disabled + true + true + c++1y +]] + end + + function suite.cppdialect_cpp17() + cppdialect "C++17" + prepare() + test.capture [[ + + NotUsing + Disabled + true + true + -std=c++1z %(AdditionalOptions) +]] + end diff --git a/vsandroid_vcxproj.lua b/vsandroid_vcxproj.lua index 55e6fb40..dc387cca 100644 --- a/vsandroid_vcxproj.lua +++ b/vsandroid_vcxproj.lua @@ -200,9 +200,6 @@ 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 @@ -240,11 +237,44 @@ -- end end - function android.cppStandard(cfg) - if cfg.flags["C++11"] then - _p(3, 'c++11') + 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 cfg.cppdialect ~= nil and cpp_langmap[cfg.cppdialect] ~= nil then + vc2010.element("CppLanguageStandard", nil, cpp_langmap[cfg.cppdialect]) + end + else + oldfn(cfg) end - end + end) + + p.override(vc2010, "additionalCompileOptions", function(oldfn, cfg, condition) + if cfg.system == p.ANDROID then + local opts = cfg.buildoptions + if cfg.cppdialect ~= nil then + 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 + 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 From 28305cc4c781fac291a2ad1e49510135abb08a2d Mon Sep 17 00:00:00 2001 From: Patrick Doane Date: Tue, 25 Jul 2017 13:29:15 -0700 Subject: [PATCH 11/20] Remove extra nil checks --- vsandroid_vcxproj.lua | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/vsandroid_vcxproj.lua b/vsandroid_vcxproj.lua index dc387cca..a006e870 100644 --- a/vsandroid_vcxproj.lua +++ b/vsandroid_vcxproj.lua @@ -247,7 +247,7 @@ ["gnu++11"] = "gnu++11", ["gnu++14"] = "gnu++1y", } - if cfg.cppdialect ~= nil and cpp_langmap[cfg.cppdialect] ~= nil then + if cpp_langmap[cfg.cppdialect] ~= nil then vc2010.element("CppLanguageStandard", nil, cpp_langmap[cfg.cppdialect]) end else @@ -258,15 +258,15 @@ p.override(vc2010, "additionalCompileOptions", function(oldfn, cfg, condition) if cfg.system == p.ANDROID then local opts = cfg.buildoptions - if cfg.cppdialect ~= nil then - 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 + + 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) From ca9453c6ca8b9b144b000fb85e8d36c0b4aceb30 Mon Sep 17 00:00:00 2001 From: Patrick Doane Date: Tue, 25 Jul 2017 15:18:10 -0700 Subject: [PATCH 12/20] Fix exception handling (#11) --- tests/test_android_project.lua | 41 +++++++++++++++++++++++++++++----- vsandroid_vcxproj.lua | 22 +++++++++++++----- 2 files changed, 53 insertions(+), 10 deletions(-) diff --git a/tests/test_android_project.lua b/tests/test_android_project.lua index 063ec4d3..de96fbcd 100644 --- a/tests/test_android_project.lua +++ b/tests/test_android_project.lua @@ -20,6 +20,15 @@ vc2010.clCompile(cfg) end + function suite.noOptions() + prepare() + test.capture [[ + + NotUsing + Disabled +]] + end + function suite.rttiOff() rtti "Off" prepare() @@ -27,7 +36,7 @@ NotUsing Disabled - true + Enabled ]] end @@ -38,7 +47,29 @@ NotUsing Disabled - true + Enabled + true +]] + end + + function suite.exceptionHandlingOff() + exceptionhandling "Off" + prepare() + test.capture [[ + + NotUsing + Disabled +]] + end + + function suite.exceptionHandlingOn() + exceptionhandling "On" + prepare() + test.capture [[ + + NotUsing + Disabled + Enabled true ]] end @@ -50,7 +81,7 @@ NotUsing Disabled - true + Enabled true c++11 ]] @@ -63,7 +94,7 @@ NotUsing Disabled - true + Enabled true c++1y ]] @@ -76,7 +107,7 @@ NotUsing Disabled - true + Enabled true -std=c++1z %(AdditionalOptions) ]] diff --git a/vsandroid_vcxproj.lua b/vsandroid_vcxproj.lua index a006e870..8fef6d29 100644 --- a/vsandroid_vcxproj.lua +++ b/vsandroid_vcxproj.lua @@ -284,14 +284,26 @@ end end) - premake.override(vc2010, "exceptionHandling", function(oldfn, cfg) - if cfg.system == premake.ANDROID then + 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 not cfg.flags.NoExceptions then - vc2010.element("GccExceptionHandling", nil, "true") + if cfg.exceptionhandling then + if _ACTION >= "vs2015" then + vc2010.element("ExceptionHandling", condition, "Enabled") + else + vc2010.element("GccExceptionHandling", condition, "true") + end end else - oldfn(cfg) + oldfn(cfg, condition) end end) From cc3b49f6d879e161d64f94d61c19c557292ce104 Mon Sep 17 00:00:00 2001 From: Tom van Dijck Date: Mon, 31 Jul 2017 16:44:44 -0700 Subject: [PATCH 13/20] Fix insertion of allows "os" options. --- _preload.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/_preload.lua b/_preload.lua index 9973f704..fd16bac9 100644 --- a/_preload.lua +++ b/_preload.lua @@ -25,9 +25,9 @@ premake.action._list["vs2017"].valid_kinds = table.join(premake.action._list["vs2017"].valid_kinds, { p.ANDROIDPROJ }) -- TODO: can I api.addAllowed() a key-value pair? - local os = p.fields["os"]; + local os = p.option.get("os") if os ~= nil then - table.insert(sys.allowed, { "android", "Android" }) + table.insert(os.allowed, { "android", "Android" }) end From ab6cd204aafe70deec19ed6774c48849ad654643 Mon Sep 17 00:00:00 2001 From: Tom van Dijck Date: Thu, 3 Aug 2017 17:41:24 -0700 Subject: [PATCH 14/20] add tags for android system. --- _preload.lua | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/_preload.lua b/_preload.lua index fd16bac9..4e7ec55f 100644 --- a/_preload.lua +++ b/_preload.lua @@ -24,12 +24,13 @@ 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 }) - -- TODO: can I api.addAllowed() a key-value pair? local os = p.option.get("os") if os ~= nil then table.insert(os.allowed, { "android", "Android" }) end + -- add system tags for android. + os.systemTags[p.ANDROID] = { "android", "mobile" } -- -- Register Android properties From 406095855aa39250abd2afee756aa5986b474732 Mon Sep 17 00:00:00 2001 From: Tom van Dijck Date: Thu, 3 Aug 2017 17:49:41 -0700 Subject: [PATCH 15/20] os is reserved name :( --- _preload.lua | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/_preload.lua b/_preload.lua index 4e7ec55f..8a38ece8 100644 --- a/_preload.lua +++ b/_preload.lua @@ -24,9 +24,9 @@ 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 os = p.option.get("os") - if os ~= nil then - table.insert(os.allowed, { "android", "Android" }) + local osoption = p.option.get("os") + if osoption ~= nil then + table.insert(osoption.allowed, { "android", "Android" }) end -- add system tags for android. From 9ef5bfa3f57e50e6327806a53cb0ef60a6d9d572 Mon Sep 17 00:00:00 2001 From: Tom van Dijck Date: Tue, 8 Aug 2017 11:48:29 -0700 Subject: [PATCH 16/20] argument is the project, not a config. --- vsandroid_vcxproj.lua | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/vsandroid_vcxproj.lua b/vsandroid_vcxproj.lua index 8fef6d29..bad50864 100644 --- a/vsandroid_vcxproj.lua +++ b/vsandroid_vcxproj.lua @@ -31,10 +31,10 @@ -- -- Extend global properties -- - premake.override(vc2010.elements, "globals", function (oldfn, cfg) - local elements = oldfn(cfg) + premake.override(vc2010.elements, "globals", function (oldfn, prj) + local elements = oldfn(prj) - if cfg.system == premake.ANDROID and cfg.kind ~= premake.ANDROIDPROJ then + if prj.system == premake.ANDROID and prj.kind ~= premake.ANDROIDPROJ then -- Remove "IgnoreWarnCompileDuplicatedFilename". local pos = table.indexof(elements, vc2010.ignoreWarnDuplicateFilename) table.remove(elements, pos) From d3ee9a47a044a591d35c8b62347b00d8365f9264 Mon Sep 17 00:00:00 2001 From: Tom van Dijck Date: Thu, 10 Aug 2017 11:51:48 -0700 Subject: [PATCH 17/20] fix nil dereference in _preload.lua, also unify some options. --- _preload.lua | 86 ++++++++++++++++--------------------------- vsandroid_vcxproj.lua | 39 +++++++------------- 2 files changed, 45 insertions(+), 80 deletions(-) diff --git a/_preload.lua b/_preload.lua index 8a38ece8..bd93af49 100644 --- a/_preload.lua +++ b/_preload.lua @@ -53,62 +53,38 @@ kind = "integer", } - if _ACTION >= "vs2015" then - api.register { - name = "toolchainversion", - scope = "config", - kind = "string", - allowed = { - "4.9", -- NDK GCC versions - "3.8", -- 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 + 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", + }, + } - 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", + 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", diff --git a/vsandroid_vcxproj.lua b/vsandroid_vcxproj.lua index bad50864..4749ade2 100644 --- a/vsandroid_vcxproj.lua +++ b/vsandroid_vcxproj.lua @@ -89,34 +89,23 @@ 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 - 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,'%s', 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,'%s', stl[cfg.stl]) + _p(2,'%s', stlType[cfg.stl]) end end end From c863674d1f2a1a8fc77c95a6d774d88961aea947 Mon Sep 17 00:00:00 2001 From: Tom van Dijck Date: Tue, 29 Aug 2017 12:08:39 -0700 Subject: [PATCH 18/20] flip default to clang and deal with platformToolset better. --- vsandroid_vcxproj.lua | 96 +++++++++++++++++++++++++------------------ 1 file changed, 57 insertions(+), 39 deletions(-) diff --git a/vsandroid_vcxproj.lua b/vsandroid_vcxproj.lua index 4749ade2..abf899f8 100644 --- a/vsandroid_vcxproj.lua +++ b/vsandroid_vcxproj.lua @@ -124,49 +124,67 @@ -- Note: this function is already patched in by vs2012... premake.override(vc2010, "platformToolset", function(oldfn, cfg) - if cfg.system == premake.ANDROID then - if _ACTION >= "vs2015" then - if cfg.toolchainversion ~= nil then - _p(2,'%s_%s', 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" + if cfg.system ~= premake.ANDROID then + return oldfn(cfg) + end - 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 _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", + } - 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,'%s', toolset .. version) - _p(2,'%s', archMap[arch]) - end + 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, "%s", ts) else - oldfn(cfg) + 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,'%s', toolset .. version) + _p(2,'%s', archMap[arch]) + end end end) From 0b479a50f5c5f741f503b9caaf0765b317b29267 Mon Sep 17 00:00:00 2001 From: Tom van Dijck Date: Wed, 1 Nov 2017 12:51:35 -0700 Subject: [PATCH 19/20] Add linking support for externally referenced files. --- vsandroid_androidproj.lua | 34 ++++++++++++++++++++++++++-------- 1 file changed, 26 insertions(+), 8 deletions(-) diff --git a/vsandroid_androidproj.lua b/vsandroid_androidproj.lua index d2e07e61..fae0efdf 100644 --- a/vsandroid_androidproj.lua +++ b/vsandroid_androidproj.lua @@ -151,17 +151,35 @@ 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) + + -- 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) - local fileCfgFunc = { - android.manifestSubType, - } - - vc2010.emitFiles(prj, group, "AndroidManifest", {vc2010.generatedFile}, fileCfgFunc) + vc2010.emitFiles(prj, group, "AndroidManifest", {vc2010.generatedFile, android.link, android.manifestSubType}) end, emitFilter = function(prj, group) @@ -178,7 +196,7 @@ priority = 99, emitFiles = function(prj, group) - vc2010.emitFiles(prj, group, "AntBuildXml", {vc2010.generatedFile}) + vc2010.emitFiles(prj, group, "AntBuildXml", {vc2010.generatedFile, android.link}) end, emitFilter = function(prj, group) @@ -191,7 +209,7 @@ priority = 99, emitFiles = function(prj, group) - vc2010.emitFiles(prj, group, "AntProjectPropertiesFile", {vc2010.generatedFile}) + vc2010.emitFiles(prj, group, "AntProjectPropertiesFile", {vc2010.generatedFile, android.link}) end, emitFilter = function(prj, group) @@ -204,7 +222,7 @@ priority = 99, emitFiles = function(prj, group) - vc2010.emitFiles(prj, group, "Content", {vc2010.generatedFile}) + vc2010.emitFiles(prj, group, "Content", {vc2010.generatedFile, android.link}) end, emitFilter = function(prj, group) From 4ef3fff58cd0e4eedc00a4d1a9118442a5c4e3a1 Mon Sep 17 00:00:00 2001 From: Tom van Dijck Date: Tue, 14 Nov 2017 10:15:49 -0800 Subject: [PATCH 20/20] Fix for external files when using absolute paths on windows. --- vsandroid_androidproj.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vsandroid_androidproj.lua b/vsandroid_androidproj.lua index fae0efdf..60920183 100644 --- a/vsandroid_androidproj.lua +++ b/vsandroid_androidproj.lua @@ -159,7 +159,7 @@ -- leading "../" sequences and, if found, remove them and mark this -- path as external. local link, count = fname:gsub("%.%.%/", "") - local external = (count > 0) + 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