xmake.lua 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. package("joltphysics")
  2. set_homepage("https://github.com/jrouwe/JoltPhysics")
  3. set_description("A multi core friendly rigid body physics and collision detection library suitable for games and VR applications.")
  4. set_license("MIT")
  5. add_urls("https://github.com/jrouwe/JoltPhysics/archive/refs/tags/$(version).tar.gz",
  6. "https://github.com/jrouwe/JoltPhysics.git")
  7. add_versions("v5.0.0", "5231953d1b1d5b9cb617facf86341a11337e1cd04456949af6911b917a1646cb")
  8. add_versions("v4.0.2", "046baf71d05e47de7a530ce5d58a587a93ea7e9ea1ef8bf3ff80238fb95650ae")
  9. add_versions("v4.0.1", "e0bb4fa07047ca9c38bd71262427ad2972a7f45f8dff74587f73457f3b60df82")
  10. add_versions("v4.0.0", "f8449ec72ffaadf423eeb80e0814f3ba14227bcf7f06cb9f3cbcfb3499a57b33")
  11. add_versions("v3.0.1", "7ebb40bf2dddbcf0515984582aaa197ddd06e97581fd55b98cb64f91b243b8a6")
  12. add_versions("v3.0.0", "f8d756ae3471a32f2ee7e07475df2f7a34752f0fdd05e9a7ed2e7ce3dcdcd574")
  13. add_versions("v2.0.1", "96ae2e8691c4802e56bf2587da30f2cc86b8abe82a78bc2398065bd87dd718af")
  14. -- patch for visibility attributes (fixes compilation in shared mode on GCC <13)
  15. add_patches("v4.0.0", "https://github.com/jrouwe/JoltPhysics/commit/b084d8f9054d78cb50bc851cc4db505462c4c634.patch", "a8f5da0bc5d4a1011771016be2ad1cdb00d4c40dd0909ef6ae4a1d1c95e8e251")
  16. -- patch for missing standard include (fixes Fedora compilation)
  17. add_patches("v3.0.1", path.join(os.scriptdir(), "patches", "v3.0.1", "fix_fedora.patch"), "12be1294669852a9f15cb01a636fde72fb5f36b59cbcc1d4f931d76c454c3150")
  18. add_patches("v3.0.0", path.join(os.scriptdir(), "patches", "v3.0.1", "fix_fedora.patch"), "12be1294669852a9f15cb01a636fde72fb5f36b59cbcc1d4f931d76c454c3150")
  19. add_patches("v2.0.1", path.join(os.scriptdir(), "patches", "v3.0.1", "fix_fedora.patch"), "12be1294669852a9f15cb01a636fde72fb5f36b59cbcc1d4f931d76c454c3150")
  20. -- patches for Android/ARMv7 and VS2019 ARM64 support
  21. add_patches("v2.0.1", path.join(os.scriptdir(), "patches", "v2.0.1", "android_fixes.patch"), "43b3d38ea5a01c281ad7b580859acaf0b30eac9a7bdc271a54199fcc88b8d491")
  22. add_patches("v2.0.1", path.join(os.scriptdir(), "patches", "v2.0.1", "armv7.patch"), "cbc59db0a0c786d473a05e84ed6f980c5288e531af44923864648c4471ccbd88")
  23. add_patches("v2.0.1", path.join(os.scriptdir(), "patches", "v2.0.1", "msvc_arm.patch"), "f6d368787ae7259dfbece7e8f1c1ba6af4d39f0f7c09a0f15186882bd827ed15")
  24. add_configs("cross_platform_deterministic", { description = "Turns on behavior to attempt cross platform determinism", default = false, type = "boolean" })
  25. add_configs("debug_renderer", { description = "Adds support to draw lines and triangles, used to be able to debug draw the state of the world", default = true, type = "boolean" })
  26. add_configs("double_precision", { description = "Compiles the library so that all positions are stored in doubles instead of floats. This makes larger worlds possible", default = false, type = "boolean" })
  27. add_configs("object_layer_bits", {description = "Number of bits to use in ObjectLayer. Can be 16 or 32.", default = "16", type = "string", values = {"16", "32"}})
  28. add_configs("symbols", { description = "When turning this option on, the library will be compiled with debug symbols", default = false, type = "boolean" })
  29. if is_arch("x86", "x64", "x86_64") then
  30. add_configs("inst_avx", { description = "Enable AVX CPU instructions (x86/x64 only)", default = false, type = "boolean" })
  31. add_configs("inst_avx2", { description = "Enable AVX2 CPU instructions (x86/x64 only)", default = false, type = "boolean" })
  32. add_configs("inst_avx512", { description = "Enable AVX512F+AVX512VL CPU instructions (x86/x64 only)", default = false, type = "boolean" })
  33. add_configs("inst_f16c", { description = "Enable half float CPU instructions (x86/x64 only)", default = false, type = "boolean" })
  34. add_configs("inst_fmadd", { description = "Enable fused multiply add CPU instructions (x86/x64 only)", default = false, type = "boolean" })
  35. add_configs("inst_lzcnt", { description = "Enable the lzcnt CPU instruction (x86/x64 only)", default = false, type = "boolean" })
  36. add_configs("inst_sse4_1", { description = "Enable SSE4.1 CPU instructions (x86/x64 only)", default = false, type = "boolean" })
  37. add_configs("inst_sse4_2", { description = "Enable SSE4.2 CPU instructions (x86/x64 only)", default = false, type = "boolean" })
  38. add_configs("inst_tzcnt", { description = "Enable the tzcnt CPU instruction (x86/x64 only)", default = false, type = "boolean" })
  39. end
  40. if is_plat("linux", "macosx", "iphoneos", "bsd", "wasm") then
  41. add_syslinks("pthread")
  42. end
  43. if is_plat("mingw") and is_subhost("msys") then
  44. add_extsources("pacman::jolt-physics")
  45. end
  46. on_load(function (package)
  47. local version = package:version()
  48. if not version or version:ge("3.0.0") then
  49. package:add("deps", "cmake")
  50. package:add("defines", "JPH_OBJECT_LAYER_BITS=" .. package:config("object_layer_bits"))
  51. end
  52. if package:is_plat("windows") and not package:config("shared") then
  53. package:add("syslinks", "Advapi32")
  54. end
  55. package:add("defines", "JPH_PROFILE_ENABLED")
  56. if package:is_plat("windows") then
  57. package:add("defines", "JPH_FLOATING_POINT_EXCEPTIONS_ENABLED")
  58. end
  59. if package:config("cross_platform_deterministic") then
  60. package:add("defines", "JPH_CROSS_PLATFORM_DETERMINISTIC")
  61. end
  62. if package:config("debug_renderer") then
  63. package:add("defines", "JPH_DEBUG_RENDERER")
  64. end
  65. if package:config("double_precision") then
  66. package:add("defines", "JPH_DOUBLE_PRECISION")
  67. end
  68. if package:config("shared") then
  69. package:add("defines", "JPH_SHARED_LIBRARY")
  70. end
  71. end)
  72. on_install("windows", "mingw", "linux", "macosx", "iphoneos", "android", "wasm", function (package)
  73. -- Jolt CMakeLists had no install target/support for custom msvc runtime until 3.0.0
  74. local version = package:version()
  75. if not version or version:ge("3.0.0") then
  76. os.cd("Build")
  77. local configs = {
  78. "-DENABLE_ALL_WARNINGS=OFF",
  79. "-DINTERPROCEDURAL_OPTIMIZATION=OFF",
  80. "-DTARGET_UNIT_TESTS=OFF",
  81. "-DTARGET_HELLO_WORLD=OFF",
  82. "-DTARGET_PERFORMANCE_TEST=OFF",
  83. "-DTARGET_SAMPLES=OFF",
  84. "-DTARGET_VIEWER=OFF",
  85. "-DUSE_STATIC_MSVC_RUNTIME_LIBRARY=OFF",
  86. "-DOVERRIDE_CXX_FLAGS=OFF"
  87. }
  88. table.insert(configs, "-DCMAKE_BUILD_TYPE=" .. (package:debug() and "Debug" or "Release"))
  89. table.insert(configs, "-DBUILD_SHARED_LIBS=" .. (package:config("shared") and "ON" or "OFF"))
  90. table.insert(configs, "-DCROSS_PLATFORM_DETERMINISTIC=" .. (package:config("cross_platform_deterministic") and "ON" or "OFF"))
  91. table.insert(configs, "-DDOUBLE_PRECISION=" .. (package:config("double_precision") and "ON" or "OFF"))
  92. table.insert(configs, "-DGENERATE_DEBUG_SYMBOLS=" .. ((package:debug() or package:config("symbols")) and "ON" or "OFF"))
  93. table.insert(configs, "-DOBJECT_LAYER_BITS=" .. package:config("object_layer_bits"))
  94. table.insert(configs, "-DUSE_AVX=" .. (package:config("inst_avx") and "ON" or "OFF"))
  95. table.insert(configs, "-DUSE_AVX2=" .. (package:config("inst_avx2") and "ON" or "OFF"))
  96. table.insert(configs, "-DUSE_AVX512=" .. (package:config("inst_avx512") and "ON" or "OFF"))
  97. table.insert(configs, "-DUSE_F16C=" .. (package:config("inst_f16c") and "ON" or "OFF"))
  98. table.insert(configs, "-DUSE_FMADD=" .. (package:config("inst_fmadd") and "ON" or "OFF"))
  99. table.insert(configs, "-DUSE_LZCNT=" .. (package:config("inst_lzcnt") and "ON" or "OFF"))
  100. table.insert(configs, "-DUSE_SSE4_1=" .. (package:config("inst_sse4_1") and "ON" or "OFF"))
  101. table.insert(configs, "-DUSE_SSE4_2=" .. (package:config("inst_sse4_2") and "ON" or "OFF"))
  102. table.insert(configs, "-DUSE_TZCNT=" .. (package:config("inst_tzcnt") and "ON" or "OFF"))
  103. import("package.tools.cmake").install(package, configs)
  104. else
  105. os.cp(path.join(os.scriptdir(), "port", "xmake.lua"), "xmake.lua")
  106. local configs = {}
  107. configs.cross_platform_deterministic = package:config("cross_platform_deterministic")
  108. configs.debug_renderer = package:config("debug_renderer")
  109. configs.double_precision = package:config("double_precision")
  110. if package:is_arch("x86", "x64", "x86_64") then
  111. configs.inst_avx = package:config("inst_avx")
  112. configs.inst_avx2 = package:config("inst_avx2")
  113. configs.inst_avx512 = package:config("inst_avx512")
  114. configs.inst_f16c = package:config("inst_f16c")
  115. configs.inst_fmadd = package:config("inst_fmadd")
  116. configs.inst_lzcnt = package:config("inst_lzcnt")
  117. configs.inst_sse4_1 = package:config("inst_sse4_1")
  118. configs.inst_sse4_2 = package:config("inst_sse4_2")
  119. configs.inst_tzcnt = package:config("inst_tzcnt")
  120. end
  121. import("package.tools.xmake").install(package, configs)
  122. end
  123. end)
  124. on_test(function (package)
  125. assert(package:check_cxxsnippets({test = [[
  126. void test() {
  127. JPH::RegisterDefaultAllocator();
  128. JPH::PhysicsSystem physics_system;
  129. physics_system.OptimizeBroadPhase();
  130. }
  131. ]]}, {configs = {languages = "c++17"}, includes = {"Jolt/Jolt.h", "Jolt/Physics/PhysicsSystem.h"}}))
  132. end)