Skip to content

Commit

Permalink
Integrate libevent with cmake
Browse files Browse the repository at this point in the history
  • Loading branch information
rnburn authored and Johannes Tax committed Jul 7, 2020
1 parent dc35d6e commit fb83a8d
Show file tree
Hide file tree
Showing 11 changed files with 87 additions and 0 deletions.
9 changes: 9 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,16 @@ endif()

option(WITH_OTPROTOCOL
"Whether to include the OpenTelemetry Protocol in the SDK" OFF)
option(WITH_LIBEVENT
"Build SDK with libevent support" ON)

set(WITH_PROTOBUF OFF)
if(WITH_OTPROTOCOL)
set(WITH_PROTOBUF ON)
endif()

set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/Modules/")

include(CTest)

find_package(Threads)
Expand All @@ -42,6 +46,11 @@ if(WITH_OTPROTOCOL)
include(third_party/opentelemetry-proto/Protobuf.cmake)
endif()

if(WITH_LIBEVENT)
find_package(Libevent REQUIRED)
include_directories(SYSTEM ${LIBEVENT_INCLUDE_DIRS})
endif()

if(BUILD_TESTING)
find_package(GTest REQUIRED)
find_package(benchmark REQUIRED)
Expand Down
2 changes: 2 additions & 0 deletions ci/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@ ADD setup_ci_environment.sh /setup-ci
ADD setup_cmake.sh /setup-ci
ADD install_gcc48.sh /setup-ci
ADD install_bazelisk.sh /setup-ci
ADD install_libevent.sh /setup-ci
ADD install_protobuf.sh /setup-ci
ADD install_format_tools.sh /setup-ci

RUN /setup-ci/setup_ci_environment.sh \
&& /setup-ci/setup_cmake.sh \
&& /setup-ci/install_gcc48.sh \
&& /setup-ci/install_bazelisk.sh \
&& /setup-ci/install_libevent.sh \
&& /setup-ci/install_protobuf.sh \
&& /setup-ci/install_format_tools.sh
7 changes: 7 additions & 0 deletions ci/install_libevent.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/bash

set -e

apt-get install --no-install-recommends --no-install-suggests -y \
libevent-dev

48 changes: 48 additions & 0 deletions cmake/Modules/FindLibevent.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# find LibEvent
# an event notification library (http://libevent.org/)
#
# Usage:
# LIBEVENT_INCLUDE_DIRS, where to find LibEvent headers
# LIBEVENT_LIBRARIES, LibEvent libraries
# Libevent_FOUND, If false, do not try to use libevent
#
# Taken from https://github.com/apache/thrift/blob/7edc8faefd391ce11eca3023a35cc54bcb2eb1af/build/cmake/FindLibevent.cmake
# with modification.

set(LIBEVENT_ROOT CACHE PATH "Root directory of libevent installation")
set(LibEvent_EXTRA_PREFIXES /usr/local /opt/local "$ENV{HOME}" ${LIBEVENT_ROOT})
foreach(prefix ${LibEvent_EXTRA_PREFIXES})
list(APPEND LibEvent_INCLUDE_PATHS "${prefix}/include")
list(APPEND LibEvent_LIBRARIES_PATHS "${prefix}/lib")
endforeach()

# Looking for "event.h" will find the Platform SDK include dir on windows
# so we also look for a peer header like evhttp.h to get the right path
find_path(LIBEVENT_INCLUDE_DIRS evhttp.h event.h PATHS ${LibEvent_INCLUDE_PATHS})

# "lib" prefix is needed on Windows in some cases
# newer versions of libevent use three libraries
find_library(LIBEVENT_LIBRARIES NAMES event_core PATHS ${LibEvent_LIBRARIES_PATHS})

if (LIBEVENT_LIBRARIES AND LIBEVENT_INCLUDE_DIRS)
set(Libevent_FOUND TRUE)
set(LIBEVENT_LIBRARIES ${LIBEVENT_LIBRARIES})
else ()
set(Libevent_FOUND FALSE)
endif ()

if (Libevent_FOUND)
if (NOT Libevent_FIND_QUIETLY)
message(STATUS "Found libevent: ${LIBEVENT_LIBRARIES}")
endif ()
else ()
if (LibEvent_FIND_REQUIRED)
message(FATAL_ERROR "Could NOT find libevent.")
endif ()
message(STATUS "libevent NOT found.")
endif ()

mark_as_advanced(
LIBEVENT_LIBRARIES
LIBEVENT_INCLUDE_DIRS
)
Empty file removed cmake/TBD
Empty file.
1 change: 1 addition & 0 deletions sdk/src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
add_subdirectory(common)
add_subdirectory(event)
add_subdirectory(trace)
3 changes: 3 additions & 0 deletions sdk/src/event/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
if(WITH_LIBEVENT)
add_subdirectory(libevent)
endif()
7 changes: 7 additions & 0 deletions sdk/src/event/libevent/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
add_library(opentelemetry_event_libevent
dispatcher.cc
event.cc
event_base.cc
file_event.cc
timer.cc)
target_link_libraries(opentelemetry_event_libevent ${LIBEVENT_LIBRARIES})
1 change: 1 addition & 0 deletions sdk/test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
add_subdirectory(common)
add_subdirectory(event)
add_subdirectory(trace)
3 changes: 3 additions & 0 deletions sdk/test/event/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
if(WITH_LIBEVENT)
add_subdirectory(libevent)
endif()
6 changes: 6 additions & 0 deletions sdk/test/event/libevent/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
foreach(testname dispatcher_test)
add_executable(${testname} "${testname}.cc")
target_link_libraries(${testname} ${GTEST_BOTH_LIBRARIES}
${CMAKE_THREAD_LIBS_INIT} opentelemetry_event_libevent)
gtest_add_tests(TARGET ${testname} TEST_PREFIX event. TEST_LIST ${testname})
endforeach()

0 comments on commit fb83a8d

Please sign in to comment.