Repository: conan-io/conan-center-index

Issue:
[request] box2d/2.4.0
### Package Details
  * Package Name/Version: **box2d/2.4.0**
  * Changelog: **https://github.com/erincatto/box2d/releases/tag/v2.4.0**

The above mentioned version is newly released by the upstream project and not yet available as a recipe. Please add this version.



Discussion:

Resolving patch:
diff --git a/recipes/box2d/2.4.x/conanfile.py b/recipes/box2d/2.4.x/conanfile.py
new file mode 100644
--- /dev/null
+++ b/recipes/box2d/2.4.x/conanfile.py
@@ -0,0 +1,66 @@
+import os
+from conans import ConanFile, CMake, tools
+
+
+class Box2dConan(ConanFile):
+    name = "box2d"
+    license = "Zlib"
+    description = "Box2D is a 2D physics engine for games"
+    homepage = "http://box2d.org/"
+    url = "https://github.com/conan-io/conan-center-index"
+    topics = ("physics-engine", "graphic", "2d", "collision")
+    settings = "os", "compiler", "build_type", "arch"
+    options = {"shared": [True, False],
+               "fPIC": [True, False]}
+    default_options = {"shared": False, "fPIC": True,}
+    generators = "cmake"
+    exports_sources = "CMakeLists.txt"
+
+    @property
+    def _source_subfolder(self):
+        return "source_subfolder"
+
+    @property
+    def _build_subfolder(self):
+        return "build_subfolder"
+
+    def config_options(self):
+        if self.settings.os == "Windows":
+            del self.options.fPIC
+
+    def configure(self):
+        if self.options.shared:
+            del self.options.fPIC
+
+    def source(self):
+        tools.get(**self.conan_data["sources"][self.version])
+        os.rename("box2d-%s" % self.version, self._source_subfolder)
+
+    def _patch_sources(self):
+        tools.replace_in_file(os.path.join(self._source_subfolder, "src", "CMakeLists.txt"),
+                              "box2d STATIC",
+                              "box2d")
+
+    def build(self):
+        self._patch_sources()
+        cmake = CMake(self)
+        if self.settings.os == "Windows" and self.options.shared:
+            cmake.definitions["CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS"] = True
+        cmake.definitions["BOX2D_BUILD_TESTBED"] = False
+        cmake.definitions["BOX2D_BUILD_UNIT_TESTS"] = False
+        cmake.configure(build_folder=self._build_subfolder)
+        cmake.build()
+
+    def package(self):
+        self.copy("LICENSE", dst="licenses", src=self._source_subfolder)
+        self.copy("*.h", dst="include", src=os.path.join(self._source_subfolder, "include"))
+        self.copy("*.lib", dst="lib", keep_path=False)
+        self.copy("*.dll", dst="bin", keep_path=False)
+        self.copy("*.so*", dst="lib", keep_path=False, symlinks=True)
+        self.copy("*.dylib", dst="lib", keep_path=False)
+        self.copy("*.a", dst="lib", keep_path=False)
+
+    def package_info(self):
+        self.cpp_info.libs = ["box2d"]
+        self.cpp_info.names["cmake_find_package"] = "Box2D"
+        self.cpp_info.names["cmake_find_package_multi"] = "Box2D"


Test patch:
diff --git a/recipes/box2d/2.4.x/test_package/CMakeLists.txt b/recipes/box2d/2.4.x/test_package/CMakeLists.txt
new file mode 100644
--- /dev/null
+++ b/recipes/box2d/2.4.x/test_package/CMakeLists.txt
@@ -0,0 +1,9 @@
+cmake_minimum_required(VERSION 3.1)
+project(test_package)
+
+include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
+conan_basic_setup()
+
+add_executable(${PROJECT_NAME} test_package.cpp)
+target_link_libraries(${PROJECT_NAME} ${CONAN_LIBS})
+set_property(TARGET ${PROJECT_NAME} PROPERTY CXX_STANDARD 11)
diff --git a/recipes/box2d/2.4.x/test_package/conanfile.py b/recipes/box2d/2.4.x/test_package/conanfile.py
new file mode 100644
--- /dev/null
+++ b/recipes/box2d/2.4.x/test_package/conanfile.py
@@ -0,0 +1,17 @@
+import os
+from conans import ConanFile, CMake, tools
+
+
+class Box2DTestConan(ConanFile):
+    settings = "os", "compiler", "build_type", "arch"
+    generators = "cmake"
+
+    def build(self):
+        cmake = CMake(self)
+        cmake.configure()
+        cmake.build()
+
+    def test(self):
+        if not tools.cross_building(self.settings):
+            bin_path = os.path.join("bin", "test_package")
+            self.run(bin_path, run_environment=True)
diff --git a/recipes/box2d/2.4.x/test_package/test_package.cpp b/recipes/box2d/2.4.x/test_package/test_package.cpp
new file mode 100644
--- /dev/null
+++ b/recipes/box2d/2.4.x/test_package/test_package.cpp
@@ -0,0 +1,16 @@
+#include <iostream>
+#include "box2d/box2d.h"
+
+int main(void) {
+    b2Vec2 gravity(0.0f, -10.0f);
+    b2World world(gravity);
+
+    b2BodyDef groundBodyDef;
+    groundBodyDef.position.Set(0.0f, -10.0f);
+
+    b2Body* groundBody = world.CreateBody(&groundBodyDef);
+    b2PolygonShape groundBox;
+    groundBox.SetAsBox(50.0f, 10.0f);
+
+    return 0;
+}