xmake.lua 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. package("chipmunk2d")
  2. set_homepage("https://chipmunk-physics.net/")
  3. set_description("A fast and lightweight 2D game physics library.")
  4. set_license("MIT")
  5. add_urls("https://github.com/slembcke/Chipmunk2D/archive/Chipmunk-$(version).tar.gz", {alias = "archive"})
  6. add_urls("https://github.com/slembcke/Chipmunk2D.git", {alias = "github"})
  7. add_versions("archive:7.0.3", "1e6f093812d6130e45bdf4cb80280cb3c93d1e1833d8cf989d554d7963b7899a")
  8. add_versions("github:7.0.3", "87340c216bf97554dc552371bbdecf283f7c540e")
  9. add_patches("7.0.3", path.join(os.scriptdir(), "patches", "7.0.3", "android.patch"), "d0bbefe66852cdadb974dce24d4383c356bc3fa88656739ff1d5baf4e3792a96")
  10. add_configs("precision", {description = "Which precision to use (defaults is double on most platforms except ARM 32bits)", default = "default", type = "string", values = {"default", "single", "double"}})
  11. if is_plat("mingw") and is_subhost("msys") then
  12. add_extsources("pacman::chipmunk")
  13. elseif is_plat("linux") then
  14. add_extsources("pacman::chipmunk", "apt::libchipmunk-dev")
  15. elseif is_plat("macosx") then
  16. add_extsources("brew::chipmunk")
  17. end
  18. add_deps("cmake")
  19. if is_plat("linux", "bsd") then
  20. add_syslinks("pthread", "m")
  21. elseif is_plat("android") then
  22. add_syslinks("log", "m")
  23. end
  24. on_load(function (package)
  25. if package:config("precision") == "double" then
  26. package:add("defines", "CP_USE_DOUBLES=1")
  27. if package:is_plat("macosx", "iphoneos") then
  28. package:add("defines", "CP_USE_CGTYPES=1")
  29. end
  30. elseif package:config("precision") == "single" then
  31. package:add("defines", "CP_USE_DOUBLES=0")
  32. if package:is_plat("macosx", "iphoneos") then
  33. package:add("defines", "CP_USE_CGTYPES=0")
  34. end
  35. end
  36. end)
  37. on_install("windows", "linux", "macosx", "iphoneos", "mingw", "android", "wasm", "bsd",function (package)
  38. local configs = {"-DBUILD_DEMOS=OFF"}
  39. table.insert(configs, "-DCMAKE_BUILD_TYPE=" .. (package:debug() and "Debug" or "Release"))
  40. if package:config("shared") then
  41. table.insert(configs, "-DBUILD_SHARED=ON")
  42. table.insert(configs, "-DBUILD_STATIC=OFF")
  43. table.insert(configs, "-DINSTALL_STATIC=OFF")
  44. else
  45. table.insert(configs, "-DBUILD_SHARED=OFF")
  46. table.insert(configs, "-DBUILD_STATIC=ON")
  47. table.insert(configs, "-DINSTALL_STATIC=ON")
  48. end
  49. local opt = {}
  50. if package:config("precision") == "double" then
  51. opt.cxflags = {"-DCP_USE_DOUBLES=1"}
  52. if package:is_plat("macosx", "iphoneos") then
  53. table.insert(opt.cxflags, "-DCP_USE_CGTYPES=1")
  54. end
  55. elseif package:config("precision") == "single" then
  56. opt.cxflags = {"-DCP_USE_DOUBLES=0"}
  57. if package:is_plat("macosx", "iphoneos") then
  58. table.insert(opt.cxflags, "-DCP_USE_CGTYPES=0")
  59. end
  60. end
  61. import("package.tools.cmake").install(package, configs, opt)
  62. os.vcp("include/chipmunk", package:installdir("include"))
  63. end)
  64. on_test(function (package)
  65. assert(package:check_cxxsnippets({test = [[
  66. void test() {
  67. cpSpace* space = cpSpaceNew();
  68. cpSpaceFree(space);
  69. }
  70. ]]}, {includes = {"chipmunk/chipmunk.h"}}))
  71. end)