genie.lua 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602
  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. 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-wayland"] then
  149. defines { "WL_EGL_PLATFORM=1" }
  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 { "linux or freebsd" }
  187. if _OPTIONS["with-wayland"] then
  188. links {
  189. "wayland-egl",
  190. }
  191. end
  192. configuration { "osx*" }
  193. libdirs { "$(SDL2_DIR)/lib" }
  194. configuration {}
  195. end
  196. if _OPTIONS["with-glfw"] then
  197. defines { "ENTRY_CONFIG_USE_GLFW=1" }
  198. links { "glfw3" }
  199. configuration { "linux or freebsd" }
  200. if _OPTIONS["with-wayland"] then
  201. links {
  202. "wayland-egl",
  203. }
  204. else
  205. links {
  206. "Xrandr",
  207. "Xinerama",
  208. "Xi",
  209. "Xxf86vm",
  210. "Xcursor",
  211. }
  212. end
  213. configuration { "osx*" }
  214. linkoptions {
  215. "-framework CoreVideo",
  216. }
  217. configuration {}
  218. end
  219. configuration { "vs*", "x32 or x64" }
  220. linkoptions {
  221. "/ignore:4199", -- LNK4199: /DELAYLOAD:*.dll ignored; no imports found from *.dll
  222. }
  223. links { -- this is needed only for testing with GLES2/3 on Windows with VS2008
  224. "DelayImp",
  225. }
  226. configuration { "vs201*", "x32 or x64" }
  227. linkoptions { -- this is needed only for testing with GLES2/3 on Windows with VS201x
  228. "/DELAYLOAD:\"libEGL.dll\"",
  229. "/DELAYLOAD:\"libGLESv2.dll\"",
  230. }
  231. configuration { "mingw*" }
  232. targetextension ".exe"
  233. links {
  234. "comdlg32",
  235. "gdi32",
  236. "psapi",
  237. }
  238. configuration { "vs20*", "x32 or x64" }
  239. links {
  240. "gdi32",
  241. "psapi",
  242. }
  243. configuration { "durango" }
  244. links {
  245. "d3d11_x",
  246. "d3d12_x",
  247. "combase",
  248. "kernelx",
  249. }
  250. configuration { "winstore*" }
  251. removelinks {
  252. "DelayImp",
  253. "gdi32",
  254. "psapi"
  255. }
  256. links {
  257. "d3d11",
  258. "d3d12",
  259. "dxgi"
  260. }
  261. linkoptions {
  262. "/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
  263. }
  264. -- WinRT targets need their own output directories or build files stomp over each other
  265. configuration { "x32", "winstore*" }
  266. targetdir (path.join(BGFX_BUILD_DIR, "win32_" .. _ACTION, "bin", _name))
  267. objdir (path.join(BGFX_BUILD_DIR, "win32_" .. _ACTION, "obj", _name))
  268. configuration { "x64", "winstore*" }
  269. targetdir (path.join(BGFX_BUILD_DIR, "win64_" .. _ACTION, "bin", _name))
  270. objdir (path.join(BGFX_BUILD_DIR, "win64_" .. _ACTION, "obj", _name))
  271. configuration { "ARM", "winstore*" }
  272. targetdir (path.join(BGFX_BUILD_DIR, "arm_" .. _ACTION, "bin", _name))
  273. objdir (path.join(BGFX_BUILD_DIR, "arm_" .. _ACTION, "obj", _name))
  274. configuration { "mingw-clang" }
  275. kind "ConsoleApp"
  276. configuration { "android*" }
  277. kind "ConsoleApp"
  278. targetextension ".so"
  279. linkoptions {
  280. "-shared",
  281. }
  282. links {
  283. "EGL",
  284. "GLESv2",
  285. }
  286. configuration { "android*", "Debug" }
  287. linkoptions {
  288. "-Wl,-soname,lib" .. project().name .. "Debug.so"
  289. }
  290. configuration { "android*", "Release" }
  291. linkoptions {
  292. "-Wl,-soname,lib" .. project().name .. "Release.so"
  293. }
  294. configuration { "wasm*" }
  295. kind "ConsoleApp"
  296. linkoptions {
  297. "-sGL_ENABLE_GET_PROC_ADDRESS",
  298. "-s TOTAL_MEMORY=32MB",
  299. "-s ALLOW_MEMORY_GROWTH=1",
  300. "--preload-file ../../../examples/runtime@/"
  301. }
  302. removeflags {
  303. "OptimizeSpeed",
  304. }
  305. flags {
  306. "Optimize"
  307. }
  308. configuration { "linux-* or freebsd" }
  309. links {
  310. "X11",
  311. "GL",
  312. "pthread",
  313. }
  314. configuration { "rpi" }
  315. links {
  316. "X11",
  317. "brcmGLESv2",
  318. "brcmEGL",
  319. "bcm_host",
  320. "vcos",
  321. "vchiq_arm",
  322. "pthread",
  323. }
  324. configuration { "osx*" }
  325. linkoptions {
  326. "-framework Cocoa",
  327. "-framework IOKit",
  328. "-framework OpenGL",
  329. "-framework QuartzCore",
  330. "-weak_framework Metal",
  331. }
  332. configuration { "ios* or tvos*" }
  333. kind "ConsoleApp"
  334. linkoptions {
  335. "-framework CoreFoundation",
  336. "-framework Foundation",
  337. "-framework IOKit",
  338. "-framework OpenGLES",
  339. "-framework QuartzCore",
  340. "-framework UIKit",
  341. "-weak_framework Metal",
  342. }
  343. configuration { "xcode*", "ios" }
  344. kind "WindowedApp"
  345. files {
  346. path.join(BGFX_DIR, "examples/runtime/iOS-Info.plist"),
  347. }
  348. configuration { "xcode*", "tvos" }
  349. kind "WindowedApp"
  350. files {
  351. path.join(BGFX_DIR, "examples/runtime/tvOS-Info.plist"),
  352. }
  353. configuration {}
  354. strip()
  355. end
  356. function exampleProject(_combined, ...)
  357. if _combined then
  358. project ("examples")
  359. uuid (os.uuid("examples"))
  360. kind "WindowedApp"
  361. for _, name in ipairs({...}) do
  362. files {
  363. path.join(BGFX_DIR, "examples", name, "**.c"),
  364. path.join(BGFX_DIR, "examples", name, "**.cpp"),
  365. path.join(BGFX_DIR, "examples", name, "**.h"),
  366. }
  367. removefiles {
  368. path.join(BGFX_DIR, "examples", name, "**.bin.h"),
  369. }
  370. end
  371. files {
  372. path.join(BGFX_DIR, "examples/25-c99/helloworld.c"), -- hack for _main_
  373. }
  374. exampleProjectDefaults()
  375. else
  376. for _, name in ipairs({...}) do
  377. project ("example-" .. name)
  378. uuid (os.uuid("example-" .. name))
  379. kind "WindowedApp"
  380. files {
  381. path.join(BGFX_DIR, "examples", name, "**.c"),
  382. path.join(BGFX_DIR, "examples", name, "**.cpp"),
  383. path.join(BGFX_DIR, "examples", name, "**.h"),
  384. }
  385. removefiles {
  386. path.join(BGFX_DIR, "examples", name, "**.bin.h"),
  387. }
  388. defines {
  389. "ENTRY_CONFIG_IMPLEMENT_MAIN=1",
  390. }
  391. exampleProjectDefaults()
  392. end
  393. end
  394. end
  395. group "libs"
  396. dofile(path.join(BX_DIR, "scripts/bx.lua"))
  397. dofile(path.join(BIMG_DIR, "scripts/bimg.lua"))
  398. dofile(path.join(BIMG_DIR, "scripts/bimg_decode.lua"))
  399. dofile "bgfx.lua"
  400. local function userdefines()
  401. local defines = {}
  402. local BGFX_CONFIG = os.getenv("BGFX_CONFIG")
  403. if BGFX_CONFIG then
  404. for def in BGFX_CONFIG:gmatch "[^%s:]+" do
  405. table.insert(defines, "BGFX_CONFIG_" .. def)
  406. end
  407. end
  408. return defines
  409. end
  410. BGFX_CONFIG = userdefines()
  411. bgfxProject("", "StaticLib", BGFX_CONFIG)
  412. if _OPTIONS["with-shared-lib"] then
  413. group "libs"
  414. bgfxProject("-shared-lib", "SharedLib", BGFX_CONFIG)
  415. end
  416. if _OPTIONS["with-tools"] then
  417. group "libs"
  418. dofile(path.join(BIMG_DIR, "scripts/bimg_encode.lua"))
  419. end
  420. if _OPTIONS["with-examples"]
  421. or _OPTIONS["with-combined-examples"]
  422. or _OPTIONS["with-tools"] then
  423. group "examples"
  424. dofile "example-common.lua"
  425. end
  426. if _OPTIONS["with-examples"]
  427. or _OPTIONS["with-combined-examples"] then
  428. group "examples"
  429. exampleProject(_OPTIONS["with-combined-examples"]
  430. , "00-helloworld"
  431. , "01-cubes"
  432. , "02-metaballs"
  433. , "03-raymarch"
  434. , "04-mesh"
  435. , "05-instancing"
  436. , "06-bump"
  437. , "07-callback"
  438. , "08-update"
  439. , "09-hdr"
  440. , "10-font"
  441. , "11-fontsdf"
  442. , "12-lod"
  443. , "13-stencil"
  444. , "14-shadowvolumes"
  445. , "15-shadowmaps-simple"
  446. , "16-shadowmaps"
  447. , "18-ibl"
  448. , "19-oit"
  449. , "20-nanovg"
  450. , "21-deferred"
  451. , "22-windows"
  452. , "23-vectordisplay"
  453. , "24-nbody"
  454. , "26-occlusion"
  455. , "27-terrain"
  456. , "28-wireframe"
  457. , "29-debugdraw"
  458. , "30-picking"
  459. , "31-rsm"
  460. , "32-particles"
  461. , "33-pom"
  462. , "34-mvs"
  463. , "35-dynamic"
  464. , "36-sky"
  465. , "37-gpudrivenrendering"
  466. , "38-bloom"
  467. , "39-assao"
  468. , "40-svt"
  469. , "41-tess"
  470. , "42-bunnylod"
  471. , "43-denoise"
  472. , "44-sss"
  473. , "45-bokeh"
  474. , "46-fsr"
  475. , "47-pixelformats"
  476. , "48-drawindirect"
  477. , "49-hextile"
  478. )
  479. -- 17-drawstress requires multithreading, does not compile for singlethreaded wasm
  480. if premake.gcc.namestyle == nil or not premake.gcc.namestyle == "Emscripten" then
  481. exampleProject(false, "17-drawstress")
  482. end
  483. -- C99 source doesn't compile under WinRT settings
  484. if not premake.vstudio.iswinrt() then
  485. exampleProject(false, "25-c99")
  486. end
  487. end
  488. if _OPTIONS["with-tools"] then
  489. group "tools"
  490. dofile "shaderc.lua"
  491. dofile "texturec.lua"
  492. dofile "texturev.lua"
  493. dofile "geometryc.lua"
  494. dofile "geometryv.lua"
  495. end