genie.lua 12 KB

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