xmake.lua 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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_resources("7816", "bx", "https://github.com/bkaradzic/bx.git", "51f25ba638b9cb35eb2ac078f842a4bed0746d56")
  10. add_resources("8203", "bx", "https://github.com/bkaradzic/bx.git", "b9501348c596b68e5e655a8308df5c55f61ecd80")
  11. add_resources("8674", "bx", "https://github.com/bkaradzic/bx.git", "67dfdf34f642a4a807b75eb600f82f4f04027963")
  12. add_resources("7816", "bimg", "https://github.com/bkaradzic/bimg.git", "8355d36befc90c1db82fca8e54f38bfb7eeb3530")
  13. add_resources("8203", "bimg", "https://github.com/bkaradzic/bimg.git", "663f724186e26caf46494e389ed82409106205fb")
  14. add_resources("8674", "bimg", "https://github.com/bkaradzic/bimg.git", "964a5b85483cdf59a30dc006e9bd8bbdde6cb2be")
  15. if is_plat("windows") then
  16. add_syslinks("user32", "gdi32", "psapi")
  17. add_includedirs("include", "include/compat/msvc")
  18. add_cxxflags("/Zc:__cplusplus")
  19. elseif is_plat("macosx") then
  20. add_frameworks("Metal", "QuartzCore", "Cocoa", "IOKit")
  21. elseif is_plat("linux") then
  22. add_deps("libx11")
  23. add_syslinks("GL", "pthread", "dl")
  24. end
  25. add_deps("genie")
  26. on_load("windows", "macosx", "linux", function (package)
  27. local suffix = package:debug() and "Debug" or "Release"
  28. for _, lib in ipairs({"bgfx", "bimg", "bx"}) do
  29. package:add("links", lib .. suffix)
  30. end
  31. package:add("defines", "BX_CONFIG_DEBUG=" .. (package:debug() and "1" or "0"))
  32. end)
  33. on_install("windows|native", "macosx", "linux", function (package)
  34. local bxdir = package:resourcefile("bx")
  35. local bimgdir = package:resourcefile("bimg")
  36. local genie = is_host("windows") and "genie.exe" or "genie"
  37. local args = {"--with-tools"}
  38. if package:config("shared") then
  39. table.insert(args, "--with-shared-lib")
  40. end
  41. os.trycp(path.join("include", "bgfx"), package:installdir("include"))
  42. os.trycp(path.join(bxdir, "include", "*"), package:installdir("include"))
  43. os.trycp(path.join(bimgdir, "include", "*"), package:installdir("include"))
  44. local mode = package:debug() and "Debug" or "Release"
  45. if package:is_plat("windows") then
  46. import("package.tools.msbuild")
  47. import("core.tool.toolchain")
  48. local msvc = toolchain.load("msvc")
  49. table.insert(args, "vs" .. msvc:config("vs"))
  50. local envs = msbuild.buildenvs(package)
  51. envs.BX_DIR = bxdir
  52. envs.BIMG_DIR = bimgdir
  53. os.vrunv(genie, args, {envs = envs})
  54. local configs = {}
  55. table.insert(configs, "/p:Configuration=" .. mode)
  56. table.insert(configs, "/p:Platform=" .. (package:is_arch("x64") and "x64" or "Win32"))
  57. table.insert(configs, "bgfx.sln")
  58. os.cd(format(".build/projects/vs%s", msvc:config("vs")))
  59. msbuild.build(package, configs)
  60. os.trycp("../../win*_vs*/bin/*.lib|*example*", package:installdir("lib"))
  61. os.trycp("../../win*_vs*/bin/*.dll", package:installdir("lib"))
  62. os.trycp("../../win*_vs*/bin/*.lib", package:installdir("lib"))
  63. os.trycp("../../win*_vs*/bin/*.exe", package:installdir("bin"))
  64. else
  65. import("package.tools.make")
  66. local configs
  67. local target
  68. if package:is_plat("macosx") then
  69. target = (package:is_arch("x86_64") and "osx-x64" or "osx-arm64")
  70. table.insert(args, "--gcc=" .. target)
  71. configs = {"-C",
  72. ".build/projects/gmake-" .. target,
  73. "config=" .. mode:lower()}
  74. elseif package:is_plat("linux") then
  75. table.insert(args, "--gcc=linux-gcc")
  76. target = "linux" .. (package:is_arch("x86_64") and "64" or "32") .. "_gcc"
  77. configs = {"-C",
  78. ".build/projects/gmake-linux",
  79. "config=" .. mode:lower() .. (package:is_arch("x86_64") and "64" or "32")}
  80. end
  81. table.insert(args, "gmake")
  82. local envs = make.buildenvs(package)
  83. envs.BX_DIR = bxdir
  84. envs.BIMG_DIR = bimgdir
  85. os.vrunv(genie, args, {envs = envs})
  86. make.build(package, configs)
  87. if package:is_plat("macosx") then
  88. os.trycp(".build/" .. target .. "/bin/*.a|*example*", package:installdir("lib"))
  89. os.trycp(".build/" .. target .. "/bin/*.dylib", package:installdir("lib"))
  90. os.trycp(".build/" .. target .. "/bin/*|*.*", package:installdir("bin"))
  91. elseif package:is_plat("linux") then
  92. os.trycp(".build/" .. target .. "/bin/*.a|*example*", package:installdir("lib"))
  93. os.trycp(".build/" .. target .. "/bin/*.so", package:installdir("lib"))
  94. os.trycp(".build/" .. target .. "/bin/*|*.*", package:installdir("bin"))
  95. end
  96. end
  97. package:addenv("PATH", "bin")
  98. end)
  99. on_test(function (package)
  100. assert(package:check_cxxsnippets({test = [[
  101. void test() {
  102. bgfx::init();
  103. }
  104. ]]}, {configs = {languages = "c++14"}, includes = "bgfx/bgfx.h"}))
  105. end)