vsandroid_androidproj.lua 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  1. --
  2. -- android/vsandroid_androidproj.lua
  3. -- vs-android integration for vstudio.
  4. -- Copyright (c) 2012-2015 Manu Evans and the Premake project
  5. --
  6. local p = premake
  7. local android = p.modules.android
  8. local vsandroid = p.modules.vsandroid
  9. local vc2010 = p.vstudio.vc2010
  10. local vstudio = p.vstudio
  11. local project = p.project
  12. --
  13. -- Add android tools to vstudio actions.
  14. --
  15. premake.override(vstudio.vs2010, "generateProject", function(oldfn, prj)
  16. if prj.kind == p.PACKAGING then
  17. p.eol("\r\n")
  18. p.indent(" ")
  19. p.escaper(vstudio.vs2010.esc)
  20. if project.iscpp(prj) then
  21. p.generate(prj, ".androidproj", vc2010.generate)
  22. -- Skip generation of empty user files
  23. local user = p.capture(function() vc2010.generateUser(prj) end)
  24. if #user > 0 then
  25. p.generate(prj, ".androidproj.user", function() p.outln(user) end)
  26. end
  27. end
  28. else
  29. oldfn(prj)
  30. end
  31. end)
  32. premake.override(vstudio, "projectfile", function(oldfn, prj)
  33. if prj.kind == p.PACKAGING then
  34. return premake.filename(prj, ".androidproj")
  35. else
  36. return oldfn(prj)
  37. end
  38. end)
  39. premake.override(vstudio, "tool", function(oldfn, prj)
  40. if prj.kind == p.PACKAGING then
  41. return "39E2626F-3545-4960-A6E8-258AD8476CE5"
  42. else
  43. return oldfn(prj)
  44. end
  45. end)
  46. premake.override(vc2010.elements, "globals", function (oldfn, cfg)
  47. local elements = oldfn(cfg)
  48. if cfg.kind == premake.PACKAGING then
  49. -- Remove "IgnoreWarnCompileDuplicatedFilename".
  50. local pos = table.indexof(elements, vc2010.ignoreWarnDuplicateFilename)
  51. table.remove(elements, pos)
  52. elements = table.join(elements, {
  53. android.projectVersion
  54. })
  55. end
  56. return elements
  57. end)
  58. function android.projectVersion(cfg)
  59. _p(2, "<RootNamespace>%s</RootNamespace>", cfg.project.name)
  60. _p(2, "<MinimumVisualStudioVersion>14.0</MinimumVisualStudioVersion>")
  61. _p(2, "<ProjectVersion>1.0</ProjectVersion>")
  62. end
  63. premake.override(vc2010.elements, "configurationProperties", function(oldfn, cfg)
  64. local elements = oldfn(cfg)
  65. if cfg.kind == p.PACKAGING then
  66. elements = {
  67. android.androidAPILevel,
  68. vc2010.useDebugLibraries,
  69. }
  70. end
  71. return elements
  72. end)
  73. premake.override(vc2010.elements, "itemDefinitionGroup", function(oldfn, cfg)
  74. local elements = oldfn(cfg)
  75. if cfg.kind == p.PACKAGING then
  76. elements = {
  77. android.antPackage,
  78. }
  79. end
  80. return elements
  81. end)
  82. premake.override(vc2010, "importDefaultProps", function(oldfn, prj)
  83. if prj.kind == p.PACKAGING then
  84. p.w('<Import Project="$(AndroidTargetsPath)\\Android.Default.props" />')
  85. else
  86. oldfn(prj)
  87. end
  88. end)
  89. premake.override(vc2010, "importLanguageSettings", function(oldfn, prj)
  90. if prj.kind == p.PACKAGING then
  91. p.w('<Import Project="$(AndroidTargetsPath)\\Android.props" />')
  92. else
  93. oldfn(prj)
  94. end
  95. end)
  96. premake.override(vc2010, "propertySheets", function(oldfn, cfg)
  97. if cfg.kind ~= p.PACKAGING then
  98. oldfn(cfg)
  99. end
  100. end)
  101. premake.override(vc2010.elements, "outputProperties", function(oldfn, cfg)
  102. if cfg.kind == p.PACKAGING then
  103. return {
  104. android.outDir,
  105. vc2010.intDir,
  106. vc2010.targetName,
  107. }
  108. else
  109. return oldfn(cfg)
  110. end
  111. end)
  112. function android.outDir(cfg)
  113. vc2010.element("OutDir", nil, "%s\\", cfg.buildtarget.directory)
  114. end
  115. premake.override(vc2010, "importLanguageTargets", function(oldfn, prj)
  116. if prj.kind == p.PACKAGING then
  117. p.w('<Import Project="$(AndroidTargetsPath)\\Android.targets" />')
  118. else
  119. oldfn(prj)
  120. end
  121. end)
  122. function android.link(cfg, file)
  123. -- default the seperator to '/' as that is what is searched for
  124. -- below. Otherwise the function will use target seperator which
  125. -- could be '\\' and result in failure to create links.
  126. local fname = path.translate(file.relpath, '/')
  127. -- Files that live outside of the project tree need to be "linked"
  128. -- and provided with a project relative pseudo-path. Check for any
  129. -- leading "../" sequences and, if found, remove them and mark this
  130. -- path as external.
  131. local link, count = fname:gsub("%.%.%/", "")
  132. local external = (count > 0) or fname:find(':', 1, true) or (file.vpath and file.vpath ~= file.relpath)
  133. -- Try to provide a little bit of flexibility by allowing virtual
  134. -- paths for external files. Would be great to support them for all
  135. -- files but Visual Studio chokes if file is already in project area.
  136. if external and file.vpath ~= file.relpath then
  137. link = file.vpath
  138. end
  139. if external then
  140. vc2010.element("Link", nil, path.translate(link))
  141. end
  142. end
  143. vc2010.categories.AndroidManifest = {
  144. name = "AndroidManifest",
  145. priority = 99,
  146. emitFiles = function(prj, group)
  147. vc2010.emitFiles(prj, group, "AndroidManifest", {vc2010.generatedFile, android.link, android.manifestSubType})
  148. end,
  149. emitFilter = function(prj, group)
  150. vc2010.filterGroup(prj, group, "AndroidManifest")
  151. end
  152. }
  153. function android.manifestSubType(cfg, file)
  154. vc2010.element("SubType", nil, "Designer")
  155. end
  156. vc2010.categories.AntBuildXml = {
  157. name = "AntBuildXml",
  158. priority = 99,
  159. emitFiles = function(prj, group)
  160. vc2010.emitFiles(prj, group, "AntBuildXml", {vc2010.generatedFile, android.link})
  161. end,
  162. emitFilter = function(prj, group)
  163. vc2010.filterGroup(prj, group, "AntBuildXml")
  164. end
  165. }
  166. vc2010.categories.AntProjectPropertiesFile = {
  167. name = "AntProjectPropertiesFile",
  168. priority = 99,
  169. emitFiles = function(prj, group)
  170. vc2010.emitFiles(prj, group, "AntProjectPropertiesFile", {vc2010.generatedFile, android.link})
  171. end,
  172. emitFilter = function(prj, group)
  173. vc2010.filterGroup(prj, group, "AntProjectPropertiesFile")
  174. end
  175. }
  176. vc2010.categories.JavaCompile = {
  177. name = "JavaCompile",
  178. priority = 99,
  179. emitFiles = function(prj, group)
  180. vc2010.emitFiles(prj, group, "JavaCompile", {vc2010.generatedFile, android.link})
  181. end,
  182. emitFilter = function(prj, group)
  183. vc2010.filterGroup(prj, group, "JavaCompile")
  184. end
  185. }
  186. vc2010.categories.Content = {
  187. name = "Content",
  188. priority = 99,
  189. emitFiles = function(prj, group)
  190. vc2010.emitFiles(prj, group, "Content", {vc2010.generatedFile, android.link})
  191. end,
  192. emitFilter = function(prj, group)
  193. vc2010.filterGroup(prj, group, "Content")
  194. end
  195. }
  196. premake.override(vc2010, "categorizeFile", function(base, prj, file)
  197. if prj.kind ~= p.PACKAGING then
  198. return base(prj, file)
  199. end
  200. local filename = path.getname(file.name):lower()
  201. local extension = path.getextension(filename)
  202. if filename == "androidmanifest.xml" then
  203. return vc2010.categories.AndroidManifest
  204. elseif filename == "build.xml" then
  205. return vc2010.categories.AntBuildXml
  206. elseif filename == "project.properties" then
  207. return vc2010.categories.AntProjectPropertiesFile
  208. elseif extension == ".java" then
  209. return vc2010.categories.JavaCompile
  210. else
  211. return vc2010.categories.Content
  212. end
  213. end)