2013-05-02 15:21:23 +00:00
|
|
|
--
|
2017-08-30 18:35:42 +00:00
|
|
|
-- vs2010.lua
|
2013-05-02 15:21:23 +00:00
|
|
|
-- Add support for the Visual Studio 2010 project formats.
|
2017-08-30 18:35:42 +00:00
|
|
|
-- Copyright (c) Jason Perkins and the Premake project
|
2013-05-02 15:21:23 +00:00
|
|
|
--
|
|
|
|
|
2014-02-08 15:44:57 +00:00
|
|
|
local p = premake
|
2017-04-25 05:44:13 +00:00
|
|
|
p.vstudio.vs2010 = {}
|
|
|
|
|
2014-02-08 15:44:57 +00:00
|
|
|
local vs2010 = p.vstudio.vs2010
|
|
|
|
local vstudio = p.vstudio
|
|
|
|
local project = p.project
|
|
|
|
local tree = p.tree
|
2013-05-02 15:21:23 +00:00
|
|
|
|
|
|
|
|
2015-01-15 17:00:57 +00:00
|
|
|
---
|
|
|
|
-- Map Premake tokens to the corresponding Visual Studio variables.
|
|
|
|
---
|
|
|
|
|
2017-06-19 19:50:34 +00:00
|
|
|
vs2010.pathVars = {
|
2015-12-18 00:13:35 +00:00
|
|
|
["cfg.objdir"] = { absolute = true, token = "$(IntDir)" },
|
|
|
|
["prj.location"] = { absolute = true, token = "$(ProjectDir)" },
|
|
|
|
["prj.name"] = { absolute = false, token = "$(ProjectName)" },
|
|
|
|
["sln.location"] = { absolute = true, token = "$(SolutionDir)" },
|
|
|
|
["sln.name"] = { absolute = false, token = "$(SolutionName)" },
|
|
|
|
["wks.location"] = { absolute = true, token = "$(SolutionDir)" },
|
|
|
|
["wks.name"] = { absolute = false, token = "$(SolutionName)" },
|
|
|
|
["cfg.buildtarget.directory"] = { absolute = false, token = "$(TargetDir)" },
|
|
|
|
["cfg.buildtarget.name"] = { absolute = false, token = "$(TargetFileName)" },
|
|
|
|
["cfg.buildtarget.basename"] = { absolute = false, token = "$(TargetName)" },
|
|
|
|
["file.basename"] = { absolute = false, token = "%(Filename)" },
|
|
|
|
["file.abspath"] = { absolute = true, token = "%(FullPath)" },
|
|
|
|
["file.relpath"] = { absolute = false, token = "%(Identity)" },
|
2017-01-19 20:37:45 +00:00
|
|
|
["file.path"] = { absolute = false, token = "%(Identity)" },
|
|
|
|
["file.directory"] = { absolute = true, token = "%(RootDir)%(Directory)" },
|
|
|
|
["file.reldirectory"] = { absolute = false, token = "%(RelativeDir)" },
|
|
|
|
["file.extension"] = { absolute = false, token = "%(Extension)" },
|
2015-01-15 17:00:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-05-22 15:15:48 +00:00
|
|
|
---
|
|
|
|
-- Identify the type of project being exported and hand it off
|
|
|
|
-- the right generator.
|
2013-05-02 15:21:23 +00:00
|
|
|
---
|
|
|
|
|
|
|
|
function vs2010.generateProject(prj)
|
2014-02-08 15:44:57 +00:00
|
|
|
p.eol("\r\n")
|
|
|
|
p.indent(" ")
|
|
|
|
p.escaper(vs2010.esc)
|
2013-05-22 15:15:48 +00:00
|
|
|
|
2017-08-30 18:35:42 +00:00
|
|
|
if p.project.iscsharp(prj) then
|
2017-01-31 20:10:40 +00:00
|
|
|
p.generate(prj, ".csproj", vstudio.cs2005.generate)
|
2015-03-12 15:26:29 +00:00
|
|
|
|
|
|
|
-- Skip generation of empty user files
|
|
|
|
local user = p.capture(function() vstudio.cs2005.generateUser(prj) end)
|
|
|
|
if #user > 0 then
|
|
|
|
p.generate(prj, ".csproj.user", function() p.outln(user) end)
|
|
|
|
end
|
|
|
|
|
2017-08-30 18:35:42 +00:00
|
|
|
elseif p.project.isfsharp(prj) then
|
|
|
|
p.generate(prj, ".fsproj", vstudio.fs2005.generate)
|
|
|
|
|
|
|
|
-- Skip generation of empty user files
|
|
|
|
local user = p.capture(function() vstudio.fs2005.generateUser(prj) end)
|
|
|
|
if #user > 0 then
|
|
|
|
p.generate(prj, ".fsproj.user", function() p.outln(user) end)
|
|
|
|
end
|
|
|
|
|
2017-01-31 20:10:40 +00:00
|
|
|
elseif p.project.isc(prj) or p.project.iscpp(prj) then
|
2017-04-07 19:17:10 +00:00
|
|
|
local projFileModified = p.generate(prj, ".vcxproj", vstudio.vc2010.generate)
|
2015-03-11 18:40:12 +00:00
|
|
|
|
|
|
|
-- Skip generation of empty user files
|
|
|
|
local user = p.capture(function() vstudio.vc2010.generateUser(prj) end)
|
|
|
|
if #user > 0 then
|
2015-03-11 21:36:25 +00:00
|
|
|
p.generate(prj, ".vcxproj.user", function() p.outln(user) end)
|
2015-03-11 18:40:12 +00:00
|
|
|
end
|
2013-10-27 14:56:22 +00:00
|
|
|
|
|
|
|
-- Only generate a filters file if the source tree actually has subfolders
|
|
|
|
if tree.hasbranches(project.getsourcetree(prj)) then
|
2017-04-07 19:17:10 +00:00
|
|
|
if p.generate(prj, ".vcxproj.filters", vstudio.vc2010.generateFilters) == true and projFileModified == false then
|
|
|
|
-- vs workaround for issue where if only the .filters file is modified, VS doesn't automaticly trigger a reload
|
|
|
|
p.touch(prj, ".vcxproj")
|
|
|
|
end
|
2013-10-27 14:56:22 +00:00
|
|
|
end
|
2013-05-02 15:21:23 +00:00
|
|
|
end
|
2017-04-04 16:17:00 +00:00
|
|
|
|
2017-09-21 22:40:25 +00:00
|
|
|
if not vstudio.nuget2010.supportsPackageReferences(prj) then
|
|
|
|
-- Skip generation of empty packages.config files
|
|
|
|
local packages = p.capture(function() vstudio.nuget2010.generatePackagesConfig(prj) end)
|
|
|
|
if #packages > 0 then
|
|
|
|
p.generate(prj, "packages.config", function() p.outln(packages) end)
|
|
|
|
end
|
2017-04-09 10:55:14 +00:00
|
|
|
|
2017-09-21 22:40:25 +00:00
|
|
|
-- Skip generation of empty NuGet.Config files
|
|
|
|
local config = p.capture(function() vstudio.nuget2010.generateNuGetConfig(prj) end)
|
|
|
|
if #config > 0 then
|
|
|
|
p.generate(prj, "NuGet.Config", function() p.outln(config) end)
|
|
|
|
end
|
2017-04-09 10:55:14 +00:00
|
|
|
end
|
2013-05-02 15:21:23 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
|
2013-05-22 15:15:48 +00:00
|
|
|
|
2014-08-11 21:02:36 +00:00
|
|
|
---
|
|
|
|
-- Generate the .props, .targets, and .xml files for custom rules.
|
|
|
|
---
|
|
|
|
|
|
|
|
function vs2010.generateRule(rule)
|
|
|
|
p.eol("\r\n")
|
|
|
|
p.indent(" ")
|
|
|
|
p.escaper(vs2010.esc)
|
|
|
|
|
2014-08-27 14:40:36 +00:00
|
|
|
p.generate(rule, ".props", vs2010.rules.props.generate)
|
|
|
|
p.generate(rule, ".targets", vs2010.rules.targets.generate)
|
|
|
|
p.generate(rule, ".xml", vs2010.rules.xml.generate)
|
2014-08-11 21:02:36 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-01-10 15:40:45 +00:00
|
|
|
--
|
|
|
|
-- The VS 2010 standard for XML escaping in generated project files.
|
|
|
|
--
|
|
|
|
|
|
|
|
function vs2010.esc(value)
|
|
|
|
value = value:gsub('&', "&")
|
|
|
|
value = value:gsub('<', "<")
|
|
|
|
value = value:gsub('>', ">")
|
|
|
|
return value
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-05-22 15:15:48 +00:00
|
|
|
---
|
|
|
|
-- Define the Visual Studio 2010 export action.
|
|
|
|
---
|
|
|
|
|
2013-05-02 15:21:23 +00:00
|
|
|
newaction {
|
|
|
|
-- Metadata for the command line and help system
|
|
|
|
|
|
|
|
trigger = "vs2010",
|
|
|
|
shortname = "Visual Studio 2010",
|
|
|
|
description = "Generate Visual Studio 2010 project files",
|
|
|
|
|
|
|
|
-- Visual Studio always uses Windows path and naming conventions
|
|
|
|
|
2017-04-11 20:39:25 +00:00
|
|
|
targetos = "windows",
|
2017-05-02 17:21:11 +00:00
|
|
|
toolset = "msc-v100",
|
2013-05-02 15:21:23 +00:00
|
|
|
|
|
|
|
-- The capabilities of this action
|
|
|
|
|
2015-07-14 16:31:06 +00:00
|
|
|
valid_kinds = { "ConsoleApp", "WindowedApp", "StaticLib", "SharedLib", "Makefile", "None", "Utility" },
|
2017-08-30 18:35:42 +00:00
|
|
|
valid_languages = { "C", "C++", "C#", "F#" },
|
2013-05-02 15:21:23 +00:00
|
|
|
valid_tools = {
|
|
|
|
cc = { "msc" },
|
|
|
|
dotnet = { "msnet" },
|
|
|
|
},
|
|
|
|
|
2015-08-12 18:53:12 +00:00
|
|
|
-- Workspace and project generation logic
|
2013-05-02 15:21:23 +00:00
|
|
|
|
2015-07-30 19:30:41 +00:00
|
|
|
onWorkspace = function(wks)
|
|
|
|
vstudio.vs2005.generateSolution(wks)
|
2015-04-09 05:58:30 +00:00
|
|
|
end,
|
|
|
|
onProject = function(prj)
|
|
|
|
vstudio.vs2010.generateProject(prj)
|
|
|
|
end,
|
2015-04-10 00:53:04 +00:00
|
|
|
onRule = function(rule)
|
|
|
|
vstudio.vs2010.generateRule(rule)
|
|
|
|
end,
|
2015-04-09 05:58:30 +00:00
|
|
|
|
2015-07-30 19:30:41 +00:00
|
|
|
onCleanWorkspace = function(wks)
|
|
|
|
vstudio.cleanSolution(wks)
|
2015-04-10 00:53:04 +00:00
|
|
|
end,
|
|
|
|
onCleanProject = function(prj)
|
|
|
|
vstudio.cleanProject(prj)
|
|
|
|
end,
|
|
|
|
onCleanTarget = function(prj)
|
|
|
|
vstudio.cleanTarget(prj)
|
|
|
|
end,
|
2013-05-02 15:21:23 +00:00
|
|
|
|
2017-06-19 19:50:34 +00:00
|
|
|
pathVars = vs2010.pathVars,
|
2015-01-15 17:00:57 +00:00
|
|
|
|
2013-05-02 15:21:23 +00:00
|
|
|
-- This stuff is specific to the Visual Studio exporters
|
|
|
|
|
|
|
|
vstudio = {
|
|
|
|
csprojSchemaVersion = "2.0",
|
|
|
|
productVersion = "8.0.30703",
|
|
|
|
solutionVersion = "11",
|
2013-10-29 05:47:39 +00:00
|
|
|
versionName = "2010",
|
2013-05-02 15:21:23 +00:00
|
|
|
targetFramework = "4.0",
|
|
|
|
toolsVersion = "4.0",
|
|
|
|
}
|
|
|
|
}
|