diff options
author | starkos <none@none> | 2009-03-26 22:29:21 +0300 |
---|---|---|
committer | starkos <none@none> | 2009-03-26 22:29:21 +0300 |
commit | 0c794084b29f35a3af53d414f320aab4a2195bca (patch) | |
tree | 5a2e186db2d66a0e7b453becbaa86d22ec02f350 /src | |
parent | 0776e56996fa3f25d4f746bd05e3b6badc339644 (diff) |
Refactored current platform code for VS2005 and VS2008
Diffstat (limited to 'src')
-rw-r--r-- | src/actions/vstudio/_vstudio.lua | 26 | ||||
-rw-r--r-- | src/actions/vstudio/vs2005_solution.lua | 83 | ||||
-rw-r--r-- | src/actions/vstudio/vs200x_vcproj.lua | 30 |
3 files changed, 64 insertions, 75 deletions
diff --git a/src/actions/vstudio/_vstudio.lua b/src/actions/vstudio/_vstudio.lua index d4fe419..c421212 100644 --- a/src/actions/vstudio/_vstudio.lua +++ b/src/actions/vstudio/_vstudio.lua @@ -143,6 +143,32 @@ -- +-- Map a list of platforms to their Visual Studio equivalents, taking the +-- Visual Studio version into account. Note that multiple target platforms +-- is only supported for Visual Studio 2005 or later right now. +-- + + function premake.vstudio_get_platforms(platforms, version) + local result = { } + if version > "vs2003" and platforms then + for _, platform in ipairs(platforms) do + if platform == "x32" then + table.insert(result, "Win32") + elseif platform == "x64" then + table.insert(result, "x64") + end + end + end + + -- make sure I've got at least one + if #result == 0 then + result = { "Win32" } + end + return result + end + + +-- -- Write out entries for the files element; called from premake.walksources(). -- diff --git a/src/actions/vstudio/vs2005_solution.lua b/src/actions/vstudio/vs2005_solution.lua index 6177248..68a2882 100644 --- a/src/actions/vstudio/vs2005_solution.lua +++ b/src/actions/vstudio/vs2005_solution.lua @@ -8,6 +8,24 @@ function premake.vs2005_solution(sln) io.eol = '\r\n' + -- Build the list of target platforms + local hascpp = premake.hascppproject(sln) + local hasdotnet = premake.hasdotnetproject(sln) + + local platforms = { } + if hasdotnet then + table.insert(platforms, "Any CPU") + end + if hasdotnet and hascpp then + table.insert(platforms, "Mixed Platforms") + end + if hascpp then + platforms.cppdefault = #platforms + 1 + for _, p in ipairs(premake.vstudio_get_platforms(sln.platforms, _ACTION)) do + table.insert(platforms, p) + end + end + -- Mark the file as Unicode io.printf('\239\187\191') @@ -19,7 +37,7 @@ io.printf('Microsoft Visual Studio Solution File, Format Version 10.00') io.printf('# Visual Studio 2008') end - + -- Write out the list of project entries for prj in premake.eachproject(sln) do -- Build a relative path from the solution file to the project file @@ -38,8 +56,8 @@ end io.printf('Global') - premake.vs2005_solution_configurations(sln) - premake.vs2005_solution_project_configurations(sln) + premake.vs2005_solution_configurations(sln, platforms) + premake.vs2005_solution_project_configurations(sln, platforms) premake.vs2005_solution_properties(sln) io.printf('EndGlobal') end @@ -51,16 +69,13 @@ -- lists all of the configuration/platform pairs that exist in the solution. -- - function premake.vs2005_solution_configurations(sln) - local platforms = premake.vs2005_solution_platforms(sln) + function premake.vs2005_solution_configurations(sln, platforms) io.printf('\tGlobalSection(SolutionConfigurationPlatforms) = preSolution') - for _, cfgname in ipairs(sln.configurations) do for _, platname in ipairs(platforms) do io.printf('\t\t%s|%s = %s|%s', cfgname, platname, cfgname, platname) end end - io.printf('\tEndGlobalSection') end @@ -71,10 +86,8 @@ -- the configuration/platform pairs into each project of the solution. -- - function premake.vs2005_solution_project_configurations(sln) - local platforms = premake.vs2005_solution_platforms(sln) + function premake.vs2005_solution_project_configurations(sln, platforms) io.printf('\tGlobalSection(ProjectConfigurationPlatforms) = postSolution') - for prj in premake.eachproject(sln) do for _, cfgname in ipairs(sln.configurations) do for i, platname in ipairs(platforms) do @@ -86,7 +99,6 @@ end end end - io.printf('\tEndGlobalSection') end @@ -105,53 +117,6 @@ -- --- Translate the generic list of platforms into their Visual Studio equivalents. --- - - function premake.vs2005_solution_platforms(sln) - -- see if I've already cached the list - if sln.__vs2005_platforms then - return sln.__vs2005_platforms - end - - local hascpp = premake.hascppproject(sln) - local hasdotnet = premake.hasdotnetproject(sln) - local result = { } - - if hasdotnet then - table.insert(result, "Any CPU") - end - - if hasdotnet and hascpp then - table.insert(result, "Mixed Platforms") - end - - if hascpp then - result._firstCppPlatform = #result + 1 - if sln.platforms then - for _, pid in ipairs(sln.platforms) do - if pid == "x32" then - table.insert(result, "Win32") - elseif pid == "x64" then - table.insert(result, "x64") - end - end - end - - -- if no VS-compatible platforms were found, add a default - if #result < result._firstCppPlatform then - table.insert(result, "Win32") - end - end - - -- cache the result; I need it pretty often - sln.__vs2005_platforms = result - return result - end - - - --- -- Map a solution-level platform to one compatible with the provided project. -- C++ platforms are mapped to "Any CPU" for .NET projects, and vice versa. -- @@ -164,5 +129,5 @@ -- C++ projects use the current platform, or the first C++ platform -- if the current one is for .NET - return platforms[math.max(i, platforms._firstCppPlatform)] + return platforms[math.max(i, platforms.cppdefault)] end
\ No newline at end of file diff --git a/src/actions/vstudio/vs200x_vcproj.lua b/src/actions/vstudio/vs200x_vcproj.lua index c8c604d..ebb553f 100644 --- a/src/actions/vstudio/vs200x_vcproj.lua +++ b/src/actions/vstudio/vs200x_vcproj.lua @@ -4,17 +4,8 @@ -- Copyright (c) 2009 Jason Perkins and the Premake project -- - -- - -- Write out an empty tool block; there are quite a few of these. - -- - local function printemptyblock(name) - io.printf('\t\t\t<Tool') - io.printf('\t\t\t\tName="%s"', name) - io.printf('\t\t\t/>') - end - - -- Write out a custom build steps block. + -- Write out a custom build steps block local function buildstepsblock(name, steps) io.printf('\t\t\t<Tool') io.printf('\t\t\t\tName="%s"', name) @@ -50,7 +41,15 @@ io.printf('\tKeyword="%s"', iif(prj.flags.Managed, "ManagedCProj", "Win32Proj")) io.printf('\t>') - premake.vs200x_vcproj_platforms(prj) + -- list target platforms + local platforms = premake.vstudio_get_platforms(prj.solution.platforms, _ACTION) + io.printf('\t<Platforms>') + for _, platform in ipairs(platforms) do + io.printf('\t\t<Platform') + io.printf('\t\t\tName="%s"', platform) + io.printf('\t\t/>') + end + io.printf('\t</Platforms>') if _ACTION > "vs2003" then io.printf('\t<ToolFiles>') @@ -59,10 +58,7 @@ io.printf('\t<Configurations>') - local platforms = premake.vs2005_solution_platforms(prj.solution) - for i = platforms._firstCppPlatform, #platforms do - local platform = platforms[i] - + for _, platform in ipairs(platforms) do for cfg in premake.eachconfig(prj) do -- Start a configuration io.printf('\t\t<Configuration') @@ -217,7 +213,9 @@ -- End build event blocks -- else - printemptyblock(block) + io.printf('\t\t\t<Tool') + io.printf('\t\t\t\tName="%s"', block) + io.printf('\t\t\t/>') end end io.printf('\t\t</Configuration>') |