Browse Source

Add chipmunk2d (#120)

* Add chipmunk2d

* chipmunk2D: Fix CMake options

* Fix chipmunk includes

* Fix linux and android builds

* I fixed the wrong version 🤦‍♂️

* Fix patch checksum

* Chipmunk2D: Use ANDROID define instead of __ANDROID__ for consistency

* Fix android build

* Fix static build

* Fix android, once again
Jérôme Leclercq 4 years ago
parent
commit
c42b02aee0
2 changed files with 75 additions and 0 deletions
  1. 35 0
      packages/c/chipmunk2d/patches/7.0.3/android.patch
  2. 40 0
      packages/c/chipmunk2d/xmake.lua

+ 35 - 0
packages/c/chipmunk2d/patches/7.0.3/android.patch

@@ -0,0 +1,35 @@
+diff --git a/include/chipmunk/chipmunk_types.h b/include/chipmunk/chipmunk_types.h
+index 9544da8..444f5c6 100644
+--- a/include/chipmunk/chipmunk_types.h
++++ b/include/chipmunk/chipmunk_types.h
+@@ -53,8 +53,12 @@
+ #endif
+ 
+ #ifndef CP_USE_DOUBLES
+-	// Use doubles by default for higher precision.
+-	#define CP_USE_DOUBLES 1
++	// Use doubles by default for higher precision when possible.
++	#if (!defined(__ARM_NEON__) || !__ARM_NEON__ || __arm64)
++		#define CP_USE_DOUBLES 1
++	#else
++		#define CP_USE_DOUBLES 0
++	#endif
+ #endif
+ 
+ /// @defgroup basicTypes Basic Types
+diff --git a/src/cpHastySpace.c b/src/cpHastySpace.c
+index 8dca425..3e3792c 100644
+--- a/src/cpHastySpace.c
++++ b/src/cpHastySpace.c
+@@ -8,7 +8,11 @@
+ 
+ //#include <sys/param.h >
+ #ifndef _WIN32
++#if defined(ANDROID)
++#include <linux/sysctl.h>
++#else
+ #include <sys/sysctl.h>
++#endif
+ #include <pthread.h>
+ #else
+ #ifndef WIN32_LEAN_AND_MEAN

+ 40 - 0
packages/c/chipmunk2d/xmake.lua

@@ -0,0 +1,40 @@
+package("chipmunk2d")
+
+    set_homepage("https://chipmunk-physics.net/")
+    set_description(" A fast and lightweight 2D game physics library.")
+
+    set_urls("https://github.com/slembcke/Chipmunk2D/archive/Chipmunk-$(version).tar.gz",
+             "https://github.com/slembcke/Chipmunk2D.git")
+
+    add_versions("7.0.3", "1e6f093812d6130e45bdf4cb80280cb3c93d1e1833d8cf989d554d7963b7899a")
+    add_patches("7.0.3", path.join(os.scriptdir(), "patches", "7.0.3", "android.patch"), "8efbd57350d0ae5febbbc03223417114d99018a31330c88d5f57e3ccbf9334fa")
+
+    add_deps("cmake")
+
+    if is_plat("linux") then
+        add_syslinks("pthread", "m")
+    end
+
+    on_install("windows", "linux", "macosx", "iphoneos", "mingw", "android", function (package)
+        local configs = {"-DBUILD_DEMOS=OFF"}
+        table.insert(configs, "-DCMAKE_BUILD_TYPE=" .. (package:debug() and "Debug" or "Release"))
+        if package:config("shared") then
+            table.insert(configs, "-DBUILD_SHARED=ON")
+            table.insert(configs, "-DBUILD_STATIC=OFF")
+            table.insert(configs, "-DINSTALL_STATIC=OFF")
+        else
+            table.insert(configs, "-DBUILD_SHARED=OFF")
+            table.insert(configs, "-DBUILD_STATIC=ON")
+        end
+        import("package.tools.cmake").install(package, configs)
+        os.vcp("include/chipmunk", package:installdir("include"))
+   end)
+
+    on_test(function (package)
+        assert(package:check_cxxsnippets({test = [[
+            void test() {
+                cpSpace* space = cpSpaceNew();
+                cpSpaceFree(space);
+            }
+        ]]}, {includes = {"chipmunk/chipmunk.h"}}))
+    end)