How can i integrate lastest Box2D (2.4.1)

Hi, I am trying to integrate latest (2.4.1) Box2D into my cocos2d-x v4 project.

I was using Box2D 2.3.1 but i want to upgrade to latest and it seems latest Box2D changed project structure and CMakeLists.txt so it doesnt work.

can anyone help ?

In your CMakeLists.txt, disable the built-in Box2D, and add your own version to your project.

This disables the default version included with Cocos2d-x:
set(BUILD_EXT_BOX2D OFF CACHE BOOL "Build with internal Box2D support" FORCE)

You can then add something like this to your CMakeLists.txt to add your own version of Box2D (the new version of Box2D happens to be in projectname/external/Box2D/ for this example):

# add box2d
#set(box2d_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/external/Box2D/include)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/external/Box2D ${PROJECT_BINARY_DIR}/Box2D)
target_include_directories(cocos2d PRIVATE ${box2d_INCLUDE_DIRS}) #cocos2d lib needs the path too
target_link_libraries(${APP_NAME} PRIVATE Box2D)

EDIT: It looks like the new v2.4.1 release of Box2D has a lot of differences, include filenames, so you may need to edit the Cocos2d-x engine code to get this working properly.


Thank you.
I moved includes folder to main Box2D from up folder and changed Box2D CMakeLists include paths based on that and run this command to create VS solution

cmake . -G"Visual Studio 15 2017" -Tv141

gives that error

CMake Error at external/Box2D/CMakeLists.txt:120 (install):
  install FILES given no DESTINATION!

You may need to delete/comment out the installation section of the Box2D CMakeLists.txt, and then check if it works. If you do need it installed somewhere, then perhaps someone else here can help you with that.

I tried it before but this time it throws error for install directives. If I remove all install directives I got error from main CMakeList.txt like this

CMake Error at CMakeLists.txt:150 (get_target_property):
get_target_property() called with non-existent target “Box2D”.

The CMake documentation will most likely help you get those issues sorted. There’s no point guessing and deleting bits and pieces randomly, because you’ll just be wasting your own time.

I guess currently staying with box2d 2.3.1 better option,