genie.lua 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618
  1. --
  2. -- Copyright 2010-2022 Branimir Karadzic. All rights reserved.
  3. -- License: https://github.com/bkaradzic/bgfx/blob/master/LICENSE
  4. --
  5. MODULE_DIR = path.getabsolute("../")
  6. newoption {
  7. trigger = "with-amalgamated",
  8. description = "Enable amalgamated build.",
  9. }
  10. newoption {
  11. trigger = "with-sdl",
  12. description = "Enable SDL entry.",
  13. }
  14. newoption {
  15. trigger = "with-glfw",
  16. description = "Enable GLFW entry.",
  17. }
  18. newoption {
  19. trigger = "with-wayland",
  20. description = "Use Wayland backend.",
  21. }
  22. newoption {
  23. trigger = "with-profiler",
  24. description = "Enable build with intrusive profiler.",
  25. }
  26. newoption {
  27. trigger = "with-shared-lib",
  28. description = "Enable building shared library.",
  29. }
  30. newoption {
  31. trigger = "with-tools",
  32. description = "Enable building tools.",
  33. }
  34. newoption {
  35. trigger = "with-combined-examples",
  36. description = "Enable building examples (combined as single executable).",
  37. }
  38. newoption {
  39. trigger = "with-examples",
  40. description = "Enable building examples.",
  41. }
  42. newoption {
  43. trigger = "with-webgpu",
  44. description = "Enable webgpu experimental renderer.",
  45. }
  46. newaction {
  47. trigger = "idl",
  48. description = "Generate bgfx interface source code",
  49. execute = function ()
  50. local gen = require "bgfx-codegen"
  51. local function generate(tempfile, outputfile, indent)
  52. local codes = gen.apply(tempfile)
  53. codes = gen.format(codes, {indent = indent})
  54. gen.write(codes, outputfile)
  55. print("Generating: " .. outputfile)
  56. end
  57. generate("temp.bgfx.h" , "../include/bgfx/c99/bgfx.h", " ")
  58. generate("temp.bgfx.idl.inl", "../src/bgfx.idl.inl", "\t")
  59. generate("temp.defines.h", "../include/bgfx/defines.h", "\t")
  60. do
  61. local csgen = require "bindings-cs"
  62. csgen.write(csgen.gen(), "../bindings/cs/bgfx.cs")
  63. csgen.write(csgen.gen_dllname(), "../bindings/cs/bgfx_dllname.cs")
  64. local dgen = require "bindings-d"
  65. dgen.write(dgen.gen_types(), "../bindings/d/types.d")
  66. dgen.write(dgen.gen_funcs(), "../bindings/d/funcs.d")
  67. local csgen = require "bindings-bf"
  68. csgen.write(csgen.gen(), "../bindings/bf/bgfx.bf")
  69. end
  70. os.exit()
  71. end
  72. }
  73. newaction {
  74. trigger = "version",
  75. description = "Generate bgfx version.h",
  76. execute = function ()
  77. local f = io.popen("git rev-list --count HEAD")
  78. local rev = string.match(f:read("*a"), ".*%S")
  79. local codegen = require "codegen"
  80. local idl = codegen.idl "bgfx.idl"
  81. print("1." .. idl._version .. "." .. rev)
  82. f:close()
  83. f = io.popen("git log --format=format:%H -1")
  84. local sha1 = f:read("*a")
  85. f:close()
  86. io.output(path.join(MODULE_DIR, "src/version.h"))
  87. io.write("/*\n")
  88. io.write(" * Copyright 2011-2022 Branimir Karadzic. All rights reserved.\n")
  89. io.write(" * License: https://github.com/bkaradzic/bgfx/blob/master/LICENSE\n")
  90. io.write(" */\n")
  91. io.write("\n")
  92. io.write("/*\n")
  93. io.write(" *\n")
  94. io.write(" * AUTO GENERATED! DO NOT EDIT!\n")
  95. io.write(" *\n")
  96. io.write(" */\n")
  97. io.write("\n")
  98. io.write("#define BGFX_REV_NUMBER " .. rev .. "\n")
  99. io.write("#define BGFX_REV_SHA1 \"" .. sha1 .. "\"\n")
  100. io.close()
  101. os.exit()
  102. end
  103. }
  104. solution "bgfx"
  105. configurations {
  106. "Debug",
  107. "Release",
  108. }
  109. if _ACTION ~= nil and _ACTION:match "^xcode" then
  110. platforms {
  111. "Native", -- let xcode decide based on the target output
  112. }
  113. else
  114. platforms {
  115. "x32",
  116. "x64",
  117. -- "Xbox360",
  118. "Native", -- for targets where bitness is not specified
  119. }
  120. end
  121. language "C++"
  122. startproject "example-00-helloworld"
  123. BGFX_DIR = path.getabsolute("..")
  124. BX_DIR = os.getenv("BX_DIR")
  125. BIMG_DIR = os.getenv("BIMG_DIR")
  126. local BGFX_BUILD_DIR = path.join(BGFX_DIR, ".build")
  127. local BGFX_THIRD_PARTY_DIR = path.join(BGFX_DIR, "3rdparty")
  128. if not BX_DIR then
  129. BX_DIR = path.getabsolute(path.join(BGFX_DIR, "../bx"))
  130. end
  131. if not BIMG_DIR then
  132. BIMG_DIR = path.getabsolute(path.join(BGFX_DIR, "../bimg"))
  133. end
  134. if not os.isdir(BX_DIR) or not os.isdir(BIMG_DIR) then
  135. if not os.isdir(BX_DIR) then
  136. print("bx not found at \"" .. BX_DIR .. "\". git clone https://github.com/bkaradzic/bx?")
  137. end
  138. if not os.isdir(BIMG_DIR) then
  139. print("bimg not found at \"" .. BIMG_DIR .. "\". git clone https://github.com/bkaradzic/bimg?")
  140. end
  141. print("For more info see: https://bkaradzic.github.io/bgfx/build.html")
  142. os.exit()
  143. end
  144. if _OPTIONS["with-webgpu"] then
  145. DAWN_DIR = os.getenv("DAWN_DIR")
  146. if not DAWN_DIR then
  147. DAWN_DIR = path.getabsolute(path.join(BGFX_DIR, "../dawn"))
  148. end
  149. if not os.isdir(DAWN_DIR) and "wasm*" ~= _OPTIONS["gcc"] then
  150. print("Dawn not found at \"" .. DAWN_DIR .. "\". git clone https://dawn.googlesource.com/dawn?")
  151. print("For more info see: https://bkaradzic.github.io/bgfx/build.html")
  152. os.exit()
  153. end
  154. _OPTIONS["with-windows"] = "10.0"
  155. end
  156. dofile (path.join(BX_DIR, "scripts/toolchain.lua"))
  157. if not toolchain(BGFX_BUILD_DIR, BGFX_THIRD_PARTY_DIR) then
  158. return -- no action specified
  159. end
  160. function copyLib()
  161. end
  162. if _OPTIONS["with-wayland"] then
  163. defines { "WL_EGL_PLATFORM=1" }
  164. end
  165. if _OPTIONS["with-sdl"] then
  166. if os.is("windows") then
  167. if not os.getenv("SDL2_DIR") then
  168. print("Set SDL2_DIR environment variable.")
  169. end
  170. end
  171. end
  172. if _OPTIONS["with-profiler"] then
  173. defines {
  174. "ENTRY_CONFIG_PROFILER=1",
  175. "BGFX_CONFIG_PROFILER=1",
  176. }
  177. end
  178. function exampleProjectDefaults()
  179. debugdir (path.join(BGFX_DIR, "examples/runtime"))
  180. includedirs {
  181. path.join(BIMG_DIR, "include"),
  182. path.join(BGFX_DIR, "include"),
  183. path.join(BGFX_DIR, "3rdparty"),
  184. path.join(BGFX_DIR, "examples/common"),
  185. }
  186. flags {
  187. "FatalWarnings",
  188. }
  189. links {
  190. "example-glue",
  191. "example-common",
  192. "bgfx",
  193. "bimg_decode",
  194. "bimg",
  195. }
  196. using_bx()
  197. if _OPTIONS["with-webgpu"] then
  198. usesWebGPU()
  199. end
  200. if _OPTIONS["with-sdl"] then
  201. defines { "ENTRY_CONFIG_USE_SDL=1" }
  202. links { "SDL2" }
  203. configuration { "linux or freebsd" }
  204. if _OPTIONS["with-wayland"] then
  205. links {
  206. "wayland-egl",
  207. }
  208. end
  209. configuration { "osx*" }
  210. libdirs { "$(SDL2_DIR)/lib" }
  211. configuration {}
  212. end
  213. if _OPTIONS["with-glfw"] then
  214. defines { "ENTRY_CONFIG_USE_GLFW=1" }
  215. links { "glfw3" }
  216. configuration { "linux or freebsd" }
  217. if _OPTIONS["with-wayland"] then
  218. links {
  219. "wayland-egl",
  220. }
  221. else
  222. links {
  223. "Xrandr",
  224. "Xinerama",
  225. "Xi",
  226. "Xxf86vm",
  227. "Xcursor",
  228. }
  229. end
  230. configuration { "osx*" }
  231. linkoptions {
  232. "-framework CoreVideo",
  233. }
  234. configuration {}
  235. end
  236. configuration { "vs*", "x32 or x64" }
  237. linkoptions {
  238. "/ignore:4199", -- LNK4199: /DELAYLOAD:*.dll ignored; no imports found from *.dll
  239. }
  240. links { -- this is needed only for testing with GLES2/3 on Windows with VS2008
  241. "DelayImp",
  242. }
  243. configuration { "vs201*", "x32 or x64" }
  244. linkoptions { -- this is needed only for testing with GLES2/3 on Windows with VS201x
  245. "/DELAYLOAD:\"libEGL.dll\"",
  246. "/DELAYLOAD:\"libGLESv2.dll\"",
  247. }
  248. configuration { "mingw*" }
  249. targetextension ".exe"
  250. links {
  251. "gdi32",
  252. "psapi",
  253. }
  254. configuration { "vs20*", "x32 or x64" }
  255. links {
  256. "gdi32",
  257. "psapi",
  258. }
  259. configuration { "durango" }
  260. links {
  261. "d3d11_x",
  262. "d3d12_x",
  263. "combase",
  264. "kernelx",
  265. }
  266. configuration { "winstore*" }
  267. removelinks {
  268. "DelayImp",
  269. "gdi32",
  270. "psapi"
  271. }
  272. links {
  273. "d3d11",
  274. "d3d12",
  275. "dxgi"
  276. }
  277. linkoptions {
  278. "/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
  279. }
  280. -- WinRT targets need their own output directories or build files stomp over each other
  281. configuration { "x32", "winstore*" }
  282. targetdir (path.join(BGFX_BUILD_DIR, "win32_" .. _ACTION, "bin", _name))
  283. objdir (path.join(BGFX_BUILD_DIR, "win32_" .. _ACTION, "obj", _name))
  284. configuration { "x64", "winstore*" }
  285. targetdir (path.join(BGFX_BUILD_DIR, "win64_" .. _ACTION, "bin", _name))
  286. objdir (path.join(BGFX_BUILD_DIR, "win64_" .. _ACTION, "obj", _name))
  287. configuration { "ARM", "winstore*" }
  288. targetdir (path.join(BGFX_BUILD_DIR, "arm_" .. _ACTION, "bin", _name))
  289. objdir (path.join(BGFX_BUILD_DIR, "arm_" .. _ACTION, "obj", _name))
  290. configuration { "mingw-clang" }
  291. kind "ConsoleApp"
  292. configuration { "android*" }
  293. kind "ConsoleApp"
  294. targetextension ".so"
  295. linkoptions {
  296. "-shared",
  297. }
  298. links {
  299. "EGL",
  300. "GLESv2",
  301. }
  302. configuration { "wasm*" }
  303. kind "ConsoleApp"
  304. linkoptions {
  305. "-s TOTAL_MEMORY=32MB",
  306. "-s ALLOW_MEMORY_GROWTH=1",
  307. "--preload-file ../../../examples/runtime@/"
  308. }
  309. removeflags {
  310. "OptimizeSpeed",
  311. }
  312. flags {
  313. "Optimize"
  314. }
  315. configuration { "linux-* or freebsd" }
  316. links {
  317. "X11",
  318. "GL",
  319. "pthread",
  320. }
  321. configuration { "rpi" }
  322. links {
  323. "X11",
  324. "brcmGLESv2",
  325. "brcmEGL",
  326. "bcm_host",
  327. "vcos",
  328. "vchiq_arm",
  329. "pthread",
  330. }
  331. configuration { "osx*" }
  332. linkoptions {
  333. "-framework Cocoa",
  334. "-framework IOKit",
  335. "-framework OpenGL",
  336. "-framework QuartzCore",
  337. "-weak_framework Metal",
  338. }
  339. configuration { "ios* or tvos*" }
  340. kind "ConsoleApp"
  341. linkoptions {
  342. "-framework CoreFoundation",
  343. "-framework Foundation",
  344. "-framework IOKit",
  345. "-framework OpenGLES",
  346. "-framework QuartzCore",
  347. "-framework UIKit",
  348. "-weak_framework Metal",
  349. }
  350. configuration { "xcode*", "ios" }
  351. kind "WindowedApp"
  352. files {
  353. path.join(BGFX_DIR, "examples/runtime/iOS-Info.plist"),
  354. }
  355. configuration { "xcode*", "tvos" }
  356. kind "WindowedApp"
  357. files {
  358. path.join(BGFX_DIR, "examples/runtime/tvOS-Info.plist"),
  359. }
  360. configuration { "qnx*" }
  361. targetextension ""
  362. links {
  363. "EGL",
  364. "GLESv2",
  365. }
  366. configuration {}
  367. strip()
  368. end
  369. function exampleProject(_combined, ...)
  370. if _combined then
  371. project ("examples")
  372. uuid (os.uuid("examples"))
  373. kind "WindowedApp"
  374. for _, name in ipairs({...}) do
  375. files {
  376. path.join(BGFX_DIR, "examples", name, "**.c"),
  377. path.join(BGFX_DIR, "examples", name, "**.cpp"),
  378. path.join(BGFX_DIR, "examples", name, "**.h"),
  379. }
  380. removefiles {
  381. path.join(BGFX_DIR, "examples", name, "**.bin.h"),
  382. }
  383. end
  384. files {
  385. path.join(BGFX_DIR, "examples/25-c99/helloworld.c"), -- hack for _main_
  386. }
  387. exampleProjectDefaults()
  388. else
  389. for _, name in ipairs({...}) do
  390. project ("example-" .. name)
  391. uuid (os.uuid("example-" .. name))
  392. kind "WindowedApp"
  393. files {
  394. path.join(BGFX_DIR, "examples", name, "**.c"),
  395. path.join(BGFX_DIR, "examples", name, "**.cpp"),
  396. path.join(BGFX_DIR, "examples", name, "**.h"),
  397. }
  398. removefiles {
  399. path.join(BGFX_DIR, "examples", name, "**.bin.h"),
  400. }
  401. defines {
  402. "ENTRY_CONFIG_IMPLEMENT_MAIN=1",
  403. }
  404. exampleProjectDefaults()
  405. end
  406. end
  407. end
  408. group "libs"
  409. dofile(path.join(BX_DIR, "scripts/bx.lua"))
  410. dofile(path.join(BIMG_DIR, "scripts/bimg.lua"))
  411. dofile(path.join(BIMG_DIR, "scripts/bimg_decode.lua"))
  412. dofile "bgfx.lua"
  413. local function userdefines()
  414. local defines = {}
  415. local BGFX_CONFIG = os.getenv("BGFX_CONFIG")
  416. if BGFX_CONFIG then
  417. for def in BGFX_CONFIG:gmatch "[^%s:]+" do
  418. table.insert(defines, "BGFX_CONFIG_" .. def)
  419. end
  420. end
  421. return defines
  422. end
  423. BGFX_CONFIG = userdefines()
  424. bgfxProject("", "StaticLib", BGFX_CONFIG)
  425. if _OPTIONS["with-shared-lib"] then
  426. group "libs"
  427. bgfxProject("-shared-lib", "SharedLib", BGFX_CONFIG)
  428. end
  429. if _OPTIONS["with-tools"] then
  430. group "libs"
  431. dofile(path.join(BIMG_DIR, "scripts/bimg_encode.lua"))
  432. end
  433. if _OPTIONS["with-examples"]
  434. or _OPTIONS["with-combined-examples"]
  435. or _OPTIONS["with-tools"] then
  436. group "examples"
  437. dofile "example-common.lua"
  438. end
  439. if _OPTIONS["with-examples"]
  440. or _OPTIONS["with-combined-examples"] then
  441. group "examples"
  442. exampleProject(_OPTIONS["with-combined-examples"]
  443. , "00-helloworld"
  444. , "01-cubes"
  445. , "02-metaballs"
  446. , "03-raymarch"
  447. , "04-mesh"
  448. , "05-instancing"
  449. , "06-bump"
  450. , "07-callback"
  451. , "08-update"
  452. , "09-hdr"
  453. , "10-font"
  454. , "11-fontsdf"
  455. , "12-lod"
  456. , "13-stencil"
  457. , "14-shadowvolumes"
  458. , "15-shadowmaps-simple"
  459. , "16-shadowmaps"
  460. , "18-ibl"
  461. , "19-oit"
  462. , "20-nanovg"
  463. , "21-deferred"
  464. , "22-windows"
  465. , "23-vectordisplay"
  466. , "24-nbody"
  467. , "26-occlusion"
  468. , "27-terrain"
  469. , "28-wireframe"
  470. , "29-debugdraw"
  471. , "30-picking"
  472. , "31-rsm"
  473. , "32-particles"
  474. , "33-pom"
  475. , "34-mvs"
  476. , "35-dynamic"
  477. , "36-sky"
  478. , "37-gpudrivenrendering"
  479. , "38-bloom"
  480. , "39-assao"
  481. , "40-svt"
  482. , "41-tess"
  483. , "42-bunnylod"
  484. , "43-denoise"
  485. , "44-sss"
  486. , "45-bokeh"
  487. , "46-fsr"
  488. )
  489. -- 17-drawstress requires multithreading, does not compile for singlethreaded wasm
  490. -- if platform is not single-threaded then
  491. exampleProject(false, "17-drawstress")
  492. -- end
  493. -- C99 source doesn't compile under WinRT settings
  494. if not premake.vstudio.iswinrt() then
  495. exampleProject(false, "25-c99")
  496. end
  497. end
  498. if _OPTIONS["with-tools"] then
  499. group "tools"
  500. dofile "shaderc.lua"
  501. dofile "texturec.lua"
  502. dofile "texturev.lua"
  503. dofile "geometryc.lua"
  504. dofile "geometryv.lua"
  505. end