bgfx.lua 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334
  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 { "android*" }
  59. targetextension ".so"
  60. configuration { "android*" ,"Debug"}
  61. linkoptions{"-soname libbgfx-shared-libDebug.so" }
  62. configuration { "android*" ,"Release"}
  63. linkoptions{"-soname libbgfx-shared-libRelease.so" }
  64. configuration {}
  65. end
  66. includedirs {
  67. path.join(BGFX_DIR, "3rdparty"),
  68. path.join(BX_DIR, "include"),
  69. path.join(BIMG_DIR, "include"),
  70. }
  71. defines (_defines)
  72. links {
  73. "bx",
  74. }
  75. if _OPTIONS["with-glfw"] then
  76. defines {
  77. "BGFX_CONFIG_MULTITHREADED=0",
  78. }
  79. end
  80. configuration { "Debug" }
  81. defines {
  82. "BGFX_CONFIG_DEBUG=1",
  83. }
  84. configuration { "vs* or mingw*", "not durango" }
  85. includedirs {
  86. path.join(BGFX_DIR, "3rdparty/dxsdk/include"),
  87. }
  88. configuration { "android*" }
  89. links {
  90. "EGL",
  91. "GLESv2",
  92. }
  93. configuration { "winstore*" }
  94. linkoptions {
  95. "/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
  96. }
  97. configuration { "*clang*" }
  98. buildoptions {
  99. "-Wno-microsoft-enum-value", -- enumerator value is not representable in the underlying type 'int'
  100. "-Wno-microsoft-const-init", -- default initialization of an object of const type '' without a user-provided default constructor is a Microsoft extension
  101. }
  102. configuration { "osx" }
  103. buildoptions { "-x objective-c++" } -- additional build option for osx
  104. linkoptions {
  105. "-framework Cocoa",
  106. "-framework QuartzCore",
  107. "-framework OpenGL",
  108. "-weak_framework Metal",
  109. "-weak_framework MetalKit",
  110. }
  111. configuration { "not NX32", "not NX64" }
  112. includedirs {
  113. -- NX has EGL headers modified...
  114. path.join(BGFX_DIR, "3rdparty/khronos"),
  115. }
  116. configuration {}
  117. includedirs {
  118. path.join(BGFX_DIR, "include"),
  119. }
  120. files {
  121. path.join(BGFX_DIR, "include/**.h"),
  122. path.join(BGFX_DIR, "src/**.cpp"),
  123. path.join(BGFX_DIR, "src/**.h"),
  124. path.join(BGFX_DIR, "scripts/**.natvis"),
  125. }
  126. removefiles {
  127. path.join(BGFX_DIR, "src/**.bin.h"),
  128. }
  129. overridefiles(BGFX_DIR, path.join(BGFX_DIR, "../bgfx-gnm"), {
  130. path.join(BGFX_DIR, "src/renderer_gnm.cpp"),
  131. path.join(BGFX_DIR, "src/renderer_gnm.h"),
  132. })
  133. overridefiles(BGFX_DIR, path.join(BGFX_DIR, "../bgfx-nvn"), {
  134. path.join(BGFX_DIR, "src/renderer_nvn.cpp"),
  135. path.join(BGFX_DIR, "src/renderer_nvn.h"),
  136. })
  137. if _OPTIONS["with-webgpu"] then
  138. defines {
  139. "BGFX_CONFIG_RENDERER_WEBGPU=1",
  140. }
  141. local generator = "out/VS2019"
  142. configuration { "wasm*" }
  143. defines {
  144. "BGFX_CONFIG_RENDERER_OPENGL=0",
  145. "BGFX_CONFIG_RENDERER_OPENGLES=0",
  146. }
  147. configuration { "not wasm*" }
  148. includedirs {
  149. path.join(DAWN_DIR, "src"),
  150. path.join(DAWN_DIR, "src/include"),
  151. path.join(DAWN_DIR, "third_party/vulkan-headers/include"),
  152. path.join(DAWN_DIR, generator, "gen/src"),
  153. path.join(DAWN_DIR, generator, "gen/src/include"),
  154. }
  155. configuration { "vs*" }
  156. defines {
  157. "NTDDI_VERSION=NTDDI_WIN10_RS2",
  158. -- We can't say `=_WIN32_WINNT_WIN10` here because some files do
  159. -- `#if WINVER < 0x0600` without including windows.h before,
  160. -- and then _WIN32_WINNT_WIN10 isn't yet known to be 0x0A00.
  161. "_WIN32_WINNT=0x0A00",
  162. "WINVER=0x0A00",
  163. }
  164. configuration {}
  165. end
  166. if _OPTIONS["with-amalgamated"] then
  167. excludes {
  168. path.join(BGFX_DIR, "src/bgfx.cpp"),
  169. path.join(BGFX_DIR, "src/debug_**.cpp"),
  170. path.join(BGFX_DIR, "src/dxgi.cpp"),
  171. path.join(BGFX_DIR, "src/glcontext_**.cpp"),
  172. path.join(BGFX_DIR, "src/hmd**.cpp"),
  173. path.join(BGFX_DIR, "src/image.cpp"),
  174. path.join(BGFX_DIR, "src/nvapi.cpp"),
  175. path.join(BGFX_DIR, "src/renderer_**.cpp"),
  176. path.join(BGFX_DIR, "src/shader**.cpp"),
  177. path.join(BGFX_DIR, "src/topology.cpp"),
  178. path.join(BGFX_DIR, "src/vertexlayout.cpp"),
  179. }
  180. configuration { "xcode* or osx or ios*" }
  181. files {
  182. path.join(BGFX_DIR, "src/amalgamated.mm"),
  183. }
  184. excludes {
  185. path.join(BGFX_DIR, "src/glcontext_**.mm"),
  186. path.join(BGFX_DIR, "src/renderer_**.mm"),
  187. path.join(BGFX_DIR, "src/amalgamated.cpp"),
  188. }
  189. configuration { "not (xcode* or osx or ios*)" }
  190. excludes {
  191. path.join(BGFX_DIR, "src/**.mm"),
  192. }
  193. configuration {}
  194. else
  195. configuration { "xcode* or osx or ios*" }
  196. files {
  197. path.join(BGFX_DIR, "src/glcontext_**.mm"),
  198. path.join(BGFX_DIR, "src/renderer_**.mm"),
  199. }
  200. configuration {}
  201. excludes {
  202. path.join(BGFX_DIR, "src/amalgamated.**"),
  203. }
  204. end
  205. if filesexist(BGFX_DIR, path.join(BGFX_DIR, "../bgfx-gnm"), {
  206. path.join(BGFX_DIR, "scripts/bgfx.lua"), }) then
  207. dofile(path.join(BGFX_DIR, "../bgfx-gnm/scripts/bgfx.lua") )
  208. end
  209. if filesexist(BGFX_DIR, path.join(BGFX_DIR, "../bgfx-nvn"), {
  210. path.join(BGFX_DIR, "scripts/bgfx.lua"), }) then
  211. dofile(path.join(BGFX_DIR, "../bgfx-nvn/scripts/bgfx.lua") )
  212. end
  213. configuration {}
  214. end
  215. function bgfxProject(_name, _kind, _defines)
  216. project ("bgfx" .. _name)
  217. uuid (os.uuid("bgfx" .. _name))
  218. bgfxProjectBase(_kind, _defines)
  219. copyLib()
  220. end
  221. if _OPTIONS["with-webgpu"] then
  222. function usesWebGPU()
  223. configuration { "wasm*" }
  224. linkoptions {
  225. "-s USE_WEBGPU=1",
  226. }
  227. configuration { "not wasm*" }
  228. --local generator = "out/Default"
  229. local generator = "out/VS2019"
  230. includedirs {
  231. path.join(DAWN_DIR, "src"),
  232. path.join(DAWN_DIR, "src/include"),
  233. path.join(DAWN_DIR, generator, "gen/src"),
  234. path.join(DAWN_DIR, generator, "gen/src/include"),
  235. }
  236. libdirs {
  237. path.join(DAWN_DIR, generator),
  238. path.join(DAWN_DIR, generator, "lib/Debug"),
  239. }
  240. files {
  241. path.join(DAWN_DIR, generator, "gen/src/dawn/webgpu_cpp.cpp"),
  242. }
  243. links {
  244. -- shared
  245. "dawn_proc_shared",
  246. "dawn_native_shared",
  247. "shaderc_spvc_shared",
  248. -- static
  249. --"dawn_common",
  250. --"dawn_proc",
  251. --"dawn_native",
  252. --"dawn_platform",
  253. ------"shaderc",
  254. --"shaderc_spvc",
  255. --"SPIRV-tools",
  256. --"SPIRV-tools-opt",
  257. --"spirv-cross-cored",
  258. --"spirv-cross-hlsld",
  259. --"spirv-cross-glsld",
  260. --"spirv-cross-msld",
  261. --"spirv-cross-reflectd",
  262. }
  263. removeflags {
  264. "FatalWarnings",
  265. }
  266. configuration {}
  267. end
  268. end