bgfx.lua 7.3 KB

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