Skip to content

Commit

Permalink
Add option to build shared library
Browse files Browse the repository at this point in the history
  • Loading branch information
trondn committed Feb 25, 2014
1 parent a0dd5df commit 4545fa9
Show file tree
Hide file tree
Showing 17 changed files with 542 additions and 12 deletions.
66 changes: 59 additions & 7 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
# Additional changes:
# Brodie Thiesfield
# Joakim Soderberg
# Trond Norbye
#
# Build example:
#
Expand All @@ -27,9 +28,16 @@ set(EVENT_VERSION_MAJOR 2)
set(EVENT_VERSION_MINOR 1)
set(EVENT_VERSION_PATCH 4)
set(EVENT_NUMERIC_VERSION 0x02010401)

set(EVENT_ABI_MAJOR 2)
set(EVENT_ABI_MINOR 1)
set(EVENT_ABI_PATCH 4)
set(EVENT_ABI_LIBVERSION "${EVENT_ABI_MAJOR}.${EVENT_ABI_MINOR}.${EVENT_ABI_PATCH}")

set(EVENT_VERSION "${EVENT_VERSION_MAJOR}.${EVENT_VERSION_MINOR}.${EVENT_VERSION_PATCH}-beta")
set(EVENT_PACKAGE_VERSION "${EVENT_VERSION_MAJOR}.${EVENT_VERSION_MINOR}.${EVENT_VERSION_PATCH}")

option(EVENT__BUILD_SHARED_LIBRARIES "Define if libevent should be built with shared libraries instead of archives" OFF)
option(EVENT__DISABLE_DEBUG_MODE "Define if libevent should build without support for a debug mode" OFF)
option(EVENT__ENABLE_VERBOSE_DEBUG "Enables verbose debugging" OFF)
option(EVENT__DISABLE_MM_REPLACEMENT "Define if libevent should not allow replacing the mm functions" OFF)
Expand Down Expand Up @@ -653,8 +661,24 @@ source_group("Source Extra" FILES ${SRC_EXTRA})
# (Place them in the build dir so we don't polute the source tree with generated files).
include_directories(BEFORE ${CMAKE_CURRENT_BINARY_DIR}/include)

if (EVENT__BUILD_SHARED_LIBRARIES)
set(EVENT__LIBRARY_TYPE SHARED)

if (CMAKE_COMPILER_IS_GNUC)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fvisibility=hidden")
elseif ("${CMAKE_C_COMPILER_ID}" STREQUAL "Clang")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fvisibility=hidden")
elseif ("${CMAKE_C_COMPILER_ID}" STREQUAL "SunPro")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -xldscope=hidden")
endif ()
set(EVENT__NEED_DLLIMPORT 1)

else (EVENT__BUILD_SHARED_LIBRARIES)
set(EVENT__LIBRARY_TYPE STATIC)
endif (EVENT__BUILD_SHARED_LIBRARIES)

configure_file(
${CMAKE_CURRENT_SOURCE_DIR}/event-config.h.cmake
${CMAKE_CURRENT_SOURCE_DIR}/event-config.h.cmake
${CMAKE_CURRENT_BINARY_DIR}/include/event2/event-config.h)

configure_file(
Expand All @@ -666,13 +690,13 @@ configure_file(
#

# TODO: Add dynamic versions of the libraries as well.
add_library(event_core STATIC
add_library(event_core ${EVENT__LIBRARY_TYPE}
${HDR_PRIVATE}
${HDR_PUBLIC}
${SRC_CORE}
)
add_library(event_extra STATIC

add_library(event_extra ${EVENT__LIBRARY_TYPE}
${HDR_PRIVATE}
${HDR_PUBLIC}
${SRC_CORE}
Expand All @@ -682,13 +706,32 @@ add_library(event_extra STATIC
# library exists for historical reasons; it contains the contents of
# both libevent_core and libevent_extra. You shouldn’t use it; it may
# go away in a future version of Libevent.
add_library(event STATIC
add_library(event ${EVENT__LIBRARY_TYPE}
${HDR_PRIVATE}
${HDR_PUBLIC}
${SRC_CORE}
${SRC_EXTRA}
)

if (EVENT__BUILD_SHARED_LIBRARIES)
target_link_libraries(event_core ${OPENSSL_LIBRARIES}
${CMAKE_THREAD_LIBS_INIT}
${LIB_PLATFORM})

target_link_libraries(event ${OPENSSL_LIBRARIES}
${CMAKE_THREAD_LIBS_INIT}
${LIB_PLATFORM})

target_link_libraries(event_extra ${OPENSSL_LIBRARIES}
${CMAKE_THREAD_LIBS_INIT}
${LIB_PLATFORM})

set_target_properties(event PROPERTIES SOVERSION ${EVENT_ABI_LIBVERSION})
set_target_properties(event_core PROPERTIES SOVERSION ${EVENT_ABI_LIBVERSION})
set_target_properties(event_extra PROPERTIES SOVERSION ${EVENT_ABI_LIBVERSION})

endif (EVENT__BUILD_SHARED_LIBRARIES)

#
# Samples.
#
Expand Down Expand Up @@ -777,6 +820,8 @@ if (NOT EVENT__DISABLE_TESTS)
test/regress_testutils.h
test/regress_util.c
test/tinytest.c
${SRC_CORE}
${SRC_EXTRA}
)

if (WIN32)
Expand All @@ -797,8 +842,14 @@ if (NOT EVENT__DISABLE_TESTS)
endif()

add_executable(regress ${SRC_REGRESS})
target_link_libraries(regress event_extra ${LIB_APPS} ${LIB_PLATFORM})
add_dependencies(regress event_extra)
# While building the test suite we don't want the visibility
# header trying to "dllimport" the symbols on windows (it
# generates a ton of warnings due to different link
# attributes for all of the symbols)
SET_TARGET_PROPERTIES(regress PROPERTIES COMPILE_DEFINITIONS
"EVENT_BUILDING_REGRESS_TEST=1")

target_link_libraries(regress ${LIB_APPS} ${LIB_PLATFORM})
else()
message(WARNING "Python not found, cannot generate regress tests!")
endif()
Expand Down Expand Up @@ -1064,6 +1115,7 @@ set_target_properties(event event_core event_extra
#
install(TARGETS event event_core event_extra
EXPORT LibeventTargets
RUNTIME DESTINATION "${EVENT_INSTALL_LIB_DIR}" COMPONENT bin
LIBRARY DESTINATION "${EVENT_INSTALL_LIB_DIR}" COMPONENT lib
ARCHIVE DESTINATION "${EVENT_INSTALL_LIB_DIR}" COMPONENT lib
PUBLIC_HEADER DESTINATION "${EVENT_INSTALL_INCLUDE_DIR}/event2" COMPONENT dev)
Expand Down
2 changes: 2 additions & 0 deletions event-config.h.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -497,4 +497,6 @@
/* Define to `int' if <sys/types.h> does not define. */
#cmakedefine EVENT__ssize_t ${EVENT__ssize_t}

#cmakedefine EVENT__NEED_DLLIMPORT ${EVENT__NEED_DLLIMPORT}

#endif
Loading

0 comments on commit 4545fa9

Please sign in to comment.