September, 2011


7
Sep 11

Integrating libevent2.

We have used libevent2 in one of our projects, I must admit I’m impressed by its performance and ease of use, what could have taken us a couple of weeks to implement only took a couple of days using libevent2.

Now comes the issue of packaging and shipping our product, we realized that linking libevent2 statically with our binary was the most ideal solution since the license allows for it anyway.

We use CMake to build our products and libevent2 uses autotools, trying to build libevent2 with a custom CMake script as listed in this thread was a real PITA and it didn’t work out, it turns out that building it using autotools invoked from CMake was trivial, the only catch is that you need version 2.8.0+ of CMake and 2.8.3+ on Mac OS X for it to work.

Extract the libevent2 source to a directory in your project tree, I chose srclib/libevent , then add the following to your top level CMakeLists.txt

include(ExternalProject)
ExternalProject_Add(
libevent
SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/srclib/libevent
CONFIGURE_COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/srclib/libevent/configure
PREFIX ${CMAKE_CURRENT_SOURCE_DIR}/srclib/libevent
BUILD_COMMAND make
BUILD_IN_SOURCE 1
)

now when it comes to linking, I used the following when building the binary, where ‘tumbak’ is the binary


target_link_libraries(tumbak ${PROJECT_SOURCE_DIR}/srclib/libevent/.libs/libevent.a)