genie.lua 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601
  1. --
  2. -- Copyright 2010-2023 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-2023 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. "-s TOTAL_MEMORY=32MB",
  298. "-s ALLOW_MEMORY_GROWTH=1",
  299. "--preload-file ../../../examples/runtime@/"
  300. }
  301. removeflags {
  302. "OptimizeSpeed",
  303. }
  304. flags {
  305. "Optimize"
  306. }
  307. configuration { "linux-* or freebsd" }
  308. links {
  309. "X11",
  310. "GL",
  311. "pthread",
  312. }
  313. configuration { "rpi" }
  314. links {
  315. "X11",
  316. "brcmGLESv2",
  317. "brcmEGL",
  318. "bcm_host",
  319. "vcos",
  320. "vchiq_arm",
  321. "pthread",
  322. }
  323. configuration { "osx*" }
  324. linkoptions {
  325. "-framework Cocoa",
  326. "-framework IOKit",
  327. "-framework OpenGL",
  328. "-framework QuartzCore",
  329. "-weak_framework Metal",
  330. }
  331. configuration { "ios* or tvos*" }
  332. kind "ConsoleApp"
  333. linkoptions {
  334. "-framework CoreFoundation",
  335. "-framework Foundation",
  336. "-framework IOKit",
  337. "-framework OpenGLES",
  338. "-framework QuartzCore",
  339. "-framework UIKit",
  340. "-weak_framework Metal",
  341. }
  342. configuration { "xcode*", "ios" }
  343. kind "WindowedApp"
  344. files {
  345. path.join(BGFX_DIR, "examples/runtime/iOS-Info.plist"),
  346. }
  347. configuration { "xcode*", "tvos" }
  348. kind "WindowedApp"
  349. files {
  350. path.join(BGFX_DIR, "examples/runtime/tvOS-Info.plist"),
  351. }
  352. configuration {}
  353. strip()
  354. end
  355. function exampleProject(_combined, ...)
  356. if _combined then
  357. project ("examples")
  358. uuid (os.uuid("examples"))
  359. kind "WindowedApp"
  360. for _, name in ipairs({...}) do
  361. files {
  362. path.join(BGFX_DIR, "examples", name, "**.c"),
  363. path.join(BGFX_DIR, "examples", name, "**.cpp"),
  364. path.join(BGFX_DIR, "examples", name, "**.h"),
  365. }
  366. removefiles {
  367. path.join(BGFX_DIR, "examples", name, "**.bin.h"),
  368. }
  369. end
  370. files {
  371. path.join(BGFX_DIR, "examples/25-c99/helloworld.c"), -- hack for _main_
  372. }
  373. exampleProjectDefaults()
  374. else
  375. for _, name in ipairs({...}) do
  376. project ("example-" .. name)
  377. uuid (os.uuid("example-" .. name))
  378. kind "WindowedApp"
  379. files {
  380. path.join(BGFX_DIR, "examples", name, "**.c"),
  381. path.join(BGFX_DIR, "examples", name, "**.cpp"),
  382. path.join(BGFX_DIR, "examples", name, "**.h"),
  383. }
  384. removefiles {
  385. path.join(BGFX_DIR, "examples", name, "**.bin.h"),
  386. }
  387. defines {
  388. "ENTRY_CONFIG_IMPLEMENT_MAIN=1",
  389. }
  390. exampleProjectDefaults()
  391. end
  392. end
  393. end
  394. group "libs"
  395. dofile(path.join(BX_DIR, "scripts/bx.lua"))
  396. dofile(path.join(BIMG_DIR, "scripts/bimg.lua"))
  397. dofile(path.join(BIMG_DIR, "scripts/bimg_decode.lua"))
  398. dofile "bgfx.lua"
  399. local function userdefines()
  400. local defines = {}
  401. local BGFX_CONFIG = os.getenv("BGFX_CONFIG")
  402. if BGFX_CONFIG then
  403. for def in BGFX_CONFIG:gmatch "[^%s:]+" do
  404. table.insert(defines, "BGFX_CONFIG_" .. def)
  405. end
  406. end
  407. return defines
  408. end
  409. BGFX_CONFIG = userdefines()
  410. bgfxProject("", "StaticLib", BGFX_CONFIG)
  411. if _OPTIONS["with-shared-lib"] then
  412. group "libs"
  413. bgfxProject("-shared-lib", "SharedLib", BGFX_CONFIG)
  414. end
  415. if _OPTIONS["with-tools"] then
  416. group "libs"
  417. dofile(path.join(BIMG_DIR, "scripts/bimg_encode.lua"))
  418. end
  419. if _OPTIONS["with-examples"]
  420. or _OPTIONS["with-combined-examples"]
  421. or _OPTIONS["with-tools"] then
  422. group "examples"
  423. dofile "example-common.lua"
  424. end
  425. if _OPTIONS["with-examples"]
  426. or _OPTIONS["with-combined-examples"] then
  427. group "examples"
  428. exampleProject(_OPTIONS["with-combined-examples"]
  429. , "00-helloworld"
  430. , "01-cubes"
  431. , "02-metaballs"
  432. , "03-raymarch"
  433. , "04-mesh"
  434. , "05-instancing"
  435. , "06-bump"
  436. , "07-callback"
  437. , "08-update"
  438. , "09-hdr"
  439. , "10-font"
  440. , "11-fontsdf"
  441. , "12-lod"
  442. , "13-stencil"
  443. , "14-shadowvolumes"
  444. , "15-shadowmaps-simple"
  445. , "16-shadowmaps"
  446. , "18-ibl"
  447. , "19-oit"
  448. , "20-nanovg"
  449. , "21-deferred"
  450. , "22-windows"
  451. , "23-vectordisplay"
  452. , "24-nbody"
  453. , "26-occlusion"
  454. , "27-terrain"
  455. , "28-wireframe"
  456. , "29-debugdraw"
  457. , "30-picking"
  458. , "31-rsm"
  459. , "32-particles"
  460. , "33-pom"
  461. , "34-mvs"
  462. , "35-dynamic"
  463. , "36-sky"
  464. , "37-gpudrivenrendering"
  465. , "38-bloom"
  466. , "39-assao"
  467. , "40-svt"
  468. , "41-tess"
  469. , "42-bunnylod"
  470. , "43-denoise"
  471. , "44-sss"
  472. , "45-bokeh"
  473. , "46-fsr"
  474. , "47-pixelformats"
  475. , "48-drawindirect"
  476. , "49-hextile"
  477. )
  478. -- 17-drawstress requires multithreading, does not compile for singlethreaded wasm
  479. if premake.gcc.namestyle == nil or not premake.gcc.namestyle == "Emscripten" then
  480. exampleProject(false, "17-drawstress")
  481. end
  482. -- C99 source doesn't compile under WinRT settings
  483. if not premake.vstudio.iswinrt() then
  484. exampleProject(false, "25-c99")
  485. end
  486. end
  487. if _OPTIONS["with-tools"] then
  488. group "tools"
  489. dofile "shaderc.lua"
  490. dofile "texturec.lua"
  491. dofile "texturev.lua"
  492. dofile "geometryc.lua"
  493. dofile "geometryv.lua"
  494. end