genie.lua 12 KB

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