From de03bb324970be63894bce40a1f5911f38101214 Mon Sep 17 00:00:00 2001 From: Sam Surtees Date: Fri, 24 Nov 2017 00:07:26 +1000 Subject: [PATCH] Added defaultplatform support to gmake and gmake2 actions --- modules/gmake/gmake.lua | 22 +++++++++++++++---- .../tests/workspace/test_default_config.lua | 16 ++++++++++++++ modules/gmake2/gmake2.lua | 22 +++++++++++++++---- 3 files changed, 52 insertions(+), 8 deletions(-) diff --git a/modules/gmake/gmake.lua b/modules/gmake/gmake.lua index 218d1641..188bb078 100644 --- a/modules/gmake/gmake.lua +++ b/modules/gmake/gmake.lua @@ -25,13 +25,27 @@ function make.defaultconfig(target) -- find the right configuration iterator function for this object local eachconfig = iif(target.project, project.eachconfig, p.workspace.eachconfig) - local iter = eachconfig(target) + local defaultconfig = nil + + -- find the right default configuration platform, grab first configuration that matches + if target.defaultplatform then + for cfg in eachconfig(target) do + if cfg.platform == target.defaultplatform then + defaultconfig = cfg + break + end + end + end -- grab the first configuration and write the block - local cfg = iter() - if cfg then + if not defaultconfig then + local iter = eachconfig(target) + defaultconfig = iter() + end + + if defaultconfig then _p('ifndef config') - _x(' config=%s', cfg.shortname) + _x(' config=%s', defaultconfig.shortname) _p('endif') _p('') end diff --git a/modules/gmake/tests/workspace/test_default_config.lua b/modules/gmake/tests/workspace/test_default_config.lua index a4bd0a80..3bc5a716 100644 --- a/modules/gmake/tests/workspace/test_default_config.lua +++ b/modules/gmake/tests/workspace/test_default_config.lua @@ -69,3 +69,19 @@ ifndef config endif ]] end + + +-- +-- Verify handling of defaultplatform +-- + + function suite.defaultsToSpecifiedPlatform() + platforms { "Win32", "Win64" } + defaultplatform "Win64" + prepare() + test.capture [[ +ifndef config + config=debug_win64 +endif + ]] + end diff --git a/modules/gmake2/gmake2.lua b/modules/gmake2/gmake2.lua index d66a9513..e9d79e95 100644 --- a/modules/gmake2/gmake2.lua +++ b/modules/gmake2/gmake2.lua @@ -20,13 +20,27 @@ function gmake2.defaultconfig(target) -- find the right configuration iterator function for this object local eachconfig = iif(target.project, project.eachconfig, p.workspace.eachconfig) - local iter = eachconfig(target) + local defaultconfig = nil + + -- find the right default configuration platform, grab first configuration that matches + if target.defaultplatform then + for cfg in eachconfig(target) do + if cfg.platform == target.defaultplatform then + defaultconfig = cfg + break + end + end + end -- grab the first configuration and write the block - local cfg = iter() - if cfg then + if not defaultconfig then + local iter = eachconfig(target) + defaultconfig = iter() + end + + if defaultconfig then _p('ifndef config') - _x(' config=%s', cfg.shortname) + _x(' config=%s', defaultconfig.shortname) _p('endif') _p('') end