From 79f453a285d260483eff7026156725d56969aecb Mon Sep 17 00:00:00 2001 From: Jason Perkins Date: Wed, 16 Dec 2015 16:25:37 -0500 Subject: [PATCH] Emit element to fix LNK4068 warnings in Visual Studio 2010+ --- src/actions/vstudio/vs2010_vcxproj.lua | 18 ++++ tests/_tests.lua | 1 + .../vstudio/vc2010/test_target_machine.lua | 87 +++++++++++++++++++ 3 files changed, 106 insertions(+) create mode 100644 tests/actions/vstudio/vc2010/test_target_machine.lua diff --git a/src/actions/vstudio/vs2010_vcxproj.lua b/src/actions/vstudio/vs2010_vcxproj.lua index a353f514..f639f998 100644 --- a/src/actions/vstudio/vs2010_vcxproj.lua +++ b/src/actions/vstudio/vs2010_vcxproj.lua @@ -406,6 +406,7 @@ m.treatLinkerWarningAsErrors, m.ignoreDefaultLibraries, m.largeAddressAware, + m.targetMachine, m.additionalLinkOptions, } end @@ -430,6 +431,7 @@ if cfg.kind == p.STATICLIB then return { m.treatLinkerWarningAsErrors, + m.targetMachine, m.additionalLinkOptions, } else @@ -1765,6 +1767,22 @@ end + function m.targetMachine(cfg) + -- If a static library project contains a resource file, VS will choke with + -- "LINK : warning LNK4068: /MACHINE not specified; defaulting to X86" + local targetmachine = { + x86 = "MachineX86", + x86_64 = "MachineX64", + } + if cfg.kind == p.STATICLIB then + local value = targetmachine[cfg.architecture] + if value ~= nil then + m.element("TargetMachine", nil, '%s', value) + end + end + end + + function m.targetName(cfg) m.element("TargetName", nil, "%s%s", cfg.buildtarget.prefix, cfg.buildtarget.basename) end diff --git a/tests/_tests.lua b/tests/_tests.lua index c315a5eb..413d9b6e 100644 --- a/tests/_tests.lua +++ b/tests/_tests.lua @@ -129,6 +129,7 @@ return { "actions/vstudio/vc2010/test_prop_sheet.lua", "actions/vstudio/vc2010/test_resource_compile.lua", "actions/vstudio/vc2010/test_rule_vars.lua", + "actions/vstudio/vc2010/test_target_machine.lua", "actions/vstudio/vc2010/test_user_file.lua", "actions/vstudio/vc2010/test_vectorextensions.lua", diff --git a/tests/actions/vstudio/vc2010/test_target_machine.lua b/tests/actions/vstudio/vc2010/test_target_machine.lua new file mode 100644 index 00000000..641061c1 --- /dev/null +++ b/tests/actions/vstudio/vc2010/test_target_machine.lua @@ -0,0 +1,87 @@ +--- +-- tests/actions/vstudio/vc2010/test_target_machine.lua +-- Validate generation of the element +-- Copyright (c) 2015 Jason Perkins and the Premake project +--- + + local suite = test.declare("vstudio_vs2010_target_machine") + local vc2010 = premake.vstudio.vc2010 + + +-- +-- Setup +-- + + local wks, prj + + function suite.setup() + wks, prj = test.createWorkspace() + end + + local function prepare(platform) + local cfg = test.getconfig(prj, "Debug", platform) + vc2010.targetMachine(cfg) + end + + + +-- +-- Emit if a static lib project contains a resource file and an +-- architecture is specified. +-- + + function suite.emitsOnStaticLibWithX86() + kind "StaticLib" + architecture "x86" + prepare() + test.capture [[ +MachineX86 + ]] + end + + function suite.emitsOnStaticLibWithX86_64() + kind "StaticLib" + architecture "x86_64" + prepare() + test.capture [[ +MachineX64 + ]] + end + + + +-- +-- Other combinations should NOT emit anything +-- + + function suite.isIgnoredOnConsoleAppNoArch() + kind "ConsoleApp" + prepare() + test.isemptycapture() + end + + function suite.isIgnoredOnConsoleAppWithX86() + kind "ConsoleApp" + architecture "x86" + prepare() + test.isemptycapture() + end + + function suite.isIgnoredOnStaticLibNoArch() + kind "StaticLib" + prepare() + test.isemptycapture() + end + + function suite.isIgnoredOnSharedLibNoArch() + kind "SharedLib" + prepare() + test.isemptycapture() + end + + function suite.isIgnoredOnSharedLibWithX86() + kind "SharedLib" + architecture "x86" + prepare() + test.isemptycapture() + end