xmake.lua 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. package("bgfx")
  2. set_homepage("https://bkaradzic.github.io/bgfx/")
  3. set_description("Cross-platform, graphics API agnostic, “Bring Your Own Engine/Framework” style rendering library")
  4. set_license("BSD-2-Clause")
  5. add_urls("https://github.com/bkaradzic/bgfx.git")
  6. add_versions("7816", "5ecddbf4d51e2dda2a56ae8cafef4810e3a45d87")
  7. add_versions("8203", "484a5f0c25b53584a6b7fce0702a6bb580072d81")
  8. add_versions("8674", "f42134876038027667ef7e47c9a612dca1051ef2")
  9. add_versions("8752", "61c770b0f5f57cf10547107974099e604358bf69")
  10. add_resources("7816", "bx", "https://github.com/bkaradzic/bx.git", "51f25ba638b9cb35eb2ac078f842a4bed0746d56")
  11. add_resources("8203", "bx", "https://github.com/bkaradzic/bx.git", "b9501348c596b68e5e655a8308df5c55f61ecd80")
  12. add_resources("8674", "bx", "https://github.com/bkaradzic/bx.git", "67dfdf34f642a4a807b75eb600f82f4f04027963")
  13. add_resources("8752", "bx", "https://github.com/bkaradzic/bx.git", "0ec634e8fdf8c810f9911c686a8158088ae25379")
  14. add_resources("7816", "bimg", "https://github.com/bkaradzic/bimg.git", "8355d36befc90c1db82fca8e54f38bfb7eeb3530")
  15. add_resources("8203", "bimg", "https://github.com/bkaradzic/bimg.git", "663f724186e26caf46494e389ed82409106205fb")
  16. add_resources("8674", "bimg", "https://github.com/bkaradzic/bimg.git", "964a5b85483cdf59a30dc006e9bd8bbdde6cb2be")
  17. add_resources("8752", "bimg", "https://github.com/bkaradzic/bimg.git", "61a7e9ebe7e33c821cf80b0542dcf23088446f5b")
  18. if is_plat("windows") then
  19. add_syslinks("user32", "gdi32", "psapi")
  20. add_includedirs("include", "include/compat/msvc")
  21. add_cxxflags("/Zc:__cplusplus")
  22. elseif is_plat("macosx") then
  23. add_frameworks("Metal", "QuartzCore", "Cocoa", "IOKit")
  24. elseif is_plat("iphoneos") then
  25. add_frameworks("OpenGLES", "CoreGraphics", "Metal", "QuartzCore", "UIKit")
  26. elseif is_plat("linux") then
  27. add_deps("libx11")
  28. add_syslinks("GL", "pthread", "dl")
  29. end
  30. add_deps("genie")
  31. on_load("windows", "macosx", "linux", "iphoneos", function (package)
  32. local suffix = package:debug() and "Debug" or "Release"
  33. for _, lib in ipairs({"bgfx", "bimg", "bx"}) do
  34. package:add("links", lib .. suffix)
  35. end
  36. package:add("defines", "BX_CONFIG_DEBUG=" .. (package:debug() and "1" or "0"))
  37. end)
  38. on_install("windows|native", "macosx", "linux", "iphoneos", function (package)
  39. local bxdir = package:resourcefile("bx")
  40. local bimgdir = package:resourcefile("bimg")
  41. local genie = is_host("windows") and "genie.exe" or "genie"
  42. local args = {}
  43. if package:is_plat("windows", "macosx", "linux") then
  44. args = {"--with-tools"}
  45. end
  46. if package:config("shared") then
  47. table.insert(args, "--with-shared-lib")
  48. end
  49. os.trycp(path.join("include", "bgfx"), package:installdir("include"))
  50. os.trycp(path.join(bxdir, "include", "*"), package:installdir("include"))
  51. os.trycp(path.join(bimgdir, "include", "*"), package:installdir("include"))
  52. local mode = package:debug() and "Debug" or "Release"
  53. if package:is_plat("windows") then
  54. import("package.tools.msbuild")
  55. import("core.tool.toolchain")
  56. local msvc = toolchain.load("msvc")
  57. table.insert(args, "vs" .. msvc:config("vs"))
  58. local envs = msbuild.buildenvs(package)
  59. envs.BX_DIR = bxdir
  60. envs.BIMG_DIR = bimgdir
  61. os.vrunv(genie, args, {envs = envs})
  62. local configs = {}
  63. table.insert(configs, "/p:Configuration=" .. mode)
  64. table.insert(configs, "/p:Platform=" .. (package:is_arch("x64") and "x64" or "Win32"))
  65. table.insert(configs, "bgfx.sln")
  66. os.cd(format(".build/projects/vs%s", msvc:config("vs")))
  67. msbuild.build(package, configs)
  68. os.trycp("../../win*_vs*/bin/*.lib|*example*", package:installdir("lib"))
  69. os.trycp("../../win*_vs*/bin/*.dll", package:installdir("lib"))
  70. os.trycp("../../win*_vs*/bin/*.lib", package:installdir("lib"))
  71. os.trycp("../../win*_vs*/bin/*.exe", package:installdir("bin"))
  72. else
  73. import("package.tools.make")
  74. local configs
  75. local target
  76. if package:is_plat("macosx") then
  77. target = (package:is_arch("x86_64") and "osx-x64" or "osx-arm64")
  78. table.insert(args, "--gcc=" .. target)
  79. configs = {"-C",
  80. ".build/projects/gmake-" .. target,
  81. "config=" .. mode:lower()}
  82. elseif package:is_plat("iphoneos") then
  83. target = "ios-arm64"
  84. table.insert(args, "--gcc=" .. target)
  85. configs = {"-C",
  86. ".build/projects/gmake-" .. target,
  87. "config=" .. mode:lower()}
  88. elseif package:is_plat("linux") then
  89. table.insert(args, "--gcc=linux-gcc")
  90. target = "linux" .. (package:is_arch("x86_64") and "64" or "32") .. "_gcc"
  91. configs = {"-C",
  92. ".build/projects/gmake-linux",
  93. "config=" .. mode:lower() .. (package:is_arch("x86_64") and "64" or "32")}
  94. end
  95. table.insert(args, "gmake")
  96. table.insert(args, "-j" .. os.cpuinfo("ncpu"))
  97. local envs = make.buildenvs(package)
  98. envs.BX_DIR = bxdir
  99. envs.BIMG_DIR = bimgdir
  100. os.vrunv(genie, args, {envs = envs})
  101. make.build(package, configs)
  102. if package:is_plat("macosx", "iphoneos") then
  103. os.trycp(".build/" .. target .. "/bin/*.a|*example*", package:installdir("lib"))
  104. os.trycp(".build/" .. target .. "/bin/*.dylib", package:installdir("lib"))
  105. os.trycp(".build/" .. target .. "/bin/*|*.*", package:installdir("bin"))
  106. elseif package:is_plat("linux") then
  107. os.trycp(".build/" .. target .. "/bin/*.a|*example*", package:installdir("lib"))
  108. os.trycp(".build/" .. target .. "/bin/*.so", package:installdir("lib"))
  109. os.trycp(".build/" .. target .. "/bin/*|*.*", package:installdir("bin"))
  110. end
  111. end
  112. package:addenv("PATH", "bin")
  113. end)
  114. on_test(function (package)
  115. assert(package:check_cxxsnippets({test = [[
  116. void test() {
  117. bgfx::init();
  118. }
  119. ]]}, {configs = {languages = "c++17"}, includes = "bgfx/bgfx.h"}))
  120. end)