vs2010.lua 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. --
  2. -- vs2010.lua
  3. -- Add support for the Visual Studio 2010 project formats.
  4. -- Copyright (c) Jason Perkins and the Premake project
  5. --
  6. local p = premake
  7. p.vstudio.vs2010 = {}
  8. local vs2010 = p.vstudio.vs2010
  9. local vstudio = p.vstudio
  10. local project = p.project
  11. local tree = p.tree
  12. ---
  13. -- Map Premake tokens to the corresponding Visual Studio variables.
  14. ---
  15. vs2010.pathVars = {
  16. ["cfg.objdir"] = { absolute = true, token = "$(IntDir)" },
  17. ["prj.location"] = { absolute = true, token = "$(ProjectDir)" },
  18. ["prj.name"] = { absolute = false, token = "$(ProjectName)" },
  19. ["sln.location"] = { absolute = true, token = "$(SolutionDir)" },
  20. ["sln.name"] = { absolute = false, token = "$(SolutionName)" },
  21. ["wks.location"] = { absolute = true, token = "$(SolutionDir)" },
  22. ["wks.name"] = { absolute = false, token = "$(SolutionName)" },
  23. ["cfg.buildtarget.directory"] = { absolute = false, token = "$(TargetDir)" },
  24. ["cfg.buildtarget.name"] = { absolute = false, token = "$(TargetFileName)" },
  25. ["cfg.buildtarget.basename"] = { absolute = false, token = "$(TargetName)" },
  26. ["file.basename"] = { absolute = false, token = "%(Filename)" },
  27. ["file.abspath"] = { absolute = true, token = "%(FullPath)" },
  28. ["file.relpath"] = { absolute = false, token = "%(Identity)" },
  29. ["file.path"] = { absolute = false, token = "%(Identity)" },
  30. ["file.directory"] = { absolute = true, token = "%(RootDir)%(Directory)" },
  31. ["file.reldirectory"] = { absolute = false, token = "%(RelativeDir)" },
  32. ["file.extension"] = { absolute = false, token = "%(Extension)" },
  33. ["file.name"] = { absolute = false, token = "%(Filename)%(Extension)" },
  34. }
  35. ---
  36. -- Identify the type of project being exported and hand it off
  37. -- the right generator.
  38. ---
  39. function vs2010.generateProject(prj)
  40. p.eol("\r\n")
  41. p.indent(" ")
  42. p.escaper(vs2010.esc)
  43. if p.project.iscsharp(prj) then
  44. p.generate(prj, ".csproj", vstudio.cs2005.generate)
  45. -- Skip generation of empty user files
  46. local user = p.capture(function() vstudio.cs2005.generateUser(prj) end)
  47. if #user > 0 then
  48. p.generate(prj, ".csproj.user", function() p.outln(user) end)
  49. end
  50. elseif p.project.isfsharp(prj) then
  51. p.generate(prj, ".fsproj", vstudio.fs2005.generate)
  52. -- Skip generation of empty user files
  53. local user = p.capture(function() vstudio.fs2005.generateUser(prj) end)
  54. if #user > 0 then
  55. p.generate(prj, ".fsproj.user", function() p.outln(user) end)
  56. end
  57. elseif p.project.isc(prj) or p.project.iscpp(prj) then
  58. if prj.kind == p.SHAREDITEMS then
  59. local projFileModified = p.generate(prj, ".vcxitems", vstudio.vc2013.generate)
  60. -- Only generate a filters file if the source tree actually has subfolders
  61. if tree.hasbranches(project.getsourcetree(prj)) then
  62. if p.generate(prj, ".vcxitems.filters", vstudio.vc2010.generateFilters) == true and projFileModified == false then
  63. -- vs workaround for issue where if only the .filters file is modified, VS doesn't automaticly trigger a reload
  64. p.touch(prj, ".vcxitems")
  65. end
  66. end
  67. else
  68. local projFileModified = p.generate(prj, ".vcxproj", vstudio.vc2010.generate)
  69. -- Skip generation of empty user files
  70. local user = p.capture(function() vstudio.vc2010.generateUser(prj) end)
  71. if #user > 0 then
  72. p.generate(prj, ".vcxproj.user", function() p.outln(user) end)
  73. end
  74. -- Only generate a filters file if the source tree actually has subfolders
  75. if tree.hasbranches(project.getsourcetree(prj)) then
  76. if p.generate(prj, ".vcxproj.filters", vstudio.vc2010.generateFilters) == true and projFileModified == false then
  77. -- vs workaround for issue where if only the .filters file is modified, VS doesn't automaticly trigger a reload
  78. p.touch(prj, ".vcxproj")
  79. end
  80. end
  81. end
  82. end
  83. if not vstudio.nuget2010.supportsPackageReferences(prj) then
  84. -- Skip generation of empty packages.config files
  85. local packages = p.capture(function() vstudio.nuget2010.generatePackagesConfig(prj) end)
  86. if #packages > 0 then
  87. p.generate(prj, "packages.config", function() p.outln(packages) end)
  88. end
  89. -- Skip generation of empty NuGet.Config files
  90. local config = p.capture(function() vstudio.nuget2010.generateNuGetConfig(prj) end)
  91. if #config > 0 then
  92. p.generate(prj, "NuGet.Config", function() p.outln(config) end)
  93. end
  94. end
  95. end
  96. ---
  97. -- Generate the .props, .targets, and .xml files for custom rules.
  98. ---
  99. function vs2010.generateRule(rule)
  100. p.eol("\r\n")
  101. p.indent(" ")
  102. p.escaper(vs2010.esc)
  103. p.generate(rule, ".props", vs2010.rules.props.generate)
  104. p.generate(rule, ".targets", vs2010.rules.targets.generate)
  105. p.generate(rule, ".xml", vs2010.rules.xml.generate)
  106. end
  107. --
  108. -- The VS 2010 standard for XML escaping in generated project files.
  109. --
  110. function vs2010.esc(value)
  111. value = value:gsub('&', "&")
  112. value = value:gsub('<', "&lt;")
  113. value = value:gsub('>', "&gt;")
  114. return value
  115. end
  116. ---
  117. -- Define the Visual Studio 2010 export action.
  118. ---
  119. newaction {
  120. -- Metadata for the command line and help system
  121. trigger = "vs2010",
  122. shortname = "Visual Studio 2010",
  123. description = "Generate Visual Studio 2010 project files",
  124. -- Visual Studio always uses Windows path and naming conventions
  125. targetos = "windows",
  126. toolset = "msc-v100",
  127. -- The capabilities of this action
  128. valid_kinds = { "ConsoleApp", "WindowedApp", "StaticLib", "SharedLib", "Makefile", "None", "Utility" },
  129. valid_languages = { "C", "C++", "C#", "F#" },
  130. valid_tools = {
  131. cc = { "msc" },
  132. dotnet = { "msnet" },
  133. },
  134. -- Workspace and project generation logic
  135. onWorkspace = function(wks)
  136. vstudio.vs2005.generateSolution(wks)
  137. end,
  138. onProject = function(prj)
  139. vstudio.vs2010.generateProject(prj)
  140. end,
  141. onRule = function(rule)
  142. vstudio.vs2010.generateRule(rule)
  143. end,
  144. onCleanWorkspace = function(wks)
  145. vstudio.cleanSolution(wks)
  146. end,
  147. onCleanProject = function(prj)
  148. vstudio.cleanProject(prj)
  149. end,
  150. onCleanTarget = function(prj)
  151. vstudio.cleanTarget(prj)
  152. end,
  153. pathVars = vs2010.pathVars,
  154. -- This stuff is specific to the Visual Studio exporters
  155. vstudio = {
  156. csprojSchemaVersion = "2.0",
  157. productVersion = "8.0.30703",
  158. solutionVersion = "11",
  159. versionName = "2010",
  160. targetFramework = "4.0",
  161. toolsVersion = "4.0",
  162. }
  163. }