bgfx.lua 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329
  1. --
  2. -- Copyright 2010-2020 Branimir Karadzic. All rights reserved.
  3. -- License: https://github.com/bkaradzic/bgfx#license-bsd-2-clause
  4. --
  5. function filesexist(_srcPath, _dstPath, _files)
  6. for _, file in ipairs(_files) do
  7. file = path.getrelative(_srcPath, file)
  8. local filePath = path.join(_dstPath, file)
  9. if not os.isfile(filePath) then return false end
  10. end
  11. return true
  12. end
  13. function overridefiles(_srcPath, _dstPath, _files)
  14. local remove = {}
  15. local add = {}
  16. for _, file in ipairs(_files) do
  17. file = path.getrelative(_srcPath, file)
  18. local filePath = path.join(_dstPath, file)
  19. if not os.isfile(filePath) then return end
  20. table.insert(remove, path.join(_srcPath, file))
  21. table.insert(add, filePath)
  22. end
  23. removefiles {
  24. remove,
  25. }
  26. files {
  27. add,
  28. }
  29. end
  30. function bgfxProjectBase(_kind, _defines)
  31. kind (_kind)
  32. if _kind == "SharedLib" then
  33. defines {
  34. "BGFX_SHARED_LIB_BUILD=1",
  35. }
  36. links {
  37. "bimg",
  38. "bx",
  39. }
  40. configuration { "vs20* or mingw*" }
  41. links {
  42. "gdi32",
  43. "psapi",
  44. }
  45. configuration { "mingw*" }
  46. linkoptions {
  47. "-shared",
  48. }
  49. configuration { "linux-*" }
  50. buildoptions {
  51. "-fPIC",
  52. }
  53. links {
  54. "X11",
  55. "GL",
  56. "pthread",
  57. }
  58. configuration {}
  59. end
  60. includedirs {
  61. path.join(BGFX_DIR, "3rdparty"),
  62. path.join(BX_DIR, "include"),
  63. path.join(BIMG_DIR, "include"),
  64. }
  65. defines {
  66. _defines,
  67. }
  68. links {
  69. "bx",
  70. }
  71. if _OPTIONS["with-glfw"] then
  72. defines {
  73. "BGFX_CONFIG_MULTITHREADED=0",
  74. }
  75. end
  76. configuration { "Debug" }
  77. defines {
  78. "BGFX_CONFIG_DEBUG=1",
  79. }
  80. configuration { "vs* or mingw*", "not durango" }
  81. includedirs {
  82. path.join(BGFX_DIR, "3rdparty/dxsdk/include"),
  83. }
  84. configuration { "android*" }
  85. links {
  86. "EGL",
  87. "GLESv2",
  88. }
  89. configuration { "winstore*" }
  90. linkoptions {
  91. "/ignore:4264" -- LNK4264: archiving object file compiled with /ZW into a static library; note that when authoring Windows Runtime types it is not recommended to link with a static library that contains Windows Runtime metadata
  92. }
  93. configuration { "*clang*" }
  94. buildoptions {
  95. "-Wno-microsoft-enum-value", -- enumerator value is not representable in the underlying type 'int'
  96. "-Wno-microsoft-const-init", -- default initialization of an object of const type '' without a user-provided default constructor is a Microsoft extension
  97. }
  98. configuration { "osx" }
  99. buildoptions { "-x objective-c++" } -- additional build option for osx
  100. linkoptions {
  101. "-framework Cocoa",
  102. "-framework QuartzCore",
  103. "-framework OpenGL",
  104. "-weak_framework Metal",
  105. "-weak_framework MetalKit",
  106. }
  107. configuration { "not NX32", "not NX64" }
  108. includedirs {
  109. -- NX has EGL headers modified...
  110. path.join(BGFX_DIR, "3rdparty/khronos"),
  111. }
  112. configuration {}
  113. includedirs {
  114. path.join(BGFX_DIR, "include"),
  115. }
  116. files {
  117. path.join(BGFX_DIR, "include/**.h"),
  118. path.join(BGFX_DIR, "src/**.cpp"),
  119. path.join(BGFX_DIR, "src/**.h"),
  120. path.join(BGFX_DIR, "scripts/**.natvis"),
  121. }
  122. removefiles {
  123. path.join(BGFX_DIR, "src/**.bin.h"),
  124. }
  125. overridefiles(BGFX_DIR, path.join(BGFX_DIR, "../bgfx-gnm"), {
  126. path.join(BGFX_DIR, "src/renderer_gnm.cpp"),
  127. path.join(BGFX_DIR, "src/renderer_gnm.h"),
  128. })
  129. overridefiles(BGFX_DIR, path.join(BGFX_DIR, "../bgfx-nvn"), {
  130. path.join(BGFX_DIR, "src/renderer_nvn.cpp"),
  131. path.join(BGFX_DIR, "src/renderer_nvn.h"),
  132. })
  133. if _OPTIONS["webgpu"] then
  134. defines {
  135. "BGFX_CONFIG_RENDERER_WEBGPU=1",
  136. }
  137. configuration { "asmjs" }
  138. defines {
  139. "BGFX_CONFIG_RENDERER_OPENGL=0",
  140. "BGFX_CONFIG_RENDERER_OPENGLES=0",
  141. }
  142. configuration { "not asmjs" }
  143. --local generator = "out/Default"
  144. local generator = "out/VS2019"
  145. includedirs {
  146. path.join(DAWN_DIR, "src"),
  147. path.join(DAWN_DIR, "src/include"),
  148. path.join(DAWN_DIR, "third_party/vulkan-headers/include"),
  149. path.join(DAWN_DIR, generator, "gen/src"),
  150. path.join(DAWN_DIR, generator, "gen/src/include"),
  151. }
  152. configuration { "vs*" }
  153. defines {
  154. "NTDDI_VERSION=NTDDI_WIN10_RS2",
  155. -- We can't say `=_WIN32_WINNT_WIN10` here because some files do
  156. -- `#if WINVER < 0x0600` without including windows.h before,
  157. -- and then _WIN32_WINNT_WIN10 isn't yet known to be 0x0A00.
  158. "_WIN32_WINNT=0x0A00",
  159. "WINVER=0x0A00",
  160. }
  161. configuration {}
  162. end
  163. if _OPTIONS["with-amalgamated"] then
  164. excludes {
  165. path.join(BGFX_DIR, "src/bgfx.cpp"),
  166. path.join(BGFX_DIR, "src/debug_**.cpp"),
  167. path.join(BGFX_DIR, "src/dxgi.cpp"),
  168. path.join(BGFX_DIR, "src/glcontext_**.cpp"),
  169. path.join(BGFX_DIR, "src/hmd**.cpp"),
  170. path.join(BGFX_DIR, "src/image.cpp"),
  171. path.join(BGFX_DIR, "src/nvapi.cpp"),
  172. path.join(BGFX_DIR, "src/renderer_**.cpp"),
  173. path.join(BGFX_DIR, "src/shader**.cpp"),
  174. path.join(BGFX_DIR, "src/topology.cpp"),
  175. path.join(BGFX_DIR, "src/vertexlayout.cpp"),
  176. }
  177. configuration { "xcode* or osx or ios*" }
  178. files {
  179. path.join(BGFX_DIR, "src/amalgamated.mm"),
  180. }
  181. excludes {
  182. path.join(BGFX_DIR, "src/glcontext_**.mm"),
  183. path.join(BGFX_DIR, "src/renderer_**.mm"),
  184. path.join(BGFX_DIR, "src/amalgamated.cpp"),
  185. }
  186. configuration { "not (xcode* or osx or ios*)" }
  187. excludes {
  188. path.join(BGFX_DIR, "src/**.mm"),
  189. }
  190. configuration {}
  191. else
  192. configuration { "xcode* or osx or ios*" }
  193. files {
  194. path.join(BGFX_DIR, "src/glcontext_**.mm"),
  195. path.join(BGFX_DIR, "src/renderer_**.mm"),
  196. }
  197. configuration {}
  198. excludes {
  199. path.join(BGFX_DIR, "src/amalgamated.**"),
  200. }
  201. end
  202. if filesexist(BGFX_DIR, path.join(BGFX_DIR, "../bgfx-gnm"), {
  203. path.join(BGFX_DIR, "scripts/bgfx.lua"), }) then
  204. dofile(path.join(BGFX_DIR, "../bgfx-gnm/scripts/bgfx.lua") )
  205. end
  206. if filesexist(BGFX_DIR, path.join(BGFX_DIR, "../bgfx-nvn"), {
  207. path.join(BGFX_DIR, "scripts/bgfx.lua"), }) then
  208. dofile(path.join(BGFX_DIR, "../bgfx-nvn/scripts/bgfx.lua") )
  209. end
  210. configuration {}
  211. end
  212. function bgfxProject(_name, _kind, _defines)
  213. project ("bgfx" .. _name)
  214. uuid (os.uuid("bgfx" .. _name))
  215. bgfxProjectBase(_kind, _defines)
  216. copyLib()
  217. end
  218. if _OPTIONS["webgpu"] then
  219. function usesWebGPU()
  220. configuration { "asmjs" }
  221. linkoptions {
  222. "-s USE_WEBGPU=1",
  223. }
  224. configuration { "not asmjs" }
  225. --local generator = "out/Default"
  226. local generator = "out/VS2019"
  227. includedirs {
  228. path.join(DAWN_DIR, "src"),
  229. path.join(DAWN_DIR, "src/include"),
  230. path.join(DAWN_DIR, generator, "gen/src"),
  231. path.join(DAWN_DIR, generator, "gen/src/include"),
  232. }
  233. libdirs {
  234. path.join(DAWN_DIR, generator),
  235. path.join(DAWN_DIR, generator, "lib/Debug"),
  236. }
  237. files {
  238. path.join(DAWN_DIR, generator, "gen/src/dawn/webgpu_cpp.cpp"),
  239. }
  240. links {
  241. -- shared
  242. "dawn_proc_shared",
  243. "dawn_native_shared",
  244. "shaderc_spvc_shared",
  245. -- static
  246. --"dawn_common",
  247. --"dawn_proc",
  248. --"dawn_native",
  249. --"dawn_platform",
  250. ------"shaderc",
  251. --"shaderc_spvc",
  252. --"SPIRV-tools",
  253. --"SPIRV-tools-opt",
  254. --"spirv-cross-cored",
  255. --"spirv-cross-hlsld",
  256. --"spirv-cross-glsld",
  257. --"spirv-cross-msld",
  258. --"spirv-cross-reflectd",
  259. }
  260. removeflags {
  261. "FatalWarnings",
  262. }
  263. configuration {}
  264. end
  265. end