Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

box2d: add new version 3.0.0 #24946

Merged
merged 10 commits into from
Sep 26, 2024
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions recipes/box2d/all/conandata.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
sources:
"3.0.0":
url: "https://github.com/erincatto/box2d/archive/refs/tags/v3.0.0.tar.gz"
sha256: "64ad759006cd2377c99367f51fb36942b57f0e9ad690ed41548dd620e6f6c8b1"
"2.4.2":
url: "https://github.com/erincatto/box2d/archive/refs/tags/v2.4.2.tar.gz"
sha256: "85b9b104d256c985e6e244b4227d447897fac429071cc114e5cc819dae848852"
Expand All @@ -9,6 +12,13 @@ sources:
url: "https://github.com/erincatto/Box2D/archive/v2.4.0.zip"
sha256: "6aebbc54c93e367c97e382a57ba12546731dcde51526964c2ab97dec2050f8b9"
patches:
"3.0.0":
- patch_file: "patches/3.0.0-0001-fix-cmake.patch"
patch_description: "fix installer"
patch_type: "conan"
- patch_file: "patches/3.0.0-0002-use-cci.patch"
patch_description: "use cci package"
patch_type: "conan"
"2.4.0":
- patch_file: "patches/0001-install-and-allow-shared.patch"
patch_description: "add install, allow shared build"
Expand Down
51 changes: 47 additions & 4 deletions recipes/box2d/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import os
from conan import ConanFile
from conan.errors import ConanInvalidConfiguration
from conan.tools.files import apply_conandata_patches, export_conandata_patches, get, rm, rmdir, copy
from conan.tools.cmake import CMake, CMakeToolchain, cmake_layout
from conan.tools.cmake import CMake, CMakeDeps, CMakeToolchain, cmake_layout
from conan.tools.microsoft import is_msvc
from conan.tools.scm import Version

required_conan_version = ">=1.53.0"
Expand All @@ -25,6 +27,16 @@ class Box2dConan(ConanFile):
"fPIC": True
}

@property
def _compilers_minimum_version(self):
return {
"apple-clang": "10",
"clang": "7",
"gcc": "8",
"msvc": "193",
"Visual Studio": "17",
}

def export_sources(self):
export_conandata_patches(self)

Expand All @@ -35,19 +47,48 @@ def config_options(self):
def configure(self):
if self.options.shared:
self.options.rm_safe("fPIC")
if Version(self.version) >= "3.0.0":
del self.settings.compiler.libcxx
del self.settings.compiler.cppstd
AbrilRBS marked this conversation as resolved.
Show resolved Hide resolved

def layout(self):
cmake_layout(self, src_folder="src")

def requirements(self):
if Version(self.version) >= "3.0.0":
self.requires("simde/0.8.2")

def validate(self):
if Version(self.version) < "3.0.0":
return

minimum_version = self._compilers_minimum_version.get(str(self.settings.compiler), False)
if minimum_version and Version(self.settings.compiler.version) < minimum_version:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that once we drop Conan 1 support, Conan 2 added support for compiler.cstd, which could be useful for C projects like this, see https://docs.conan.io/2/reference/tools/build.html#cstd

raise ConanInvalidConfiguration(
f"{self.ref} requires C17, which your compiler does not support."
)

def build_requirements(self):
if Version(self.version) >= "3.0.0":
self.tool_requires("cmake/[>=3.22 <4]")

def source(self):
get(self, **self.conan_data["sources"][self.version], strip_root=True)

def generate(self):
tc = CMakeToolchain(self)
tc.cache_variables["CMAKE_POLICY_DEFAULT_CMP0077"] = "NEW"
tc.variables["BOX2D_BUILD_TESTBED"] = False
tc.variables["BOX2D_BUILD_UNIT_TESTS"] = False
if Version(self.version) < "3.0.0":
tc.variables["BOX2D_BUILD_TESTBED"] = False
tc.variables["BOX2D_BUILD_UNIT_TESTS"] = False
else:
tc.variables["BOX2D_SAMPLES"] = False
tc.variables["BOX2D_VALIDATE"] = False
tc.variables["BOX2D_UNIT_TESTS"] = False
tc.generate()
if Version(self.version) >= "3.0.0":
deps = CMakeDeps(self)
deps.generate()

def build(self):
apply_conandata_patches(self)
Expand All @@ -67,7 +108,9 @@ def package_info(self):
self.cpp_info.names["cmake_find_package"] = "box2d"
self.cpp_info.names["cmake_find_package_multi"] = "box2d"
self.cpp_info.libs = ["box2d"]
if Version(self.version) >= "2.4.1" and self.options.shared:
if Version(self.version) >= "3.0.0" and is_msvc(self) and self.options.shared:
self.cpp_info.defines.append("BOX2D_DLL")
elif Version(self.version) >= "2.4.1" and self.options.shared:
self.cpp_info.defines.append("B2_SHARED")
if self.settings.os in ["Linux", "FreeBSD"]:
self.cpp_info.system_libs.append("m")
17 changes: 17 additions & 0 deletions recipes/box2d/all/patches/3.0.0-0001-fix-cmake.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 5078d14..7ec17bc 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -180,4 +180,11 @@ endif()
source_group(TREE "${CMAKE_CURRENT_SOURCE_DIR}" PREFIX "src" FILES ${BOX2D_SOURCE_FILES})
source_group(TREE "${CMAKE_CURRENT_SOURCE_DIR}/../include" PREFIX "include" FILES ${BOX2D_API_FILES})

