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

easy way to switch from bundled libs to system #5

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all 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
37 changes: 29 additions & 8 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,36 @@ set(STK_INSTALL_BINARY_DIR "bin" CACHE
set(STK_INSTALL_DATA_DIR "share/supertuxkart" CACHE
STRING "Install data folder to this directory, absolute or relative to CMAKE_INSTALL_PREFIX")

INCLUDE (FindPkgConfig)

# Build the Bullet physics library
add_subdirectory("${PROJECT_SOURCE_DIR}/lib/bullet")
include_directories("${PROJECT_SOURCE_DIR}/lib/bullet/src")
pkg_search_module(BULLET bullet)
if(NOT BULLET_FOUND)
message("Using bundled bullet libs")
add_subdirectory("${PROJECT_SOURCE_DIR}/lib/bullet")
include_directories("${PROJECT_SOURCE_DIR}/lib/bullet/src")
set(BULLET_LIBRARIES "bulletdynamics;bulletcollision;bulletmath")
else(NOT BULLET_FOUND)
message("Using system bullet libs")
include_directories(${BULLET_INCLUDE_DIRS})
if(BULLET_VERSION GREATER 2.80)
message("We must apply patch for new bullet")
execute_process(COMMAND patch -p1 -d ${PROJECT_SOURCE_DIR} -i
${PROJECT_SOURCE_DIR}/patches/0001-btKartRaycast.cpp-fix-usage-with-new-bullet.patch)
endif(BULLET_VERSION GREATER 2.80)
endif(NOT BULLET_FOUND)

# Build the ENet UDP network library
add_subdirectory("${PROJECT_SOURCE_DIR}/lib/enet")
include_directories("${PROJECT_SOURCE_DIR}/lib/enet/include")
find_package(ENet)
if(NOT ENET_FOUND)
message("Using bundled enet libs")
add_subdirectory("${PROJECT_SOURCE_DIR}/lib/enet")
include_directories("${PROJECT_SOURCE_DIR}/lib/enet/include")
set(ENet_LIBRARIES "enet")
else(NOT ENET_FOUND)
message("Using system enet libs")
include_directories(${ENet_INCLUDE_DIRS})
endif(NOT ENET_FOUND)

# Build the irrlicht library
add_subdirectory("${PROJECT_SOURCE_DIR}/lib/irrlicht")
Expand Down Expand Up @@ -227,10 +250,8 @@ endif()

# Common library dependencies
target_link_libraries(supertuxkart
bulletdynamics
bulletcollision
bulletmath
enet
${BULLET_LIBRARIES}
${ENet_LIBRARIES}
stkirrlicht
${CURL_LIBRARIES}
${OGGVORBIS_LIBRARIES}
Expand Down
48 changes: 48 additions & 0 deletions cmake/FindENet.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# - Try to find enet
# Once done this will define
#
# ENET_FOUND - system has enet
# ENet_INCLUDE_DIRS - the enet include directory
# ENet_LIBRARIES - the libraries needed to use enet
#
# $ENETDIR is an environment variable used for finding enet.
#
# Borrowed from The Mana World
# http://themanaworld.org/
#
# Several changes and additions by Fabian 'x3n' Landau
# Lots of simplifications by Adrian Friedli
# > www.orxonox.net <

FIND_PATH(ENet_INCLUDE_DIRS enet/enet.h
PATHS
$ENV{ENETDIR}
/usr/local
/usr
PATH_SUFFIXES include
)

FIND_LIBRARY(ENet_LIBRARY
NAMES enet
PATHS
$ENV{ENETDIR}
/usr/local
/usr
PATH_SUFFIXES lib
)

# handle the QUIETLY and REQUIRED arguments and set ENET_FOUND to TRUE if
# all listed variables are TRUE
INCLUDE(FindPackageHandleStandardArgs)
FIND_PACKAGE_HANDLE_STANDARD_ARGS(ENet DEFAULT_MSG ENet_LIBRARY ENet_INCLUDE_DIRS)

IF (ENET_FOUND)
IF(WIN32)
SET(WINDOWS_ENET_DEPENDENCIES "ws2_32;winmm")
SET(ENet_LIBRARIES ${ENet_LIBRARY} ${WINDOWS_ENET_DEPENDENCIES})
ELSE(WIN32)
SET(ENet_LIBRARIES ${ENet_LIBRARY})
ENDIF(WIN32)
ENDIF (ENET_FOUND)

MARK_AS_ADVANCED(ENet_LIBRARY ENet_LIBRARIES ENet_INCLUDE_DIRS)
61 changes: 61 additions & 0 deletions patches/0001-btKartRaycast.cpp-fix-usage-with-new-bullet.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
From 44c1ff53faf31f4550ee26af4107802773c6f625 Mon Sep 17 00:00:00 2001
From: Igor Gnatenko <i.gnatenko.brain@gmail.com>
Date: Fri, 17 Jan 2014 13:11:54 +0400
Subject: [PATCH] btKartRaycast.cpp: fix usage with new bullet
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

btKartRaycast.cpp:66:78: error: invalid conversion from ‘const btRigidBody*’ to ‘btRigidBody*’ [-fpermissive]
btRigidBody* body = btRigidBody::upcast(rayCallback.m_collisionObject);
^
make[2]: *** [CMakeFiles/supertuxkart.dir/src/physics/btKartRaycast.cpp.o] Error 1

Signed-off-by: Igor Gnatenko <i.gnatenko.brain@gmail.com>
---
src/physics/btKartRaycast.cpp | 4 ++--
src/physics/physics.cpp | 6 ++----
2 files changed, 4 insertions(+), 6 deletions(-)

diff --git a/src/physics/btKartRaycast.cpp b/src/physics/btKartRaycast.cpp
index 13b310f..7c00d42 100644
--- a/src/physics/btKartRaycast.cpp
+++ b/src/physics/btKartRaycast.cpp
@@ -63,7 +63,7 @@ void* btKartRaycaster::castRay(const btVector3& from, const btVector3& to,

if (rayCallback.hasHit())
{
- btRigidBody* body = btRigidBody::upcast(rayCallback.m_collisionObject);
+ const btRigidBody* body = btRigidBody::upcast(rayCallback.m_collisionObject);
if (body && body->hasContactResponse())
{
result.m_hitPointInWorld = rayCallback.m_hitPointWorld;
@@ -88,7 +88,7 @@ void* btKartRaycaster::castRay(const btVector3& from, const btVector3& to,
result.m_hitNormalInWorld.getZ());
#endif
}
- return body;
+ return (void *) body;
}
}
return 0;
diff --git a/src/physics/physics.cpp b/src/physics/physics.cpp
index 927ad6f..d2d00f9 100644
--- a/src/physics/physics.cpp
+++ b/src/physics/physics.cpp
@@ -449,10 +449,8 @@ btScalar Physics::solveGroup(btCollisionObject** bodies, int numBodies,
btPersistentManifold* contact_manifold =
m_dynamics_world->getDispatcher()->getManifoldByIndexInternal(i);

- btCollisionObject* objA =
- static_cast<btCollisionObject*>(contact_manifold->getBody0());
- btCollisionObject* objB =
- static_cast<btCollisionObject*>(contact_manifold->getBody1());
+ const btCollisionObject* objA = contact_manifold->getBody0();
+ const btCollisionObject* objB = contact_manifold->getBody1();

unsigned int num_contacts = contact_manifold->getNumContacts();
if(!num_contacts) continue; // no real collision
--
1.8.4.2