xmake.lua 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. package("box2d")
  2. set_homepage("https://box2d.org")
  3. set_description("A 2D Physics Engine for Games")
  4. set_license("MIT")
  5. set_urls("https://github.com/erincatto/box2d/archive/v$(version).zip")
  6. add_versions("2.4.0", "6aebbc54c93e367c97e382a57ba12546731dcde51526964c2ab97dec2050f8b9")
  7. add_versions("2.4.1", "0cb512dfa5be79ca227cd881b279adee61249c85c8b51caf5aa036b71e943002")
  8. add_versions("2.4.2", "593f165015fdd07ea521a851105f1c86ae313c5af0a15968ed95f864417fa8a7")
  9. if is_arch("x64", "x86_64", "arm64.*") then
  10. add_versions("3.0.0", "c2983a30a95037c46c19e42f398de6bc375d6ae87f30e0d0bbabb059ec60f8c0")
  11. end
  12. if is_arch("x64", "x86_64") then
  13. add_configs("avx2", {description = "Enable AVX2.", default = false, type = "boolean"})
  14. end
  15. add_deps("cmake")
  16. if on_check then
  17. on_check("windows", function (package)
  18. if package:version():ge("3.0.0") then
  19. assert(not package:is_arch("arm64.*"), "package(box2d =>3.0.0) Unsupported architecture.")
  20. local configs = {languages = "c11"}
  21. if package:has_tool("cc", "cl") then
  22. configs.cflags = "/experimental:c11atomics"
  23. end
  24. assert(package:has_cincludes("stdatomic.h", {configs = configs}),
  25. "package(box2d >=3.0.0) Requires at least C11 and stdatomic.h")
  26. end
  27. end)
  28. end
  29. on_install("windows", "linux", "macosx", "mingw", function (package)
  30. local configs = {}
  31. if package:version():ge("3.0.0") then
  32. table.insert(configs, "--compile-no-warning-as-error")
  33. table.insert(configs, "-DBOX2D_SANITIZE=OFF")
  34. table.insert(configs, "-DBOX2D_SAMPLES=OFF")
  35. table.insert(configs, "-DBOX2D_BENCHMARKS=OFF")
  36. table.insert(configs, "-DBOX2D_DOCS=OFF")
  37. table.insert(configs, "-DBOX2D_PROFILE=OFF")
  38. table.insert(configs, "-DBOX2D_VALIDATE=OFF")
  39. table.insert(configs, "-DBOX2D_UNIT_TESTS=OFF")
  40. table.insert(configs, "-DBOX2D_AVX2=" .. (package:config("avx2") and "ON" or "OFF"))
  41. else
  42. table.insert(configs, "-DBOX2D_BUILD_UNIT_TESTS=OFF")
  43. table.insert(configs, "-DBOX2D_BUILD_TESTBED=OFF")
  44. table.insert(configs, "-DBOX2D_BUILD_DOCS=OFF")
  45. end
  46. table.insert(configs, "-DCMAKE_BUILD_TYPE=" .. (package:debug() and "Debug" or "Release"))
  47. import("package.tools.cmake").build(package, configs, {buildir = "build"})
  48. if package:is_plat("windows") then
  49. os.trycp(path.join("build", "src", "*", "*.lib"), package:installdir("lib"))
  50. os.trycp(path.join("build", "bin", "*", "*.lib"), package:installdir("lib"))
  51. else
  52. os.trycp("build/src/*.a", package:installdir("lib"))
  53. os.trycp("build/bin/*.a", package:installdir("lib"))
  54. end
  55. os.cp("include", package:installdir())
  56. end)
  57. on_test(function (package)
  58. if package:version():ge("3.0.0") then
  59. assert(package:check_csnippets({test = [[
  60. void test(int argc, char** argv) {
  61. b2WorldDef worldDef = b2DefaultWorldDef();
  62. b2WorldId worldId = b2CreateWorld(&worldDef);
  63. b2BodyDef bodyDef = b2DefaultBodyDef();
  64. b2BodyId bodyId = b2CreateBody(worldId, &bodyDef);
  65. b2Polygon box = b2MakeBox(1.0f, 1.0f);
  66. b2ShapeDef shapeDef = b2DefaultShapeDef();
  67. b2CreatePolygonShape(bodyId, &shapeDef, &box);
  68. float timeStep = 1.0f / 60.0f;
  69. int subStepCount = 4;
  70. b2World_Step(worldId, timeStep, subStepCount);
  71. b2Vec2 position = b2Body_GetPosition(bodyId);
  72. b2Rot rotation = b2Body_GetRotation(bodyId);
  73. b2DestroyWorld(worldId);
  74. }
  75. ]]}, {configs = {languages = "c11"}, includes = "box2d/box2d.h"}))
  76. else
  77. assert(package:check_cxxsnippets({test = [[
  78. void test(int argc, char** argv) {
  79. b2World world(b2Vec2(0.0f, -10.0f));
  80. b2BodyDef bodyDef;
  81. b2Body* body = world.CreateBody(&bodyDef);
  82. b2PolygonShape box;
  83. box.SetAsBox(1.0f, 1.0f);
  84. b2FixtureDef fixtureDef;
  85. fixtureDef.shape = &box;
  86. body->CreateFixture(&fixtureDef);
  87. float timeStep = 1.0f / 60.0f;
  88. int32 velocityIterations = 6;
  89. int32 positionIterations = 2;
  90. world.Step(timeStep, velocityIterations, positionIterations);
  91. b2Vec2 position = body->GetPosition();
  92. float angle = body->GetAngle();
  93. }
  94. ]]}, {configs = {languages = "c++11"}, includes = "box2d/box2d.h"}))
  95. end
  96. end)