genie.lua 12 KB

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