diff --git a/recipes/box2d/all/conandata.yml b/recipes/box2d/all/conandata.yml index 8a363f08c6689..28c5a38b19b94 100644 --- a/recipes/box2d/all/conandata.yml +++ b/recipes/box2d/all/conandata.yml @@ -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" @@ -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" diff --git a/recipes/box2d/all/conanfile.py b/recipes/box2d/all/conanfile.py index cdd4fd6ee5dc9..1f7923c5d4d0d 100644 --- a/recipes/box2d/all/conanfile.py +++ b/recipes/box2d/all/conanfile.py @@ -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" @@ -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) @@ -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": + self.settings.rm_safe("compiler.cppstd") + self.settings.rm_safe("compiler.libcxx") 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: + 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) @@ -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") diff --git a/recipes/box2d/all/patches/3.0.0-0001-fix-cmake.patch b/recipes/box2d/all/patches/3.0.0-0001-fix-cmake.patch new file mode 100644 index 0000000000000..156dff0943ae2 --- /dev/null +++ b/recipes/box2d/all/patches/3.0.0-0001-fix-cmake.patch @@ -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) diff --git a/recipes/box2d/all/patches/3.0.0-0002-use-cci.patch b/recipes/box2d/all/patches/3.0.0-0002-use-cci.patch new file mode 100644 index 0000000000000..b9d850f931bb8 --- /dev/null +++ b/recipes/box2d/all/patches/3.0.0-0002-use-cci.patch @@ -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 + $ +@@ -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 + #include diff --git a/recipes/box2d/all/test_package/CMakeLists.txt b/recipes/box2d/all/test_package/CMakeLists.txt index 985bafbcaa4c7..4648d77c658ec 100644 --- a/recipes/box2d/all/test_package/CMakeLists.txt +++ b/recipes/box2d/all/test_package/CMakeLists.txt @@ -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) diff --git a/recipes/box2d/all/test_package/conanfile.py b/recipes/box2d/all/test_package/conanfile.py index d1ce1a2cbc477..3526395bd33d5 100644 --- a/recipes/box2d/all/test_package/conanfile.py +++ b/recipes/box2d/all/test_package/conanfile.py @@ -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" @@ -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() diff --git a/recipes/box2d/all/test_package/test_package3.c b/recipes/box2d/all/test_package/test_package3.c new file mode 100644 index 0000000000000..abad79d1a39be --- /dev/null +++ b/recipes/box2d/all/test_package/test_package3.c @@ -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; +} diff --git a/recipes/box2d/config.yml b/recipes/box2d/config.yml index d0f0027e07e5c..476a7f5aa4a7c 100644 --- a/recipes/box2d/config.yml +++ b/recipes/box2d/config.yml @@ -1,4 +1,6 @@ versions: + "3.0.0": + folder: "all" "2.4.2": folder: "all" "2.4.1":