mosra / magnum-examples

Examples for the Magnum C++11 graphics engine
https://magnum.graphics/
The Unlicense
282 stars 95 forks source link

Box2D: Support for July 2020 version #90

Closed alanjfs closed 4 years ago

alanjfs commented 4 years ago

The latest release (as of this writing) of Box2D is from 2014 and uses mixed-case Box2D.h whereas the newer one is all lowercase box2d.h. This change adds support for the newer version, without breaking compatibility with the older one.

Box2D also no longer provides a CMake install() directive, which can be gotten around like this.

From..

# Version 2014
git clone https://github.com/erincatto/box2d --branch v2.3.1
cd box2d
mkdir build && cd build
cmake ..
cmake --build . --target install

To..

# Version 2020
git clone https://github.com/erincatto/box2d
cd box2d
git checkout 1025f9a
mkdir build && cd build
cmake ..
cmake --build .
cp src/box2d.bc <your-prefix>/lib/
cp -R ../include/box2d <your-prefix>/include/box2d
mosra commented 4 years ago

Thanks! Doesn't this need a similar update for the Box2D include? I assume you didn't run into this one because of case-insensitive filesystems, but then I wonder why CMake needed the change.

Something like this could work I think:

/* Latest Box2D release from 2014 uses mixed case, current master (2020) uses
   lowercase */
#ifdef __has_include
#if __has_include(<box2d/box2d.h>)
#include <box2d/box2d.h>
#else
#include <Box2D/Box2D.h>
#endif
/* If the compiler doesn't have __has_include, assume it's extremely old, and 
   thus an extremely old Box2D is more likely as well */
#else
#include <Box2D/Box2D.h>
#endif
alanjfs commented 4 years ago

You're right! I actually only tested this on my own code (on a Linux-box), but I should have also built the examples.

mosra commented 4 years ago

I see, that explains everything :)

mosra commented 4 years ago

Merged in 8ed6f5e9884c61db9c89c13d49f09a994a077574, together with fixing Yet Another Fun But Unnecessary Breakage in 5eb6fca6af7f9f506e3e2ad11fc1aa2fa57e0fa2.

Severe apologies for taking three centuries to merge PRs nowadays.