genie.lua 12 KB

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