Skip to content

Commit

Permalink
Merge no-boost into master.
Browse files Browse the repository at this point in the history
This eradicates boost as a dependency for everything except the Python
integration, which may or may not work for now.
  • Loading branch information
alecthomas committed Nov 29, 2013
2 parents 9271445 + b921445 commit d657954
Show file tree
Hide file tree
Showing 22 changed files with 166 additions and 194 deletions.
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ before_install:
- sudo apt-add-repository -y ppa:jkeiren/ppa
- if test $CC = gcc; then sudo add-apt-repository -y ppa:ubuntu-toolchain-r/test; fi
- sudo apt-get update -qq
- sudo apt-get install -y boost1.48 python-dev
- if test $CC = gcc; then sudo apt-get install gcc-4.7 g++-4.7; fi
- if test $CC = gcc; then sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.7 20; fi
- if test $CC = gcc; then sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-4.7 20; fi
Expand Down
4 changes: 4 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Change Log

## 2013-10-29 [no-boost branch] - Removed boost dependency for everything except python integration.

This branch requires C++11 support and has removed all the non-boost::python dependecies, reducing the overhead of running entityx.

## 2013-08-22 - Remove `boost::signal` and switch to `Simple::Signal`.

According to the [benchmarks](http://timj.testbit.eu/2013/cpp11-signal-system-performance/) Simple::Signal is an order of magnitude faster than `boost::signal`. Additionally, `boost::signal` is now deprecated in favor of `boost::signal2`, which is not supported on versions of Boost on a number of platforms.
Expand Down
51 changes: 26 additions & 25 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,9 @@ include_directories(${CMAKE_CURRENT_LIST_DIR})
set(ENTITYX_BUILD_TESTING false CACHE BOOL "Enable building of tests.")
set(ENTITYX_RUN_BENCHMARKS false CACHE BOOL "Run benchmarks (in conjunction with -DENTITYX_BUILD_TESTING=1).")
set(ENTITYX_MAX_COMPONENTS 64 CACHE STRING "Set the maximum number of components.")
set(ENTITYX_USE_CPP11_STDLIB false CACHE BOOL "For Clang, specify whether to use libc++ (-stdlib=libc++).")
# Check for which shared_ptr implementation to use.
set(ENTITYX_USE_STD_SHARED_PTR false CACHE BOOL "Use std::shared_ptr<T> rather than boost::shared_ptr<T>?")
set(ENTITYX_BUILD_SHARED true CACHE BOOL "Build shared libraries?")
set(ENTITYX_BUILD_PYTHON true CACHE BOOL "Build entityx::python?")
set(ENTITYX_BOOST_SP_DISABLE_THREADS false CACHE BOOL "Disable multi-threading support in boost::shared_ptr")
set(ENTITYX_USE_CPP11_STDLIB true CACHE BOOL "For Clang, specify whether to use libc++ (-stdlib=libc++).")
set(ENTITYX_BUILD_SHARED false CACHE BOOL "Build shared libraries?")
set(ENTITYX_BUILD_PYTHON false CACHE BOOL "Build entityx::python?")

include(${CMAKE_ROOT}/Modules/CheckIncludeFile.cmake)
include(CheckCXXSourceCompiles)
Expand All @@ -28,14 +25,30 @@ set(CMAKE_CXX_FLAGS_MINSIZEREL "-Os -DNDEBUG")
set(CMAKE_CXX_FLAGS_RELEASE "-O2 -DNDEBUG")
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O2 -g")

# C++11 feature checks
include(CheckCXX11Features.cmake)

add_definitions(-DGTEST_USE_OWN_TR1_TUPLE=1)
set(OLD_CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++")
check_cxx_source_compiles(
"
#include <memory>
int main() {
std::shared_ptr<int>();
}
"
ENTITYX_HAVE_CXX11_STDLIB
)

if (ENTITYX_BOOST_SP_DISABLE_THREADS)
message("-- Disabled multi-threading support in Boost (see http://www.boost.org/doc/libs/1_54_0/libs/smart_ptr/shared_ptr.htm)")
add_definitions(-DBOOST_SP_DISABLE_THREADS=1)
if (NOT ENTITYX_HAVE_CXX11_STDLIB)
message("-- Not using -stdlib=libc++ (test failed to build)")
set(CMAKE_CXX_FLAGS "${OLD_CMAKE_CXX_FLAGS}")
else ()
message("-- Using -stdlib=libc++")
endif ()

# C++11 feature checks
include(CheckCXX11Features.cmake)

# Misc features
check_include_file("stdint.h" HAVE_STDINT_H)
Expand All @@ -55,9 +68,6 @@ macro(create_test TARGET_NAME SOURCE)
entityx
gtest
gtest_main
${Boost_SYSTEM_LIBRARY}
${Boost_TIMER_LIBRARY}
${Boost_SIGNALS_LIBRARY}
${ARGN}
)
add_test(${TARGET_NAME} ${TARGET_NAME})
Expand All @@ -81,17 +91,13 @@ require(HAS_CXX11_LONG_LONG "C++11 lambdas")
message("-- Checking misc features")
require(HAVE_STDINT_H "stdint.h")

set(Boost_USE_STATIC_LIBS OFF)
set(Boost_USE_MULTITHREADED ON)
set(Boost_USE_STATIC_RUNTIME OFF)
if (ENTITYX_BUILD_PYTHON)
message("-- Building with Python support (-DENTITYX_BUILD_PYTHON=0 to disable)")
find_package(Boost 1.48.0 COMPONENTS python)
else (ENTITYX_BUILD_PYTHON)
message("-- Python support disabled")
endif (ENTITYX_BUILD_PYTHON)

include_directories(${Boost_INCLUDE_DIR})
set(CMAKE_CXX_FLAGS_DEBUG "-O0 -g")
set(CMAKE_CXX_FLAGS_MINSIZEREL "-Os -DNDEBUG")
set(CMAKE_CXX_FLAGS_RELEASE "-O2 -DNDEBUG")
Expand All @@ -100,24 +106,19 @@ set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O2 -g")
# Things to install
set(install_libs entityx)

include(CheckCXX11SharedPtr.cmake)

set(sources entityx/tags/TagsComponent.cc entityx/deps/Dependencies.cc entityx/System.cc entityx/Event.cc entityx/Entity.cc entityx/Manager.cc)
set(sources entityx/tags/TagsComponent.cc entityx/deps/Dependencies.cc entityx/System.cc entityx/Event.cc entityx/Entity.cc entityx/Manager.cc entityx/help/Timer.cc)
add_library(entityx STATIC ${sources})

if (ENTITYX_BUILD_SHARED)
message("-- Building shared libraries (-DENTITYX_BUILD_SHARED=0 to only build static librarires)")
add_library(entityx_shared SHARED ${sources})
target_link_libraries(
entityx_shared
${Boost_SIGNALS_LIBRARY}
)
set_target_properties(entityx_shared PROPERTIES OUTPUT_NAME entityx)
list(APPEND install_libs entityx_shared)
endif (ENTITYX_BUILD_SHARED)

include_directories(${Boost_INCLUDE_DIR})

if (ENTITYX_BUILD_PYTHON AND Boost_PYTHON_LIBRARY)
message("-- Found boost::python, building entityx/python")
find_package(PythonLibs REQUIRED)
Expand Down Expand Up @@ -149,7 +150,7 @@ if (ENTITYX_BUILD_PYTHON AND Boost_PYTHON_LIBRARY)
endif (ENTITYX_BUILD_PYTHON AND Boost_PYTHON_LIBRARY)

if (ENTITYX_BUILD_TESTING)
find_package(Boost 1.48.0 REQUIRED COMPONENTS timer system)
#find_package(Boost 1.48.0 REQUIRED COMPONENTS timer system)
add_subdirectory(gtest-1.6.0)
include_directories(${gtest_SOURCE_DIR}/include ${gtest_SOURCE_DIR})
enable_testing()
Expand Down
54 changes: 0 additions & 54 deletions CheckCXX11SharedPtr.cmake

This file was deleted.

18 changes: 0 additions & 18 deletions CheckNeedGetPointer.cmake

This file was deleted.

20 changes: 3 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# EntityX - A fast, type-safe C++ Entity Component System
# EntityX - A fast, type-safe C++ Entity Component System

[![Build Status](https://travis-ci.org/alecthomas/entityx.png)](https://travis-ci.org/alecthomas/entityx)

Expand All @@ -15,6 +15,7 @@ You can also contact me directly via [email](mailto:[email protected]) or [Twitte

## Recent Notable Changes

- 2013-10-29 - Boost has been removed as a primary dependency for builds not using python.
- 2013-08-21 - Remove dependency on `boost::signal` and switch to embedded [Simple::Signal](http://timj.testbit.eu/2013/cpp11-signal-system-performance/).
- 2013-08-18 - Destroying an entity invalidates all other references
- 2013-08-17 - Python scripting, and a more robust build system
Expand Down Expand Up @@ -281,7 +282,6 @@ EntityX has the following build and runtime requirements:
- A C++ compiler that supports a basic set of C++11 features (ie. Clang >= 3.1, GCC >= 4.7, and maybe (untested) VC++ with the [Nov 2012 CTP](http://www.microsoft.com/en-us/download/details.aspx?id=35515)).
- [CMake](http://cmake.org/)
- [Boost](http://boost.org) `1.48.0` (headers only unless using boost::python).
### C++11 compiler and library support
Expand All @@ -291,22 +291,12 @@ C++11 support is quite...raw. To make life more interesting, C++ support really
On OSX you must use Clang as the GCC version is practically prehistoric.
EntityX can build against libstdc++ (GCC with no C++11 library support) or libc++ (Clang with C++11 library support), though you will need to ensure that Boost is built with the same standard library.
I use Homebrew, and the following works for me:
For libstdc++:
```bash
brew install boost
cmake -DENTITYX_BUILD_SHARED=0 -DENTITYX_BUILD_TESTING=1 -DENTITYX_USE_STD_SHARED_PTR=1 -DENTITYX_USE_CPP11_STDLIB=0 ..
```

For libc++ (with C++11 support):

```bash
brew install boost --with-c++11
cmake -DENTITYX_BUILD_SHARED=0 -DENTITYX_BUILD_TESTING=1 -DENTITYX_USE_STD_SHARED_PTR=1 -DENTITYX_USE_CPP11_STDLIB=1 ..
cmake -DENTITYX_BUILD_SHARED=0 -DENTITYX_BUILD_TESTING=1 ..
```

### Installing on Ubuntu 12.04
Expand Down Expand Up @@ -338,14 +328,10 @@ Once these dependencies are installed you should be able to build and install En
- `-DENTITYX_BUILD_PYTHON=1` - Build Python scripting integration.
- `-DENTITYX_BUILD_TESTING=1` - Build tests (run with `make test`).
- `-DENTITYX_RUN_BENCHMARKS=1` - In conjunction with `-DENTITYX_BUILD_TESTING=1`, also build benchmarks.
- `-DENTITYX_USE_CPP11_STDLIB=1` - For Clang, specify whether to use `-stdlib=libc++`.
- `-DENTITYX_USE_STD_SHARED_PTR=1` - Use `std::shared_ptr<T>` (and friends) rather than the Boost equivalents. This does not eliminate the need for Boost, but is useful if the rest of your application uses `std::shared_ptr<T>`.
- `-DENTITYX_MAX_COMPONENTS=64` - Override the maximum number of components that can be assigned to each entity.
- `-DENTITYX_BUILD_SHARED=1` - Whether to build shared libraries (defaults to 1).
- `-DENTITYX_BUILD_TESTING=0` - Whether to build tests (defaults to 0). Run with "make && make test".

For a production build, you'll typically only need the `-DENTITYX_USE_STD_SHARED_PTR=1` flag, if any.

Once you have selected your flags, build and install with:

```sh
Expand Down
17 changes: 8 additions & 9 deletions entityx/3rdparty/simplesignal.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
#include <assert.h>
#include <stdint.h>
#include <vector>
#include <boost/function.hpp>

namespace Simple {

Expand Down Expand Up @@ -46,7 +45,7 @@ struct CollectorDefault<void> {
template<class Collector, class R, class... Args>
struct CollectorInvocation<Collector, R (Args...)> {
inline bool
invoke (Collector &collector, const boost::function<R (Args...)> &cbf, Args... args)
invoke (Collector &collector, const std::function<R (Args...)> &cbf, Args... args)
{
return collector (cbf (args...));
}
Expand All @@ -56,7 +55,7 @@ struct CollectorInvocation<Collector, R (Args...)> {
template<class Collector, class... Args>
struct CollectorInvocation<Collector, void (Args...)> {
inline bool
invoke (Collector &collector, const boost::function<void (Args...)> &cbf, Args... args)
invoke (Collector &collector, const std::function<void (Args...)> &cbf, Args... args)
{
cbf (args...); return collector();
}
Expand All @@ -66,7 +65,7 @@ struct CollectorInvocation<Collector, void (Args...)> {
template<class Collector, class R, class... Args>
class ProtoSignal<R (Args...), Collector> : private CollectorInvocation<Collector, R (Args...)> {
protected:
typedef boost::function<R (Args...)> CbFunction;
typedef std::function<R (Args...)> CbFunction;
typedef typename CbFunction::result_type Result;
typedef typename Collector::CollectorResult CollectorResult;
private:
Expand Down Expand Up @@ -237,7 +236,7 @@ class ProtoSignal<R (Args...), Collector> : private CollectorInvocation<Collecto
* The overhead of an unused signal is intentionally kept very low, around the size of a single pointer.
* Note that the Signal template types is non-copyable.
*/
template <typename SignalSignature, class Collector = Lib::CollectorDefault<typename boost::function<SignalSignature>::result_type> >
template <typename SignalSignature, class Collector = Lib::CollectorDefault<typename std::function<SignalSignature>::result_type> >
struct Signal /*final*/ :
Lib::ProtoSignal<SignalSignature, Collector>
{
Expand All @@ -247,15 +246,15 @@ struct Signal /*final*/ :
Signal (const CbFunction &method = CbFunction()) : ProtoSignal (method) {}
};

/// This function creates a boost::function by binding @a object to the member function pointer @a method.
template<class Instance, class Class, class R, class... Args> boost::function<R (Args...)>
/// This function creates a std::function by binding @a object to the member function pointer @a method.
template<class Instance, class Class, class R, class... Args> std::function<R (Args...)>
slot (Instance &object, R (Class::*method) (Args...))
{
return [&object, method] (Args... args) { return (object .* method) (args...); };
}

/// This function creates a boost::function by binding @a object to the member function pointer @a method.
template<class Class, class R, class... Args> boost::function<R (Args...)>
/// This function creates a std::function by binding @a object to the member function pointer @a method.
template<class Class, class R, class... Args> std::function<R (Args...)>
slot (Class *object, R (Class::*method) (Args...))
{
return [object, method] (Args... args) { return (object ->* method) (args...); };
Expand Down
Loading

0 comments on commit d657954

Please sign in to comment.