genie.lua 12 KB

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