-install(TARGETS box2d)
+include(GNUInstallDirs)
+
+install(TARGETS box2d
+ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
+ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
+ ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
+)
+install(FILES ${BOX2D_API_FILES} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/box2d)
76 changes: 76 additions & 0 deletions recipes/box2d/all/patches/3.0.0-0002-use-cci.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 8c1390e..d6590d7 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -53,7 +53,7 @@ set_property(GLOBAL PROPERTY USE_FOLDERS ON)
set(CMAKE_VERBOSE_MAKEFILE ON)

# The Box2D library uses simde https://github.com/simd-everywhere/simde
-add_subdirectory(extern/simde)
+# add_subdirectory(extern/simde)
add_subdirectory(src)

# This hides samples, test, and doxygen from apps that use box2d via FetchContent
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 5078d14..7ec17bc 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -78,7 +78,7 @@ add_library(box2d ${BOX2D_SOURCE_FILES} ${BOX2D_API_FILES})
# turned this off to make Box2D easier to use without cmake
# include(GenerateExportHeader)
# generate_export_header(box2d)
-
+find_package(simde REQUIRED CONFIG)
target_include_directories(box2d
PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/../include>
@@ -89,7 +89,7 @@ target_include_directories(box2d
)

# SIMDE is used to support SIMD math on multiple platforms
-target_link_libraries(box2d PRIVATE simde)
+target_link_libraries(box2d PRIVATE simde::simde)

# Box2D uses C17
set_target_properties(box2d PROPERTIES
diff --git a/src/contact_solver.c b/src/contact_solver.c
index b190501..c61e250 100644
--- a/src/contact_solver.c
+++ b/src/contact_solver.c
@@ -9,8 +9,8 @@
#include "core.h"
#include "solver_set.h"
#include "world.h"
-#include "x86/avx2.h"
-#include "x86/fma.h"
+#include "simde/x86/avx2.h"
+#include "simde/x86/fma.h"

// Soft contact constraints with sub-stepping support
// http://mmacklin.com/smallsteps.pdf
diff --git a/src/contact_solver.h b/src/contact_solver.h
index e265e93..dcdc1fb 100644
--- a/src/contact_solver.h
+++ b/src/contact_solver.h
@@ -4,7 +4,7 @@
#pragma once

#include "solver.h"
-#include "x86/avx.h"
+#include "simde/x86/avx.h"

typedef struct b2ContactSim b2ContactSim;

diff --git a/src/solver.c b/src/solver.c
index d83a471..a115417 100644
--- a/src/solver.c
+++ b/src/solver.c
@@ -17,7 +17,7 @@
#include "world.h"

// for mm_pause
-#include "x86/sse2.h"
+#include "simde/x86/sse2.h"

#include <limits.h>
#include <stdatomic.h>
13 changes: 9 additions & 4 deletions recipes/box2d/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
cmake_minimum_required(VERSION 3.1)
project(test_package LANGUAGES CXX)
cmake_minimum_required(VERSION 3.21)
project(test_package LANGUAGES C CXX)

find_package(box2d REQUIRED CONFIG)

add_executable(${PROJECT_NAME} test_package.cpp)
if(box2d_VERSION VERSION_LESS "3.0.0")
add_executable(${PROJECT_NAME} test_package.cpp)
target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_11)
else()
add_executable(${PROJECT_NAME} test_package3.c)
target_compile_features(${PROJECT_NAME} PRIVATE c_std_17)
endif()
target_link_libraries(${PROJECT_NAME} PRIVATE box2d::box2d)
target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_11)
5 changes: 4 additions & 1 deletion recipes/box2d/all/test_package/conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from conan import ConanFile
from conan.tools.build import can_run
from conan.tools.cmake import CMake, cmake_layout

from conan.tools.scm import Version

class Box2DTestConan(ConanFile):
settings = "os", "compiler", "build_type", "arch"
Expand All @@ -15,6 +15,9 @@ def layout(self):
def requirements(self):
self.requires(self.tested_reference_str)

def build_requirements(self):
self.tool_requires("cmake/[>=3.21 <4]")

def build(self):
cmake = CMake(self)
cmake.configure()
Expand Down
13 changes: 13 additions & 0 deletions recipes/box2d/all/test_package/test_package3.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#include "box2d/box2d.h"

int main() {
b2WorldDef worldDef = b2DefaultWorldDef();

worldDef.gravity = (b2Vec2){0.0f, -10.0f};
b2WorldId worldId = b2CreateWorld(&worldDef);

b2BodyDef groundBodyDef = b2DefaultBodyDef();
groundBodyDef.position = (b2Vec2){0.0f, -10.0f};

return 0;
}
2 changes: 2 additions & 0 deletions recipes/box2d/config.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
versions:
"3.0.0":
folder: "all"
"2.4.2":
folder: "all"
"2.4.1":
Expand Down
Loading