Improved handling of linker defaults in VS2010

This commit is contained in:
Jason Perkins 2011-11-13 15:07:31 -05:00
parent 2a8b81ac8d
commit b0b881284e
7 changed files with 275 additions and 209 deletions

View File

@ -40,6 +40,7 @@
* Patch 3381066: Fix VS2010 project references
* Added debug environment variable support for Visual Studio
* Added debug environment variable support for Codeblocks using gdb
* Bug: Visual Studio 2010 forces x86 when platform is Native
-------

View File

@ -353,7 +353,7 @@
end
local function link_target_machine(index,cfg)
local platforms = {x32 = 'MachineX86',Native = 'MachineX86', x64 = 'MachineX64'}
local platforms = {x32 = 'MachineX86', x64 = 'MachineX64'}
if platforms[cfg.platform] then
_p(index,'<TargetMachine>%s</TargetMachine>', platforms[cfg.platform])
end
@ -380,42 +380,28 @@
end
local function common_link_section(cfg)
_p(3,'<SubSystem>%s</SubSystem>',iif(cfg.kind == "ConsoleApp","Console", "Windows"))
--
-- Generate the <Link> element and its children.
--
if cfg.flags.Symbols then
_p(3,'<GenerateDebugInformation>true</GenerateDebugInformation>')
else
_p(3,'<GenerateDebugInformation>false</GenerateDebugInformation>')
end
function vc2010.link(cfg)
_p(2,'<Link>')
_p(3,'<SubSystem>%s</SubSystem>', iif(cfg.kind == "ConsoleApp", "Console", "Windows"))
_p(3,'<GenerateDebugInformation>%s</GenerateDebugInformation>', tostring(cfg.flags.Symbols ~= nil))
if premake.config.isoptimizedbuild(cfg.flags) then
_p(3,'<OptimizeReferences>true</OptimizeReferences>')
_p(3,'<EnableCOMDATFolding>true</EnableCOMDATFolding>')
_p(3,'<OptimizeReferences>true</OptimizeReferences>')
end
end
function vc2010.additionalDependencies(cfg)
local links = premake.getlinks(cfg, "system", "fullpath")
if #links > 0 then
_p(3,'<AdditionalDependencies>%s;%%(AdditionalDependencies)</AdditionalDependencies>',
table.concat(links, ";"))
end
end
local function item_link(cfg)
_p(2,'<Link>')
if cfg.kind ~= 'StaticLib' then
vc2010.additionalDependencies(cfg)
_p(3,'<OutputFile>$(OutDir)%s</OutputFile>', cfg.buildtarget.name)
_p(3,'<AdditionalLibraryDirectories>%s%s%%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>',
table.concat(premake.esc(path.translate(cfg.libdirs, '\\')) , ";"),
iif(cfg.libdirs and #cfg.libdirs > 0,';',''))
common_link_section(cfg)
if #cfg.libdirs > 0 then
_p(3,'<AdditionalLibraryDirectories>%s;%%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>',
premake.esc(path.translate(table.concat(cfg.libdirs, ';'), '\\')))
end
if vc2010.config_type(cfg) == 'Application' and not cfg.flags.WinMain and not cfg.flags.Managed then
_p(3,'<EntryPointSymbol>mainCRTStartup</EntryPointSymbol>')
@ -424,14 +410,27 @@
import_lib(cfg)
link_target_machine(3,cfg)
additional_options(3,cfg)
else
common_link_section(cfg)
end
_p(2,'</Link>')
end
--
-- Generate the <Link/AdditionalDependencies> element, which links in system
-- libraries required by the project (but not sibling projects; that's handled
-- by an <ItemGroup/ProjectReference>).
--
function vc2010.additionalDependencies(cfg)
local links = premake.getlinks(cfg, "system", "fullpath")
if #links > 0 then
_p(3,'<AdditionalDependencies>%s;%%(AdditionalDependencies)</AdditionalDependencies>',
table.concat(links, ";"))
end
end
local function item_definitions(prj)
for _, cfginfo in ipairs(prj.solution.vstudio_configs) do
local cfg = premake.getconfig(prj, cfginfo.src_buildcfg, cfginfo.src_platform)
@ -440,7 +439,7 @@
vs10_clcompile(cfg)
resource_compile(cfg)
item_def_lib(cfg)
item_link(cfg)
vc2010.link(cfg)
event_hooks(cfg)
_p(1,'</ItemDefinitionGroup>')

View File

@ -1,143 +0,0 @@
T.vs2010_links = { }
local vs10_links = T.vs2010_links
local sln, prj
function vs10_links.setup()
_ACTION = "vs2010"
sln = solution "MySolution"
configurations { "Debug" }
platforms {}
prj = project "MyProject"
language "C++"
kind "ConsoleApp"
uuid "AE61726D-187C-E440-BD07-2556188A6565"
end
local function get_buffer()
premake.bake.buildconfigs()
sln.vstudio_configs = premake.vstudio.buildconfigs(sln)
prj = premake.solution.getproject(sln, 1)
premake.vs2010_vcxproj(prj)
buffer = io.endcapture()
return buffer
end
function vs10_links.hasLinkBlock()
local buffer = get_buffer()
test.string_contains(buffer,'<Link>.*</Link>')
end
function vs10_links.additionalDependancies_isInsideLinkBlock()
configuration("Debug")
links{"link_test"}
local buffer = get_buffer()
test.string_contains(buffer,
'<Link>.*<AdditionalDependencies>.*%%%(AdditionalDependencies%)</AdditionalDependencies>.*</Link>')
end
function vs10_links.additionalDependancies_containsLinkTestDotLib()
configuration("Debug")
links{"link_test"}
local buffer = get_buffer()
test.string_contains(buffer,
'<AdditionalDependencies>link_test%.lib;%%%(AdditionalDependencies%)</AdditionalDependencies>')
end
function vs10_links.outPutFile_isEqualToOutDirMyProjectDotExe()
local buffer = get_buffer()
test.string_contains(buffer,'<OutputFile>%$%(OutDir%)MyProject.exe</OutputFile>')
end
function vs10_links.additionalLibraryDirectories_inputNoDirectories_tagsAreEmpty()
local buffer = get_buffer()
test.string_contains(buffer,
'<AdditionalLibraryDirectories>%%%(AdditionalLibraryDirectories%)</AdditionalLibraryDirectories>')
end
function vs10_links.additionalLibraryDirectories_inputTestPath_tagsContainExspectedValue()
configuration("Debug")
libdirs { "test_path" }
local buffer = get_buffer()
local exspect = "test_path;"
test.string_contains(buffer,
'<AdditionalLibraryDirectories>'..exspect..'%%%(AdditionalLibraryDirectories%)</AdditionalLibraryDirectories>')
end
function vs10_links.additionalLibraryDirectories_inputTwoPaths_tagsContainExspectedValue()
configuration("Debug")
libdirs { "test_path","another_path" }
local buffer = get_buffer()
local exspect = "test_path;another_path;"
test.string_contains(buffer,
'<AdditionalLibraryDirectories>'..exspect..'%%%(AdditionalLibraryDirectories%)</AdditionalLibraryDirectories>')
end
function vs10_links.generateDebugInformation_withoutSymbolsFlag_valueInTagsIsFalse()
local buffer = get_buffer()
test.string_contains(buffer,'<GenerateDebugInformation>false</GenerateDebugInformation>')
end
function vs10_links.generateDebugInformation_withSymbolsFlag_valueInTagsIsTrue()
flags {"Symbols"}
local buffer = get_buffer()
test.string_contains(buffer,'<GenerateDebugInformation>true</GenerateDebugInformation>')
end
function vs10_links.noOptimiseFlag_optimizeReferences_isNotInBuffer()
local buffer = get_buffer()
test.string_does_not_contain(buffer,'OptimizeReferences')
end
function vs10_links.noOptimiseFlag_enableCOMDATFolding_isNotInBuffer()
local buffer = get_buffer()
test.string_does_not_contain(buffer,'EnableCOMDATFolding')
end
function vs10_links.optimiseFlag_optimizeReferences_valueInsideTagsIsTrue()
flags{"Optimize"}
local buffer = get_buffer()
test.string_contains(buffer,'<OptimizeReferences>true</OptimizeReferences>')
end
function vs10_links.noOptimiseFlag_enableCOMDATFolding_valueInsideTagsIsTrue()
flags{"Optimize"}
local buffer = get_buffer()
test.string_contains(buffer,'EnableCOMDATFolding>true</EnableCOMDATFolding')
end
function vs10_links.entryPointSymbol_noWimMainFlag_valueInTagsIsMainCrtStartUp()
local buffer = get_buffer()
test.string_contains(buffer,'<EntryPointSymbol>mainCRTStartup</EntryPointSymbol>')
end
function vs10_links.entryPointSymbol_noWimMainFlag_valueInTagsIsMainCrtStartUp()
local buffer = get_buffer()
test.string_contains(buffer,'<EntryPointSymbol>mainCRTStartup</EntryPointSymbol>')
end
function vs10_links.entryPointSymbol_winMainFlag_doesNotContainEntryPointSymbol()
flags{"WinMain"}
local buffer = get_buffer()
test.string_does_not_contain(buffer,'<EntryPointSymbol>')
end
function vs10_links.targetMachine_default_valueInTagsIsMachineX86()
local buffer = get_buffer()
test.string_contains(buffer,'<TargetMachine>MachineX86</TargetMachine>')
end
function vs10_links.targetMachine_x32_valueInTagsIsMachineX64()
platforms {"x32"}
local buffer = get_buffer()
test.string_contains(buffer,'<TargetMachine>MachineX86</TargetMachine>')
end
function vs10_links.targetMachine_x64_valueInTagsIsMachineX64()
platforms {"x64"}
local buffer = get_buffer()
test.string_contains(buffer,'<TargetMachine>MachineX64</TargetMachine>')
end

View File

@ -8,12 +8,12 @@
sln = solution "MySolution"
configurations { "Debug" }
platforms {}
prj = project "MyProject"
language "C++"
end
local function get_buffer()
local function get_buffer(platform)
premake.bake.buildconfigs()
sln.vstudio_configs = premake.vstudio.buildconfigs(sln)
prj = premake.solution.getproject(sln, 1)
@ -22,7 +22,7 @@
return buffer
end
function vs10_project_kinds.staticLib_containsLibSection()
kind "StaticLib"
local buffer = get_buffer()
@ -34,7 +34,7 @@
test.string_contains(buffer,'<Lib>.*<OutputFile>.*MyProject.lib.*</OutputFile>.*</Lib>')
end
function vs10_project_kinds.staticLib_valueInMinimalRebuildIsTrue()
kind "StaticLib"
flags {"Symbols"}
@ -64,7 +64,7 @@
local buffer = get_buffer()
test.string_contains(buffer,'<Link>.*<ImportLibrary>.*</ImportLibrary>.*</Link>')
end
function vs10_project_kinds.sharedLib_bufferContainsImportLibrary()
kind "SharedLib"
local buffer = get_buffer()
@ -83,58 +83,58 @@
local buffer = get_buffer()
test.string_contains(buffer,'<PropertyGroup>.*<IgnoreImportLibrary.*</IgnoreImportLibrary>.*</PropertyGroup>')
end
function vs10_project_kinds.sharedLib_withNoImportLibraryFlag_propertyGroupSectionContainsIgnoreImportLibrary()
kind "SharedLib"
flags{"NoImportLib"}
local buffer = get_buffer()
test.string_contains(buffer,'<PropertyGroup>.*<IgnoreImportLibrary.*</IgnoreImportLibrary>.*</PropertyGroup>')
end
function vs10_project_kinds.sharedLib_withOutNoImportLibraryFlag_ignoreImportLibraryValueIsFalse()
kind "SharedLib"
local buffer = get_buffer()
test.string_contains(buffer,'<PropertyGroup>.*<IgnoreImportLibrary.*false</IgnoreImportLibrary>.*</PropertyGroup>')
end
function vs10_project_kinds.sharedLib_withNoImportLibraryFlag_ignoreImportLibraryValueIsTrue()
kind "SharedLib"
flags{"NoImportLib"}
local buffer = get_buffer()
test.string_contains(buffer,'<PropertyGroup>.*<IgnoreImportLibrary.*true</IgnoreImportLibrary>.*</PropertyGroup>')
end
function vs10_project_kinds.staticLib_doesNotContainLinkIncremental()
kind "StaticLib"
local buffer = get_buffer()
test.string_does_not_contain(buffer,'<LinkIncremental.*</LinkIncremental>')
end
function vs10_project_kinds.sharedLib_withoutOptimisation_linkIncrementalValueIsTrue()
kind "SharedLib"
local buffer = get_buffer()
test.string_contains(buffer,'<LinkIncremental.*true</LinkIncremental>')
end
function vs10_project_kinds.sharedLib_withOptimisation_linkIncrementalValueIsFalse()
kind "SharedLib"
flags{"Optimize"}
local buffer = get_buffer()
test.string_contains(buffer,'<LinkIncremental.*false</LinkIncremental>')
end
function vs10_project_kinds.kindDoesNotMatter_noAdditionalDirectoriesSpecified_bufferDoesNotContainAdditionalIncludeDirectories()
kind "SharedLib"
local buffer = get_buffer()
test.string_does_not_contain(buffer,'<ClCompile>.*<AdditionalIncludeDirectories>.*</ClCompile>')
end
function vs10_project_kinds.configType_configIsWindowedApp_resultComparesEqualToApplication()
local t = { kind = "WindowedApp"}
local result = premake.vstudio.vc2010.config_type(t)
test.isequal('Application',result)
end
function vs10_project_kinds.linkOptions_staticLib_bufferContainsAdditionalOptionsInSideLibTag()
kind "StaticLib"
linkoptions{'/dummyOption'}
@ -142,33 +142,33 @@
test.string_contains(get_buffer(),
'<AdditionalOptions>.*%%%(AdditionalOptions%)</AdditionalOptions>.*</Lib>')
end
function vs10_project_kinds.noLinkOptions_staticLib_bufferDoesNotContainAdditionalOptionsInSideLibTag()
kind "StaticLib"
test.string_does_not_contain(get_buffer(),
'<AdditionalOptions>.*%%%(AdditionalOptions%)</AdditionalOptions>.*</Lib>')
end
end
function vs10_project_kinds.linkOptions_staticLib_bufferContainsPassedOption()
kind "StaticLib"
linkoptions{'/dummyOption'}
test.string_contains(get_buffer(),
'<AdditionalOptions>/dummyOption %%%(AdditionalOptions%)</AdditionalOptions>.*</Lib>')
end
end
function vs10_project_kinds.linkOptions_windowedApp_bufferContainsAdditionalOptionsInSideLinkTag()
kind "WindowedApp"
linkoptions{'/dummyOption'}
test.string_contains(get_buffer(),
'<AdditionalOptions>.* %%%(AdditionalOptions%)</AdditionalOptions>.*</Link>')
end
end
function vs10_project_kinds.linkOptions_consoleApp_bufferContainsAdditionalOptionsInSideLinkTag()
kind "ConsoleApp"
linkoptions{'/dummyOption'}
test.string_contains(get_buffer(),
'<AdditionalOptions>.* %%%(AdditionalOptions%)</AdditionalOptions>.*</Link>')
end
@ -176,12 +176,12 @@
function vs10_project_kinds.linkOptions_sharedLib_bufferContainsAdditionalOptionsInSideLinkTag()
kind "SharedLib"
linkoptions{'/dummyOption'}
test.string_contains(get_buffer(),
'<AdditionalOptions>.* %%%(AdditionalOptions%)</AdditionalOptions>.*</Link>')
end
end
function vs10_project_kinds.staticLibX64_TargetMachineSetInLib()
kind "StaticLib"
platforms{'x64'}
@ -209,10 +209,3 @@
local buffer = get_buffer()
test.string_contains(buffer,'<Lib>.*<TargetMachine>MachineX86</TargetMachine>.*</Lib>')
end
function vs10_project_kinds.staticLibNative_TargetMachineInLibSetToMachineX86()
kind "StaticLib"
platforms{'Native'}
local buffer = get_buffer()
test.string_contains(buffer,'<Lib>.*<TargetMachine>MachineX86</TargetMachine>.*</Lib>')
end

View File

@ -0,0 +1,210 @@
--
-- tests/actions/vstudio/vc2010/test_link_settings.lua
-- Validate linker settings in Visual Studio 2010 C/C++ projects.
-- Copyright (c) 2011 Jason Perkins and the Premake project
--
T.vstudio_vs2010_link_settings = { }
local suite = T.vstudio_vs2010_link_settings
local vc2010 = premake.vstudio.vc2010
--
-- Setup
--
local sln, prj, cfg
function suite.setup()
_ACTION = "vs2010"
sln, prj = test.createsolution()
end
local function prepare(platform)
premake.bake.buildconfigs()
sln.vstudio_configs = premake.vstudio.buildconfigs(sln)
cfg = premake.getconfig(prj, "Debug", platform)
vc2010.link(cfg)
end
--
-- Check the basic element structure for a console application.
--
function suite.writesCorrectSubsystem_onConsoleApp()
kind "ConsoleApp"
prepare()
test.capture [[
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>false</GenerateDebugInformation>
<OutputFile>$(OutDir)MyProject.exe</OutputFile>
<EntryPointSymbol>mainCRTStartup</EntryPointSymbol>
</Link>
]]
end
--
-- Check the basic element structure for a windowed application.
--
function suite.writesCorrectSubsystem_onWindowedApp()
kind "WindowedApp"
prepare()
test.capture [[
<Link>
<SubSystem>Windows</SubSystem>
<GenerateDebugInformation>false</GenerateDebugInformation>
<OutputFile>$(OutDir)MyProject.exe</OutputFile>
<EntryPointSymbol>mainCRTStartup</EntryPointSymbol>
</Link>
]]
end
--
-- Check the basic element structure for a shared library.
--
function suite.writesCorrectSubsystem_onSharedLib()
kind "SharedLib"
prepare()
test.capture [[
<Link>
<SubSystem>Windows</SubSystem>
<GenerateDebugInformation>false</GenerateDebugInformation>
<OutputFile>$(OutDir)MyProject.dll</OutputFile>
<ImportLibrary>MyProject.lib</ImportLibrary>
</Link>
]]
end
--
-- Check the basic element structure for a static library.
--
function suite.writesCorrectSubsystem_onStaticLib()
kind "StaticLib"
prepare()
test.capture [[
<Link>
<SubSystem>Windows</SubSystem>
<GenerateDebugInformation>false</GenerateDebugInformation>
</Link>
]]
end
--
-- Check the structure of the additional library directories element.
--
function suite.additionalLibraryDirectories()
libdirs { "include/GL", "include/lua" }
prepare()
test.capture [[
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>false</GenerateDebugInformation>
<OutputFile>$(OutDir)MyProject.exe</OutputFile>
<AdditionalLibraryDirectories>include\GL;include\lua;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<EntryPointSymbol>mainCRTStartup</EntryPointSymbol>
</Link>
]]
end
--
-- Enable debug information if the Symbols flag is specified.
--
function suite.generateDebugInformation_onSymbolsFlag()
flags { "Symbols" }
prepare()
test.capture [[
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<OutputFile>$(OutDir)MyProject.exe</OutputFile>
<EntryPointSymbol>mainCRTStartup</EntryPointSymbol>
</Link>
]]
end
--
-- Enable reference optimizing if Optimize flag is specified.
--
function suite.optimizeReferences_onOptimizeFlag()
flags { "Optimize" }
prepare()
test.capture [[
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>false</GenerateDebugInformation>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<OutputFile>$(OutDir)MyProject.exe</OutputFile>
<EntryPointSymbol>mainCRTStartup</EntryPointSymbol>
</Link>
]]
end
--
-- Skip the entry point override if the WinMain flag is specified.
--
function suite.noEntryPointElement_onWinMainFlag()
flags { "WinMain" }
prepare()
test.capture [[
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>false</GenerateDebugInformation>
<OutputFile>$(OutDir)MyProject.exe</OutputFile>
</Link>
]]
end
--
-- Use the x86 target for Premake's x32 platform.
--
function suite.writesCorrectTarget_onX32Platform()
platforms "x32"
prepare("x32")
test.capture [[
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>false</GenerateDebugInformation>
<OutputFile>$(OutDir)MyProject.exe</OutputFile>
<EntryPointSymbol>mainCRTStartup</EntryPointSymbol>
<TargetMachine>MachineX86</TargetMachine>
</Link>
]]
end
--
-- Use the x64 target for Premake's x64 platform.
--
function suite.writesCorrectTarget_onX64Platform()
platforms { "x64" }
prepare("x64")
test.capture [[
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>false</GenerateDebugInformation>
<OutputFile>$(OutDir)MyProject.exe</OutputFile>
<EntryPointSymbol>mainCRTStartup</EntryPointSymbol>
<TargetMachine>MachineX64</TargetMachine>
</Link>
]]
end

View File

@ -36,7 +36,7 @@
-- entire project references item group should be skipped.
--
function suite.noSectionWritten_onNoSiblingReferences()
function suite.noProjectReferencesGroup_onNoSiblingReferences()
prepare()
vc2010.projectReferences(prj2)
test.isemptycapture()
@ -75,6 +75,12 @@
test.isemptycapture()
end
--
-- If a mix of sibling and system links are listed, only the system
-- libraries should appear in the additional dependencies element.
--
function suite.onlySystemDependencies_OnSiblingProjectLink()
links { "MyProject", "kernel32" }
prepare()

View File

@ -75,7 +75,6 @@
dofile("actions/vstudio/test_vs200x_vcproj_linker.lua")
dofile("actions/vstudio/test_vs2010_vcxproj.lua")
dofile("actions/vstudio/test_vs2010_flags.lua")
dofile("actions/vstudio/test_vs2010_links.lua")
dofile("actions/vstudio/test_vs2010_project_kinds.lua")
-- Visual Studio 2002-2003 C# projects
@ -106,6 +105,7 @@
dofile("actions/vstudio/vc2010/test_header.lua")
dofile("actions/vstudio/vc2010/test_files.lua")
dofile("actions/vstudio/vc2010/test_filters.lua")
dofile("actions/vstudio/vc2010/test_link_settings.lua")
dofile("actions/vstudio/vc2010/test_links.lua")
dofile("actions/vstudio/vc2010/test_pch.lua")