genie.lua 12 KB

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