Added PS3 compiler block for Visual Studio

This commit is contained in:
starkos 2009-05-07 14:30:13 +00:00
parent ea8b251082
commit d87875d2a6
3 changed files with 343 additions and 160 deletions

View File

@ -93,6 +93,7 @@
for _, buildcfg in ipairs(sln.configurations) do
for _, platform in ipairs(platforms) do
local entry = { }
entry.src_buildcfg = buildcfg
entry.src_platform = platform
-- PS3 is funky and needs special handling; it's more of a build

View File

@ -5,11 +5,241 @@
--
--
-- Write out the <Platforms> element; ensures that each target platform
-- is listed only once. Skips over .NET's pseudo-platforms (like "Any CPU").
--
function premake.vs200x_vcproj_platforms(prj)
local used = { }
_p('\t<Platforms>')
for _, cfg in ipairs(prj.solution.vstudio_configs) do
if cfg.isreal and not table.contains(used, cfg.platform) then
table.insert(used, cfg.platform)
_p('\t\t<Platform')
_p('\t\t\tName="%s"', cfg.platform)
_p('\t\t/>')
end
end
_p('\t</Platforms>')
end
--
-- Compiler block for Windows and XBox360 platforms.
--
function premake.vs200x_vcproj_VCCLCompilerTool(cfg)
_p('\t\t\t<Tool')
_p('\t\t\t\tName="%s"', iif(cfg.platform ~= "Xbox360", "VCCLCompilerTool", "VCCLX360CompilerTool"))
if #cfg.buildoptions > 0 then
_p('\t\t\t\tAdditionalOptions="%s"', table.concat(premake.esc(cfg.buildoptions), " "))
end
_p('\t\t\t\tOptimization="%s"', _VS.optimization(cfg))
if cfg.flags.NoFramePointer then
_p('\t\t\t\tOmitFramePointers="%s"', _VS.bool(true))
end
if #cfg.includedirs > 0 then
_p('\t\t\t\tAdditionalIncludeDirectories="%s"', premake.esc(path.translate(table.concat(cfg.includedirs, ";"), '\\')))
end
if #cfg.defines > 0 then
_p('\t\t\t\tPreprocessorDefinitions="%s"', premake.esc(table.concat(cfg.defines, ";")))
end
if cfg.flags.Symbols and not cfg.flags.Managed then
_p('\t\t\t\tMinimalRebuild="%s"', _VS.bool(true))
end
if cfg.flags.NoExceptions then
_p('\t\t\t\tExceptionHandling="%s"', iif(_ACTION < "vs2005", "FALSE", 0))
elseif cfg.flags.SEH and _ACTION > "vs2003" then
_p('\t\t\t\tExceptionHandling="2"')
end
if _VS.optimization(cfg) == 0 and not cfg.flags.Managed then
_p('\t\t\t\tBasicRuntimeChecks="3"')
end
if _VS.optimization(cfg) ~= 0 then
_p('\t\t\t\tStringPooling="%s"', _VS.bool(true))
end
_p('\t\t\t\tRuntimeLibrary="%s"', _VS.runtime(cfg))
_p('\t\t\t\tEnableFunctionLevelLinking="%s"', _VS.bool(true))
if _ACTION < "vs2005" and not cfg.flags.NoRTTI then
_p('\t\t\t\tRuntimeTypeInfo="%s"', _VS.bool(true))
elseif _ACTION > "vs2003" and cfg.flags.NoRTTI then
_p('\t\t\t\tRuntimeTypeInfo="%s"', _VS.bool(false))
end
if cfg.flags.NativeWChar then
_p('\t\t\t\tTreatWChar_tAsBuiltInType="%s"', _VS.bool(true))
elseif cfg.flags.NoNativeWChar then
_p('\t\t\t\tTreatWChar_tAsBuiltInType="%s"', _VS.bool(false))
end
if not cfg.flags.NoPCH and cfg.pchheader then
_p('\t\t\t\tUsePrecompiledHeader="%s"', iif(_ACTION < "vs2005", 3, 2))
_p('\t\t\t\tPrecompiledHeaderThrough="%s"', cfg.pchheader)
else
_p('\t\t\t\tUsePrecompiledHeader="%s"', iif(_ACTION > "vs2003" or cfg.flags.NoPCH, 0, 2))
end
_p('\t\t\t\tWarningLevel="%s"', iif(cfg.flags.ExtraWarnings, 4, 3))
if cfg.flags.FatalWarnings then
_p('\t\t\t\tWarnAsError="%s"', _VS.bool(true))
end
if _ACTION < "vs2008" and not cfg.flags.Managed then
_p('\t\t\t\tDetect64BitPortabilityProblems="%s"', _VS.bool(not cfg.flags.No64BitChecks))
end
_p('\t\t\t\tProgramDataBaseFileName="$(OutDir)\\$(ProjectName).pdb"')
_p('\t\t\t\tDebugInformationFormat="%s"', _VS.symbols(cfg))
_p('\t\t\t/>')
end
--
-- Linker block for Windows and Xbox 360 platforms.
--
function premake.vs200x_vcproj_VCLinkerTool(cfg)
_p('\t\t\t<Tool')
if cfg.kind ~= "StaticLib" then
_p('\t\t\t\tName="%s"', iif(cfg.platform ~= "Xbox360", "VCLinkerTool", "VCX360LinkerTool"))
if cfg.flags.NoImportLib then
_p('\t\t\t\tIgnoreImportLibrary="%s"', _VS.bool(true))
end
if #cfg.linkoptions > 0 then
_p('\t\t\t\tAdditionalOptions="%s"', table.concat(premake.esc(cfg.linkoptions), " "))
end
if #cfg.links > 0 then
_p('\t\t\t\tAdditionalDependencies="%s"', table.concat(premake.getlinks(cfg, "all", "fullpath"), " "))
end
_p('\t\t\t\tOutputFile="$(OutDir)\\%s"', cfg.buildtarget.name)
_p('\t\t\t\tLinkIncremental="%s"', iif(_VS.optimization(cfg) == 0, 2, 1))
_p('\t\t\t\tAdditionalLibraryDirectories="%s"', table.concat(premake.esc(path.translate(cfg.libdirs, '\\')) , ";"))
local deffile = premake.findfile(cfg, ".def")
if deffile then
_p('\t\t\t\tModuleDefinitionFile="%s"', deffile)
end
if cfg.flags.NoManifest then
_p('\t\t\t\tGenerateManifest="%s"', _VS.bool(false))
end
_p('\t\t\t\tGenerateDebugInformation="%s"', _VS.bool(_VS.symbols(cfg) ~= 0))
if _VS.symbols(cfg) ~= 0 then
_p('\t\t\t\tProgramDatabaseFile="$(OutDir)\\$(ProjectName).pdb"')
end
_p('\t\t\t\tSubSystem="%s"', iif(cfg.kind == "ConsoleApp", 1, 2))
if _VS.optimization(cfg) ~= 0 then
_p('\t\t\t\tOptimizeReferences="2"')
_p('\t\t\t\tEnableCOMDATFolding="2"')
end
if (cfg.kind == "ConsoleApp" or cfg.kind == "WindowedApp") and not cfg.flags.WinMain then
_p('\t\t\t\tEntryPointSymbol="mainCRTStartup"')
end
if cfg.kind == "SharedLib" then
local implibname = path.translate(premake.gettarget(cfg, "link", "windows").fullpath, "\\")
_p('\t\t\t\tImportLibrary="%s"', iif(cfg.flags.NoImportLib, cfg.objectsdir .. "\\" .. path.getname(implibname), implibname))
end
_p('\t\t\t\tTargetMachine="1"')
else
_p('\t\t\t\tName="VCLibrarianTool"')
if #cfg.links > 0 then
_p('\t\t\t\tAdditionalDependencies="%s"', table.concat(premake.getlinks(cfg, "all", "fullpath"), " "))
end
_p('\t\t\t\tOutputFile="$(OutDir)\\%s"', cfg.buildtarget.name)
_p('\t\t\t\tAdditionalLibraryDirectories="%s"', table.concat(premake.esc(path.translate(cfg.libdirs)) , ";"))
end
_p('\t\t\t/>')
end
--
-- Compiler block for the PS3 platform, which uses GCC.
--
function premake.vs200x_vcproj_VCCLCompilerTool_GCC(cfg)
_p('\t\t\t<Tool')
_p('\t\t\t\tName="VCCLCompilerTool"')
local buildoptions = table.join(premake.gcc.getcflags(cfg), premake.gcc.getcxxflags(cfg), cfg.buildoptions)
if #buildoptions > 0 then
_p('\t\t\t\tAdditionalOptions="%s"', premake.esc(table.concat(buildoptions, " ")))
end
if #cfg.includedirs > 0 then
_p('\t\t\t\tAdditionalIncludeDirectories="%s"', premake.esc(path.translate(table.concat(cfg.includedirs, ";"), '\\')))
end
if #cfg.defines > 0 then
_p('\t\t\t\tPreprocessorDefinitions="%s"', table.concat(premake.esc(cfg.defines), ";"))
end
_p('\t\t\t\tProgramDataBaseFileName="$(OutDir)\\$(ProjectName).pdb"')
_p('\t\t\t\tDebugInformationFormat="0"')
_p('\t\t\t\tCompileAs="0"')
_p('\t\t\t/>')
end
--
-- Resource compiler block.
--
function premake.vs200x_vcproj_VCResourceCompilerTool(cfg)
_p('\t\t\t<Tool')
_p('\t\t\t\tName="VCResourceCompilerTool"')
if #cfg.resoptions > 0 then
_p('\t\t\t\tAdditionalOptions="%s"', table.concat(premake.esc(cfg.resoptions), " "))
end
if #cfg.defines > 0 or #cfg.resdefines > 0 then
_p('\t\t\t\tPreprocessorDefinitions="%s"', table.concat(premake.esc(table.join(cfg.defines, cfg.resdefines)), ";"))
end
if #cfg.includedirs > 0 or #cfg.resincludedirs > 0 then
local dirs = table.join(cfg.includedirs, cfg.resincludedirs)
_p('\t\t\t\tAdditionalIncludeDirectories="%s"', premake.esc(path.translate(table.concat(dirs, ";"), '\\')))
end
_p('\t\t\t/>')
end
--
-- Write out a custom build steps block.
--
local function buildstepsblock(name, steps)
function premake.vs200x_vcproj_buildstepsblock(name, steps)
_p('\t\t\t<Tool')
_p('\t\t\t\tName="%s"', name)
if #steps > 0 then
@ -19,6 +249,21 @@
end
--
-- Map project tool blocks to handler functions. Unmapped blocks will output
-- an empty <Tool> element.
--
local blockmap =
{
VCCLCompilerTool = premake.vs200x_vcproj_VCCLCompilerTool,
VCCLCompilerTool_GCC = premake.vs200x_vcproj_VCCLCompilerTool_GCC,
VCLinkerTool = premake.vs200x_vcproj_VCLinkerTool,
VCResourceCompilerTool = premake.vs200x_vcproj_VCResourceCompilerTool,
}
--
-- Return a list of sections for a particular Visual Studio version and target platform.
--
@ -62,7 +307,7 @@
"VCXMLDataGeneratorTool",
"VCWebServiceProxyGeneratorTool",
"VCMIDLTool",
"VCCLX360CompilerTool",
"VCCLCompilerTool",
"VCManagedResourceCompilerTool",
"VCResourceCompilerTool",
"VCPreLinkEventTool",
@ -74,6 +319,28 @@
"VCPostBuildEventTool",
"DebuggerTool",
}
end
if platform == "PS3" then
return {
"VCPreBuildEventTool",
"VCCustomBuildTool",
"VCXMLDataGeneratorTool",
"VCWebServiceProxyGeneratorTool",
"VCMIDLTool",
"VCCLCompilerTool_GCC",
"VCManagedResourceCompilerTool",
"VCResourceCompilerTool",
"VCPreLinkEventTool",
"VCLinkerTool",
"VCALinkTool",
"VCManifestTool",
"VCXDCMakeTool",
"VCBscMakeTool",
"VCFxCopTool",
"VCAppVerifierTool",
"VCWebDeploymentTool",
"VCPostBuildEventTool"
}
else
return {
"VCPreBuildEventTool",
@ -100,27 +367,6 @@
--
-- Write out the <Platforms> element; ensures that each target platform
-- is listed only once. Skips over .NET's pseudo-platforms (like "Any CPU").
--
function premake.vs200x_vcproj_platforms(prj)
local used = { }
_p('\t<Platforms>')
for _, cfg in ipairs(prj.solution.vstudio_configs) do
if cfg.isreal and not table.contains(used, cfg.platform) then
table.insert(used, cfg.platform)
_p('\t\t<Platform')
_p('\t\t\tName="%s"', cfg.platform)
_p('\t\t/>')
end
end
_p('\t</Platforms>')
end
--
-- The main function: write the project file.
--
@ -160,7 +406,7 @@
_p('\t<Configurations>')
for _, cfginfo in ipairs(prj.solution.vstudio_configs) do
if cfginfo.isreal then
local cfg = premake.getconfig(prj, cfginfo.buildcfg, cfginfo.src_platform)
local cfg = premake.getconfig(prj, cfginfo.src_buildcfg, cfginfo.src_platform)
-- Start a configuration
_p('\t\t<Configuration')
@ -176,142 +422,16 @@
for _, block in ipairs(getsections(_ACTION, cfginfo.src_platform)) do
-- Compiler block --
if block == "VCCLCompilerTool" or block == "VCCLX360CompilerTool" then
_p('\t\t\t<Tool')
_p('\t\t\t\tName="%s"', block)
if #cfg.buildoptions > 0 then
_p('\t\t\t\tAdditionalOptions="%s"', table.concat(premake.esc(cfg.buildoptions), " "))
end
_p('\t\t\t\tOptimization="%s"', _VS.optimization(cfg))
if cfg.flags.NoFramePointer then
_p('\t\t\t\tOmitFramePointers="%s"', _VS.bool(true))
end
if #cfg.includedirs > 0 then
_p('\t\t\t\tAdditionalIncludeDirectories="%s"', table.concat(premake.esc(cfg.includedirs), ";"))
end
if #cfg.defines > 0 then
_p('\t\t\t\tPreprocessorDefinitions="%s"', table.concat(premake.esc(cfg.defines), ";"))
end
if cfg.flags.Symbols and not cfg.flags.Managed then
_p('\t\t\t\tMinimalRebuild="%s"', _VS.bool(true))
end
if cfg.flags.NoExceptions then
_p('\t\t\t\tExceptionHandling="%s"', iif(_ACTION < "vs2005", "FALSE", 0))
elseif cfg.flags.SEH and _ACTION > "vs2003" then
_p('\t\t\t\tExceptionHandling="2"')
end
if _VS.optimization(cfg) == 0 and not cfg.flags.Managed then
_p('\t\t\t\tBasicRuntimeChecks="3"')
end
if _VS.optimization(cfg) ~= 0 then
_p('\t\t\t\tStringPooling="%s"', _VS.bool(true))
end
_p('\t\t\t\tRuntimeLibrary="%s"', _VS.runtime(cfg))
_p('\t\t\t\tEnableFunctionLevelLinking="%s"', _VS.bool(true))
if _ACTION < "vs2005" and not cfg.flags.NoRTTI then
_p('\t\t\t\tRuntimeTypeInfo="%s"', _VS.bool(true))
elseif _ACTION > "vs2003" and cfg.flags.NoRTTI then
_p('\t\t\t\tRuntimeTypeInfo="%s"', _VS.bool(false))
end
if cfg.flags.NativeWChar then
_p('\t\t\t\tTreatWChar_tAsBuiltInType="%s"', _VS.bool(true))
elseif cfg.flags.NoNativeWChar then
_p('\t\t\t\tTreatWChar_tAsBuiltInType="%s"', _VS.bool(false))
end
if not cfg.flags.NoPCH and cfg.pchheader then
_p('\t\t\t\tUsePrecompiledHeader="%s"', iif(_ACTION < "vs2005", 3, 2))
_p('\t\t\t\tPrecompiledHeaderThrough="%s"', cfg.pchheader)
else
_p('\t\t\t\tUsePrecompiledHeader="%s"', iif(_ACTION > "vs2003" or cfg.flags.NoPCH, 0, 2))
end
_p('\t\t\t\tWarningLevel="%s"', iif(cfg.flags.ExtraWarnings, 4, 3))
if cfg.flags.FatalWarnings then
_p('\t\t\t\tWarnAsError="%s"', _VS.bool(true))
end
if _ACTION < "vs2008" and not cfg.flags.Managed then
_p('\t\t\t\tDetect64BitPortabilityProblems="%s"', _VS.bool(not cfg.flags.No64BitChecks))
end
_p('\t\t\t\tProgramDataBaseFileName="$(OutDir)\\$(ProjectName).pdb"')
_p('\t\t\t\tDebugInformationFormat="%s"', _VS.symbols(cfg))
_p('\t\t\t/>')
-- End compiler block --
if blockmap[block] then
blockmap[block](cfg)
-- Linker block --
elseif block == "VCLinkerTool" or block == "VCX360LinkerTool" then
_p('\t\t\t<Tool')
if cfg.kind ~= "StaticLib" then
_p('\t\t\t\tName="%s"', block)
if cfg.flags.NoImportLib then
_p('\t\t\t\tIgnoreImportLibrary="%s"', _VS.bool(true))
end
if #cfg.linkoptions > 0 then
_p('\t\t\t\tAdditionalOptions="%s"', table.concat(premake.esc(cfg.linkoptions), " "))
end
if #cfg.links > 0 then
_p('\t\t\t\tAdditionalDependencies="%s"', table.concat(premake.getlinks(cfg, "all", "fullpath"), " "))
end
_p('\t\t\t\tOutputFile="$(OutDir)\\%s"', cfg.buildtarget.name)
_p('\t\t\t\tLinkIncremental="%s"', iif(_VS.optimization(cfg) == 0, 2, 1))
_p('\t\t\t\tAdditionalLibraryDirectories="%s"', table.concat(premake.esc(path.translate(cfg.libdirs)) , ";"))
local deffile = premake.findfile(cfg, ".def")
if deffile then
_p('\t\t\t\tModuleDefinitionFile="%s"', deffile)
end
if cfg.flags.NoManifest then
_p('\t\t\t\tGenerateManifest="%s"', _VS.bool(false))
end
_p('\t\t\t\tGenerateDebugInformation="%s"', _VS.bool(_VS.symbols(cfg) ~= 0))
if _VS.symbols(cfg) ~= 0 then
_p('\t\t\t\tProgramDatabaseFile="$(OutDir)\\$(ProjectName).pdb"')
end
_p('\t\t\t\tSubSystem="%s"', iif(cfg.kind == "ConsoleApp", 1, 2))
if _VS.optimization(cfg) ~= 0 then
_p('\t\t\t\tOptimizeReferences="2"')
_p('\t\t\t\tEnableCOMDATFolding="2"')
end
if (cfg.kind == "ConsoleApp" or cfg.kind == "WindowedApp") and not cfg.flags.WinMain then
_p('\t\t\t\tEntryPointSymbol="mainCRTStartup"')
end
if cfg.kind == "SharedLib" then
local implibname = path.translate(premake.gettarget(cfg, "link", "windows").fullpath, "\\")
_p('\t\t\t\tImportLibrary="%s"', iif(cfg.flags.NoImportLib, cfg.objectsdir .. "\\" .. path.getname(implibname), implibname))
end
_p('\t\t\t\tTargetMachine="1"')
else
_p('\t\t\t\tName="VCLibrarianTool"')
if #cfg.links > 0 then
_p('\t\t\t\tAdditionalDependencies="%s"', table.concat(premake.getlinks(cfg, "all", "fullpath"), " "))
end
_p('\t\t\t\tOutputFile="$(OutDir)\\%s"', cfg.buildtarget.name)
_p('\t\t\t\tAdditionalLibraryDirectories="%s"', table.concat(premake.esc(path.translate(cfg.libdirs)) , ";"))
end
_p('\t\t\t/>')
-- End linker block --
-- Resource compiler --
elseif block == "VCResourceCompilerTool" then
_p('\t\t\t<Tool')
_p('\t\t\t\tName="VCResourceCompilerTool"')
if #cfg.resoptions > 0 then
_p('\t\t\t\tAdditionalOptions="%s"', table.concat(premake.esc(cfg.resoptions), " "))
end
if #cfg.defines > 0 or #cfg.resdefines > 0 then
_p('\t\t\t\tPreprocessorDefinitions="%s"', table.concat(premake.esc(table.join(cfg.defines, cfg.resdefines)), ";"))
end
if #cfg.includedirs > 0 or #cfg.resincludedirs > 0 then
_p('\t\t\t\tAdditionalIncludeDirectories="%s"', table.concat(premake.esc(table.join(cfg.includedirs, cfg.resincludedirs)), ";"))
end
_p('\t\t\t/>')
-- End resource compiler --
-- Build event blocks --
elseif block == "VCPreBuildEventTool" then
buildstepsblock("VCPreBuildEventTool", cfg.prebuildcommands)
premake.vs200x_vcproj_buildstepsblock("VCPreBuildEventTool", cfg.prebuildcommands)
elseif block == "VCPreLinkEventTool" then
buildstepsblock("VCPreLinkEventTool", cfg.prelinkcommands)
premake.vs200x_vcproj_buildstepsblock("VCPreLinkEventTool", cfg.prelinkcommands)
elseif block == "VCPostBuildEventTool" then
buildstepsblock("VCPostBuildEventTool", cfg.postbuildcommands)
premake.vs200x_vcproj_buildstepsblock("VCPostBuildEventTool", cfg.postbuildcommands)
-- End build event blocks --
-- Xbox 360 custom sections --
@ -352,3 +472,4 @@
end

View File

@ -16,15 +16,15 @@
configurations { "Debug", "Release" }
platforms {}
project "DotNetProject" -- to test handling of .NET platform in solution
language "C#"
kind "ConsoleApp"
prj = project "MyProject"
language "C++"
kind "ConsoleApp"
uuid "AE61726D-187C-E440-BD07-2556188A6565"
project "DotNetProject" -- to test handling of .NET platform in solution
language "C#"
kind "ConsoleApp"
_ACTION = 'vs2005'
end
@ -33,7 +33,7 @@
premake.buildconfigs()
sln.vstudio_configs = premake.vstudio_buildconfigs(sln)
local cfg = premake.getconfig(sln.projects[1])
local cfg = premake.getconfig(sln.projects[2])
cfg.name = prj.name
cfg.blocks = prj.blocks
prj = cfg
@ -273,6 +273,47 @@
--
-- Test Xbox360 handling
--
function T.vs200x_vcproj.PlatformsList_OnXbox360()
platforms { "Native", "Xbox360" }
prepare()
premake.vs200x_vcproj_platforms(prj)
test.capture [[
<Platforms>
<Platform
Name="Win32"
/>
<Platform
Name="Xbox 360"
/>
</Platforms>
]]
end
function T.vs200x_vcproj.CompilerBlock_OnXbox360()
platforms { "Xbox360" }
prepare()
premake.vs200x_vcproj_VCCLCompilerTool(premake.getconfig(prj, "Debug", "Xbox360"))
test.capture [[
<Tool
Name="VCCLX360CompilerTool"
Optimization="0"
BasicRuntimeChecks="3"
RuntimeLibrary="3"
EnableFunctionLevelLinking="true"
UsePrecompiledHeader="0"
WarningLevel="3"
Detect64BitPortabilityProblems="true"
ProgramDataBaseFileName="$(OutDir)\$(ProjectName).pdb"
DebugInformationFormat="0"
/>
]]
end
--
-- Test PS3 handling
--
@ -289,3 +330,23 @@
</Platforms>
]]
end
function T.vs200x_vcproj.CompilerBlock_OnPS3()
platforms { "PS3" }
flags { "Symbols" }
includedirs { "include/pkg1", "include/pkg2" }
defines { "DEFINE1", "DEFINE2" }
prepare()
premake.vs200x_vcproj_VCCLCompilerTool_GCC(premake.getconfig(prj, "Debug", "PS3"))
test.capture [[
<Tool
Name="VCCLCompilerTool"
AdditionalOptions="-g"
AdditionalIncludeDirectories="include\pkg1;include\pkg2"
PreprocessorDefinitions="DEFINE1;DEFINE2"
ProgramDataBaseFileName="$(OutDir)\$(ProjectName).pdb"
DebugInformationFormat="0"
CompileAs="0"
/>
]]
end