Rework VC 200x linker block to call arrays

This commit is contained in:
Jason Perkins 2014-03-06 10:11:08 -05:00
parent e1fa699109
commit 8c54e7943f
6 changed files with 228 additions and 234 deletions

View File

@ -335,13 +335,16 @@
--
function vstudio.needsExplicitLink(cfg)
local ex = cfg.flags.NoImplicitLink
if not ex then
local prjdeps = project.getdependencies(cfg.project)
local cfgdeps = config.getlinks(cfg, "dependencies", "object")
ex = #prjdeps ~= #cfgdeps
if not cfg._needsExplicitLink then
local ex = cfg.flags.NoImplicitLink
if not ex then
local prjdeps = project.getdependencies(cfg.project)
local cfgdeps = config.getlinks(cfg, "dependencies", "object")
ex = #prjdeps ~= #cfgdeps
end
cfg._needsExplicitLink = ex
end
return ex
return cfg._needsExplicitLink
end

View File

@ -275,8 +275,7 @@
-- closes the element.
--
-- @param name
-- The name of the tool, e.g. "VCCustomBuildTool". If nil, no name
-- attribute will be written.
-- The name of the tool, e.g. "VCCustomBuildTool".
-- @param ...
-- Any additional arguments required by the call list.
---
@ -365,7 +364,7 @@
m.runtimeTypeInfo,
m.treatWChar_tAsBuiltInType,
m.usePrecompiledHeader,
m.programDatabaseFileName,
m.programDataBaseFileName,
m.warnings,
m.debugInformationFormat,
m.compileAs,
@ -379,13 +378,12 @@
m.additionalIncludeDirectories,
m.preprocessorDefinitions,
m.usePrecompiledHeader,
m.programDatabaseFileName,
m.programDataBaseFileName,
m.debugInformationFormat,
m.compileAs,
m.forcedIncludeFiles,
}
end
end
function m.VCCLCompilerToolName(cfg)
@ -425,6 +423,54 @@
------------
m.elements.VCLinkerTool = function(cfg, toolset)
if cfg.kind ~= p.STATICLIB then
return {
m.linkLibraryDependencies,
m.ignoreImportLibrary,
m.additionalLinkerOptions,
m.additionalDependencies,
m.outputFile,
m.linkIncremental,
m.additionalLibraryDirectories,
m.moduleDefinitionFile,
m.generateManifest,
m.generateDebugInformation,
m.subSystem,
m.optimizeReferences,
m.enableCOMDATFolding,
m.entryPointSymbol,
m.importLibrary,
m.targetMachine,
m.randomizedBaseAddress,
m.dataExecutionPrevention,
}
else
return {
m.additionalLinkerOptions,
m.additionalDependencies,
m.outputFile,
m.additionalLibraryDirectories,
}
end
end
function m.VCLinkerToolName(cfg)
if cfg.kind == p.STATICLIB then
return "VCLibrarianTool"
elseif cfg.system == p.XBOX360 then
return "VCX360LinkerTool"
else
return "VCLinkerTool"
end
end
function m.VCLinkerTool(cfg, toolset)
m.VCTool("VCLinkerTool", cfg, toolset)
end
------------
m.elements.VCManagedResourceCompilerTool = function(cfg)
return {}
end
@ -472,135 +518,6 @@
--
---------------------------------------------------------------------------
function m.VCLinkerTool(cfg, toolset)
p.push('<Tool')
p.w('Name="%s"', m.linkerTool(cfg))
if cfg.fake then
p.pop('/>')
return
end
-- Decide between the built-in linker or an external toolset;
-- PS3 uses the external toolset
if toolset then
m.VCExternalLinkerTool(cfg, toolset)
else
m.VCBuiltInLinkerTool(cfg)
end
p.pop('/>')
end
function m.VCBuiltInLinkerTool(cfg)
local explicitLink = vstudio.needsExplicitLink(cfg)
if cfg.kind ~= p.STATICLIB then
if explicitLink then
p.w('LinkLibraryDependencies="false"')
end
if cfg.flags.NoImportLib then
p.w('IgnoreImportLibrary="%s"', m.bool(true))
end
end
if #cfg.linkoptions > 0 then
p.x('AdditionalOptions="%s"', table.concat(cfg.linkoptions, " "))
end
if #cfg.links > 0 then
local links = m.links(cfg, explicitLink)
if links ~= "" then
p.x('AdditionalDependencies="%s"', links)
end
end
p.x('OutputFile="$(OutDir)\\%s"', cfg.buildtarget.name)
if cfg.kind ~= p.STATICLIB then
p.w('LinkIncremental="%s"', iif(config.canLinkIncremental(cfg) , 2, 1))
end
m.additionalLibraryDirectories(cfg)
if cfg.kind ~= p.STATICLIB then
local deffile = config.findfile(cfg, ".def")
if deffile then
p.w('ModuleDefinitionFile="%s"', deffile)
end
if cfg.flags.NoManifest then
p.w('GenerateManifest="%s"', m.bool(false))
end
p.w('GenerateDebugInformation="%s"', m.bool(m.symbols(cfg) ~= 0))
if m.symbols(cfg) >= 3 then
p.x('ProgramDataBaseFileName="$(OutDir)\\%s.pdb"', cfg.buildtarget.basename)
end
p.w('SubSystem="%s"', iif(cfg.kind == "ConsoleApp", 1, 2))
if config.isOptimizedBuild(cfg) then
p.w('OptimizeReferences="2"')
p.w('EnableCOMDATFolding="2"')
end
if (cfg.kind == "ConsoleApp" or cfg.kind == "WindowedApp") and not cfg.flags.WinMain then
p.w('EntryPointSymbol="mainCRTStartup"')
end
if cfg.kind == "SharedLib" then
local implibdir = cfg.linktarget.abspath
-- I can't actually stop the import lib, but I can hide it in the objects directory
if cfg.flags.NoImportLib then
implibdir = path.join(cfg.objdir, path.getname(implibdir))
end
implibdir = project.getrelative(cfg.project, implibdir)
p.x('ImportLibrary="%s"', path.translate(implibdir))
end
p.w('TargetMachine="%d"', iif(cfg.architecture == "x64", 17, 1))
end
end
function m.VCExternalLinkerTool(cfg, toolset)
local explicitLink = vstudio.needsExplicitLink(cfg)
local buildoptions = table.join(toolset.getldflags(cfg), cfg.linkoptions)
if #buildoptions > 0 then
p.x('AdditionalOptions="%s"', table.concat(buildoptions, " "))
end
if #cfg.links > 0 then
local links = toolset.getlinks(cfg, not explicitLink)
if #links > 0 then
p.x('AdditionalDependencies="%s"', table.concat(links, " "))
end
end
p.x('OutputFile="$(OutDir)\\%s"', cfg.buildtarget.name)
if cfg.kind ~= p.STATICLIB then
p.w('LinkIncremental="0"')
end
m.additionalLibraryDirectories(cfg)
if cfg.kind ~= p.STATICLIB then
p.w('GenerateManifest="%s"', m.bool(false))
p.w('ProgramDatabaseFile=""')
p.w('RandomizedBaseAddress="1"')
p.w('DataExecutionPrevention="0"')
end
end
function m.VCManifestTool(cfg)
if cfg.kind == p.STATICLIB then
return
@ -957,39 +874,6 @@
end
--
-- Returns the list of libraries required to link a specific configuration,
-- formatted for Visual Studio's XML.
--
function m.links(cfg, explicit)
local scope = iif(explicit, "all", "system")
local links = config.getlinks(cfg, scope, "fullpath")
for i, link in ipairs(links) do
if link:find(" ", 1, true) then
link = '"' .. link .. '"'
end
links[i] = path.translate(link)
end
return table.concat(links, " ")
end
--
-- Returns the correct name for the linker tool element, based on
-- the configuration target system.
--
function m.linkerTool(cfg)
if cfg.kind == p.STATICLIB then
return "VCLibrarianTool"
elseif cfg.system == p.XBOX360 then
return "VCX360LinkerTool"
else
return "VCLinkerTool"
end
end
--
-- Return the debugging symbol level for a configuration.
@ -1023,6 +907,31 @@
---------------------------------------------------------------------------
function m.additionalDependencies(cfg, toolset)
if #cfg.links == 0 then return end
local ex = vstudio.needsExplicitLink(cfg)
local links
if not toolset then
local scope = iif(ex, "all", "system")
links = config.getlinks(cfg, scope, "fullpath")
for i, link in ipairs(links) do
if link:find(" ", 1, true) then
link = '"' .. link .. '"'
end
links[i] = path.translate(link)
end
else
links = toolset.getlinks(cfg, not ex)
end
if #links > 0 then
p.x('AdditionalDependencies="%s"', table.concat(links, " "))
end
end
function m.additionalIncludeDirectories(cfg)
if #cfg.includedirs > 0 then
local dirs = project.getrelative(cfg.project, cfg.includedirs)
@ -1069,6 +978,17 @@
end
function m.additionalLinkerOptions(cfg, toolset)
local flags = cfg.linkoptions
if toolset then
flags = table.join(toolset.getldflags(cfg), flags)
end
if #flags > 0 then
p.x('AdditionalOptions="%s"', table.concat(flags, " "))
end
end
function m.assemblyReferences(prj)
-- Visual Studio doesn't support per-config references
local cfg = project.getfirstconfig(prj)
@ -1159,12 +1079,26 @@
end
function m.dataExecutionPrevention(cfg, toolset)
if toolset then
p.w('DataExecutionPrevention="0"')
end
end
function m.debugInformationFormat(cfg, toolset)
local fmt = iif(toolset, "0", m.symbols(cfg))
p.w('DebugInformationFormat="%s"', fmt)
end
function m.enableCOMDATFolding(cfg, toolset)
if config.isOptimizedBuild(cfg) and not toolset then
p.w('EnableCOMDATFolding="2"')
end
end
function m.enableEnhancedInstructionSet(cfg)
local map = { SSE = "1", SSE2 = "2" }
local value = map[cfg.vectorextensions]
@ -1179,6 +1113,16 @@
end
function m.entryPointSymbol(cfg, toolset)
if (cfg.kind == "ConsoleApp" or cfg.kind == "WindowedApp") and
not cfg.flags.WinMain and
not toolset
then
p.w('EntryPointSymbol="mainCRTStartup"')
end
end
function m.exceptionHandling(cfg)
if cfg.flags.NoExceptions then
p.w('ExceptionHandling="%s"', iif(_ACTION < "vs2005", "FALSE", 0))
@ -1216,13 +1160,6 @@
end
function m.omitDefaultLib(cfg)
if cfg.flags.OmitDefaultLibrary then
p.w('OmitDefaultLibName="true"')
end
end
function m.keyword(prj)
local windows, managed, makefile
for cfg in project.eachconfig(prj) do
@ -1244,6 +1181,42 @@
end
function m.generateDebugInformation(cfg, toolset)
if not toolset then
p.w('GenerateDebugInformation="%s"', m.bool(m.symbols(cfg) ~= 0))
end
end
function m.generateManifest(cfg, toolset)
if cfg.flags.NoManifest or toolset then
p.w('GenerateManifest="%s"', m.bool(false))
end
end
function m.ignoreImportLibrary(cfg, toolset)
if cfg.flags.NoImportLib and not toolset then
p.w('IgnoreImportLibrary="%s"', m.bool(true))
end
end
function m.importLibrary(cfg, toolset)
if cfg.kind == p.SHAREDLIB and not toolset then
local implibdir = cfg.linktarget.abspath
-- I can't actually stop the import lib, but I can hide it in the objects directory
if cfg.flags.NoImportLib then
implibdir = path.join(cfg.objdir, path.getname(implibdir))
end
implibdir = project.getrelative(cfg.project, implibdir)
p.x('ImportLibrary="%s"', path.translate(implibdir))
end
end
function m.intermediateDirectory(cfg)
local objdir
if not cfg.fake then
@ -1255,6 +1228,24 @@
end
function m.linkIncremental(cfg, toolset)
local value
if not toolset then
value = iif(config.canLinkIncremental(cfg) , 2, 1)
else
value = 0
end
p.w('LinkIncremental="%s"', value)
end
function m.linkLibraryDependencies(cfg, toolset)
if vstudio.needsExplicitLink(cfg) and not toolset then
p.w('LinkLibraryDependencies="false"')
end
end
function m.managedExtensions(cfg)
if cfg.flags.Managed then
p.w('ManagedExtensions="1"')
@ -1274,6 +1265,16 @@
end
function m.moduleDefinitionFile(cfg, toolset)
if not toolset then
local deffile = config.findfile(cfg, ".def")
if deffile then
p.w('ModuleDefinitionFile="%s"', deffile)
end
end
end
function m.nmakeCommandLine(cfg, commands, phase)
commands = table.concat(commands, "\r\n")
p.w('%sCommandLine="%s"', phase, p.esc(commands))
@ -1294,6 +1295,13 @@
end
function m.omitDefaultLib(cfg)
if cfg.flags.OmitDefaultLibrary then
p.w('OmitDefaultLibName="true"')
end
end
function m.omitFramePointers(cfg)
if cfg.flags.NoFramePointer then
p.w('OmitFramePointers="%s"', m.bool(true))
@ -1310,12 +1318,24 @@
end
function m.optimizeReferences(cfg, toolset)
if config.isOptimizedBuild(cfg) and not toolset then
p.w('OptimizeReferences="2"')
end
end
function m.outputDirectory(cfg)
local outdir = project.getrelative(cfg.project, cfg.buildtarget.directory)
p.x('OutputDirectory="%s"', path.translate(outdir))
end
function m.outputFile(cfg)
p.x('OutputFile="$(OutDir)\\%s"', cfg.buildtarget.name)
end
function m.platforms(prj)
p.push('<Platforms>')
table.foreachi(m.architectures(prj), function(arch)
@ -1334,9 +1354,10 @@
end
function m.programDatabaseFileName(cfg)
local target = cfg.buildtarget
p.x('ProgramDataBaseFileName="$(OutDir)\\%s%s.pdb"', target.prefix, target.basename)
function m.programDataBaseFileName(cfg, toolset)
if toolset then
p.w('ProgramDataBaseFileName=""')
end
end
@ -1382,6 +1403,14 @@
end
function m.randomizedBaseAddress(cfg, toolset)
if toolset then
p.w('RandomizedBaseAddress="1"')
end
end
function m.resourceAdditionalIncludeDirectories(cfg)
local dirs = table.join(cfg.includedirs, cfg.resincludedirs)
if #dirs > 0 then
@ -1439,6 +1468,13 @@
end
function m.subSystem(cfg, toolset)
if not toolset then
p.w('SubSystem="%s"', iif(cfg.kind == "ConsoleApp", 1, 2))
end
end
function m.targetFrameworkVersion(prj)
local windows, makefile
for cfg in project.eachconfig(prj) do
@ -1454,10 +1490,10 @@
end
function m.tool(name)
p.push('<Tool')
p.w('Name="%s"', name)
p.pop('/>')
function m.targetMachine(cfg, toolset)
if not toolset then
p.w('TargetMachine="%d"', iif(cfg.architecture == "x64", 17, 1))
end
end

View File

@ -39,7 +39,6 @@
RuntimeLibrary="2"
EnableFunctionLevelLinking="true"
UsePrecompiledHeader="0"
ProgramDataBaseFileName="$(OutDir)\MyProject.pdb"
WarningLevel="3"
DebugInformationFormat="0"
/>
@ -81,7 +80,6 @@
RuntimeLibrary="3"
EnableFunctionLevelLinking="true"
UsePrecompiledHeader="0"
ProgramDataBaseFileName="$(OutDir)\MyProject.pdb"
WarningLevel="3"
DebugInformationFormat="4"
/>
@ -106,7 +104,6 @@
RuntimeLibrary="2"
EnableFunctionLevelLinking="true"
UsePrecompiledHeader="0"
ProgramDataBaseFileName="$(OutDir)\MyProject.pdb"
WarningLevel="3"
DebugInformationFormat="3"
/>
@ -130,7 +127,6 @@
RuntimeLibrary="3"
EnableFunctionLevelLinking="true"
UsePrecompiledHeader="0"
ProgramDataBaseFileName="$(OutDir)\MyProject.pdb"
WarningLevel="3"
DebugInformationFormat="1"
/>
@ -159,7 +155,6 @@
EnableFunctionLevelLinking="true"
UsePrecompiledHeader="2"
PrecompiledHeaderThrough="include/common.h"
ProgramDataBaseFileName="$(OutDir)\MyProject.pdb"
WarningLevel="3"
DebugInformationFormat="0"
/>
@ -183,7 +178,6 @@
EnableFunctionLevelLinking="true"
FloatingPointModel="2"
UsePrecompiledHeader="0"
ProgramDataBaseFileName="$(OutDir)\MyProject.pdb"
WarningLevel="3"
DebugInformationFormat="0"
/>
@ -202,30 +196,6 @@
EnableFunctionLevelLinking="true"
FloatingPointModel="1"
UsePrecompiledHeader="0"
ProgramDataBaseFileName="$(OutDir)\MyProject.pdb"
WarningLevel="3"
DebugInformationFormat="0"
/>
]]
end
--
-- Verify that the PDB file uses the target name if specified.
--
function suite.pdbUsesTargetName_onTargetName()
targetname "foob"
prepare()
test.capture [[
<Tool
Name="VCCLCompilerTool"
Optimization="0"
BasicRuntimeChecks="3"
RuntimeLibrary="2"
EnableFunctionLevelLinking="true"
UsePrecompiledHeader="0"
ProgramDataBaseFileName="$(OutDir)\foob.pdb"
WarningLevel="3"
DebugInformationFormat="0"
/>
@ -248,7 +218,6 @@
RuntimeLibrary="3"
EnableFunctionLevelLinking="true"
UsePrecompiledHeader="0"
ProgramDataBaseFileName="$(OutDir)\MyProject.pdb"
WarningLevel="3"
DebugInformationFormat="4"
/>
@ -271,7 +240,6 @@
RuntimeLibrary="2"
EnableFunctionLevelLinking="true"
UsePrecompiledHeader="0"
ProgramDataBaseFileName="$(OutDir)\MyProject.pdb"
WarningLevel="3"
DebugInformationFormat="0"
/>
@ -293,7 +261,6 @@
RuntimeLibrary="2"
EnableFunctionLevelLinking="true"
UsePrecompiledHeader="0"
ProgramDataBaseFileName="$(OutDir)\MyProject.pdb"
WarningLevel="3"
DebugInformationFormat="0"
CompileAs="1"
@ -318,7 +285,6 @@
RuntimeLibrary="3"
EnableFunctionLevelLinking="true"
UsePrecompiledHeader="0"
ProgramDataBaseFileName="$(OutDir)\MyProject.pdb"
WarningLevel="3"
DebugInformationFormat="4"
/>
@ -341,7 +307,6 @@
RuntimeLibrary="2"
EnableFunctionLevelLinking="true"
UsePrecompiledHeader="0"
ProgramDataBaseFileName="$(OutDir)\MyProject.pdb"
WarningLevel="4"
DebugInformationFormat="0"
/>
@ -364,7 +329,6 @@
RuntimeLibrary="2"
EnableFunctionLevelLinking="true"
UsePrecompiledHeader="0"
ProgramDataBaseFileName="$(OutDir)\MyProject.pdb"
WarningLevel="3"
WarnAsError="true"
DebugInformationFormat="0"
@ -389,7 +353,6 @@
RuntimeLibrary="2"
EnableFunctionLevelLinking="true"
UsePrecompiledHeader="0"
ProgramDataBaseFileName="$(OutDir)\MyProject.pdb"
WarningLevel="0"
DebugInformationFormat="0"
/>
@ -412,7 +375,6 @@
RuntimeLibrary="2"
EnableFunctionLevelLinking="true"
UsePrecompiledHeader="0"
ProgramDataBaseFileName="$(OutDir)\MyProject.pdb"
WarningLevel="3"
Detect64BitPortabilityProblems="true"
DebugInformationFormat="0"
@ -437,7 +399,6 @@
RuntimeLibrary="2"
EnableFunctionLevelLinking="true"
UsePrecompiledHeader="0"
ProgramDataBaseFileName="$(OutDir)\MyProject.pdb"
WarningLevel="0"
DebugInformationFormat="0"
/>
@ -460,7 +421,6 @@
RuntimeLibrary="2"
EnableFunctionLevelLinking="true"
UsePrecompiledHeader="0"
ProgramDataBaseFileName="$(OutDir)\MyProject.pdb"
WarningLevel="3"
DebugInformationFormat="0"
/>
@ -483,7 +443,6 @@
RuntimeLibrary="2"
EnableFunctionLevelLinking="true"
UsePrecompiledHeader="0"
ProgramDataBaseFileName="$(OutDir)\MyProject.pdb"
WarningLevel="3"
DebugInformationFormat="0"
ForcedIncludeFiles="stdafx.h;include\sys.h"
@ -501,7 +460,6 @@
RuntimeLibrary="2"
EnableFunctionLevelLinking="true"
UsePrecompiledHeader="0"
ProgramDataBaseFileName="$(OutDir)\MyProject.pdb"
WarningLevel="3"
DebugInformationFormat="0"
ForcedUsingFiles="stdafx.h;include\sys.h"
@ -678,7 +636,6 @@
RuntimeLibrary="2"
EnableFunctionLevelLinking="true"
UsePrecompiledHeader="0"
ProgramDataBaseFileName="$(OutDir)\MyProject.pdb"
WarningLevel="3"
DebugInformationFormat="0"
OmitDefaultLibName="true"

View File

@ -38,7 +38,7 @@
Name="VCCLCompilerTool"
AdditionalOptions="-Xc+=exceptions -Xc+=rtti"
UsePrecompiledHeader="0"
ProgramDataBaseFileName="$(OutDir)\MyProject.pdb"
ProgramDataBaseFileName=""
DebugInformationFormat="0"
CompileAs="0"
/>
@ -75,7 +75,7 @@
Name="VCCLCompilerTool"
AdditionalOptions="-Xc+=exceptions -Xc+=rtti"
UsePrecompiledHeader="0"
ProgramDataBaseFileName="$(OutDir)\MyProject.pdb"
ProgramDataBaseFileName=""
DebugInformationFormat="0"
CompileAs="0"
ForcedIncludeFiles="stdafx.h;include\sys.h"

View File

@ -43,7 +43,6 @@
OutputFile="$(OutDir)\MyProject.elf"
LinkIncremental="0"
GenerateManifest="false"
ProgramDatabaseFile=""
RandomizedBaseAddress="1"
DataExecutionPrevention="0"
/>

View File

@ -118,7 +118,6 @@
OutputFile="$(OutDir)\MyProject.exe"
LinkIncremental="2"
GenerateDebugInformation="true"
ProgramDataBaseFileName="$(OutDir)\MyProject.pdb"
]]
end