#
# Libevent CMake project
#
# Based on initial work by:
# Alexey Ozeritsky
#
# Additional changes:
# Brodie Thiesfield
# Joakim Soderberg
# Trond Norbye
# Sergei Nikulov
#
# Build example:
#
# cd libevent
# md build
# cd build
# cmake -G "Visual Studio 10" ..
# start libevent.sln
#
cmake_minimum_required(VERSION 3.1 FATAL_ERROR)
if (POLICY CMP0054)
cmake_policy(SET CMP0054 NEW)
endif()
if (POLICY CMP0074)
cmake_policy(SET CMP0074 NEW)
endif()
if (POLICY CMP0075)
cmake_policy(SET CMP0075 NEW)
endif()
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release
CACHE STRING "Set build type to Debug o Release (default Release)" FORCE)
endif()
string(TOLOWER "${CMAKE_BUILD_TYPE}" CMAKE_BUILD_TYPE_LOWER)
# get rid of the extra default configurations
# what? why would you get id of other useful build types? - Ellzey
set(CMAKE_CONFIGURATION_TYPES "Debug;Release" CACHE STRING "Limited configurations" FORCE)
set(EVENT__LIBRARY_TYPE DEFAULT CACHE STRING
"Set library type to SHARED/STATIC/BOTH (default SHARED for MSVC, otherwise BOTH)")
project(libevent C)
list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake/")
string(REGEX MATCH "SunOS" SOLARIS "${CMAKE_SYSTEM_NAME}")
set(EVENT_NUMERIC_VERSION 0x02010c00)
# equals to VERSION_INFO in Makefile.am
set(EVENT_ABI_LIBVERSION_CURRENT 7)
set(EVENT_ABI_LIBVERSION_REVISION 1)
set(EVENT_ABI_LIBVERSION_AGE 0)
# equals to RELEASE in Makefile.am
set(EVENT_PACKAGE_RELEASE 2.1)
# only a subset of names can be used, defaults to "beta"
set(EVENT_STAGE_NAME ${EVENT_VERSION_STAGE})
# a list that defines what can set for EVENT_STAGE_VERSION
set(EVENT__ALLOWED_STAGE_NAMES
rc
beta
alpha
alpha-dev
release
stable
)
list(
FIND EVENT__ALLOWED_STAGE_NAMES
"${EVENT_STAGE_NAME}"
EVENT__STAGE_RET
)
if (EVENT__STAGE_RET EQUAL -1)
message(WARNING
"stage ${EVENT_STAGE_NAME} is not allowed, reset to beta")
set(EVENT_STAGE_NAME beta)
endif()
option(EVENT__DISABLE_CLOCK_GETTIME
"Do not use clock_gettime even if it is available" OFF)
option(EVENT__FORCE_KQUEUE_CHECK
"When crosscompiling forces running a test program that verifies that Kqueue works with pipes. Note that this requires you to manually run the test program on the cross compilation target to verify that it works. See cmake documentation for try_run for more details" OFF)
# TODO: Add --disable-largefile omit support for large files
option(EVENT__COVERAGE
"Enable running gcov to get a test coverage report (only works with GCC/CLang). Make sure to enable -DCMAKE_BUILD_TYPE=Debug as well." OFF)
# Put the libaries and binaries that get built into directories at the
# top of the build tree rather than in hard-to-find leaf directories.
#
# But only if this variables are not defined yet
# (i.e. libevent is used via add_subdirectory())
if (NOT DEFINED CMAKE_RUNTIME_OUTPUT_DIRECTORY)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/bin)
endif()
if (NOT DEFINED CMAKE_LIBRARY_OUTPUT_DIRECTORY)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/lib)
endif()
if (NOT DEFINED CMAKE_ARCHIVE_OUTPUT_DIRECTORY)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/lib)
endif()
if (EVENT__ENABLE_VERBOSE_DEBUG)
add_definitions(-DUSE_DEBUG=1)
endif()
# make it colorful under ninja-build
if ("${CMAKE_GENERATOR}" STREQUAL "Ninja")
add_compiler_flags(-fdiagnostics-color=always)
endif()
# Setup compiler flags for coverage.
if (EVENT__COVERAGE)
if (NOT "${CMAKE_BUILD_TYPE_LOWER}" STREQUAL "debug")
message(FATAL_ERROR "Coverage requires -DCMAKE_BUILD_TYPE=Debug")
endif()
if (${CLANG})
list(APPEND __FLAGS -Wno-unused-function)
endif()
if (EVENT__DISABLE_GCC_WARNINGS)
list(APPEND __FLAGS -w)
endif()
if (EVENT__ENABLE_GCC_HARDENING)
list(APPEND __FLAGS
-fstack-protector-all
-fwrapv
-fPIE
-Wstack-protector
"--param ssp-buffer-size=1")
add_definitions(-D_FORTIFY_SOURCE=2)
endif()
if (EVENT__ENABLE_GCC_FUNCTION_SECTIONS)
list(APPEND __FLAGS -ffunction-sections)
# TODO: Add --gc-sections support. We need some checks for NetBSD to ensure this works.
endif()
if (EVENT__ENABLE_GCC_WARNINGS)
list(APPEND __FLAGS -Werror)
endif()
add_compiler_flags(${__FLAGS})
endif()
if (APPLE)
# Get rid of deprecated warnings for OpenSSL on OSX 10.7 and greater.
add_compiler_flags(
-Wno-error=deprecated-declarations
-Qunused-arguments
)
endif()
if(WIN32)
# These aren't available until Windows Vista.
# But you can still link them. They just won't be found when running the exe.
set(EVENT__HAVE_INET_NTOP 0)
set(EVENT__HAVE_INET_PTON 0)
endif()
# Check for different inline keyword versions.
check_function_keywords("inline" "__inline" "__inline__")
# __func__/__FUNCTION__ is not a macros in general
CHECK_SYMBOL_EXISTS("__func__" "" EVENT__HAVE___func__)
CHECK_SYMBOL_EXISTS("__FUNCTION__" "" EVENT__HAVE___FUNCTION__)
CHECK_TYPE_SIZE("off_t" EVENT__SIZEOF_OFF_T LANGUAGE C)
# XXX we should functionalize these size and type sets. --elley
# Winssck.
if (_MSC_VER)
list(APPEND CMAKE_EXTRA_INCLUDE_FILES BaseTsd.h)
endif()
CHECK_TYPE_SIZE("ssize_t" EVENT__SIZEOF_SSIZE_T_LOWER LANGUAGE C)
CHECK_TYPE_SIZE("SSIZE_T" EVENT__SIZEOF_SSIZE_T_UPPER LANGUAGE C)
# Tests file offset bits.
# TODO: Add AIX test for if -D_LARGE_FILES is needed.
# XXX: Why is this here? we don't even use it. Well, we don't even use it
# on top of that, why is it set in the config.h?! IT_MAKES_NO_SENSE
# I'm commenting it out for now.
# - ellzey
#CHECK_FILE_OFFSET_BITS()
# Verify kqueue works with pipes.
if (EVENT__HAVE_KQUEUE)
if ((CMAKE_CROSSCOMPILING OR APPLE) AND NOT EVENT__FORCE_KQUEUE_CHECK)
message(WARNING "Cannot check if kqueue works with pipes when crosscompiling, use EVENT__FORCE_KQUEUE_CHECK to be sure (this requires manually running a test program on the cross compilation target)")
set(EVENT__HAVE_WORKING_KQUEUE 1)
else()
message(STATUS "Checking if kqueue works with pipes...")
include(CheckWorkingKqueue)
endif()
endif()
if (NOT EVENT__DISABLE_THREAD_SUPPORT)
if (WIN32)
list(APPEND SRC_CORE evthread_win32.c)
else()
find_package(Threads REQUIRED)
if (NOT CMAKE_USE_PTHREADS_INIT)
message(FATAL_ERROR
"Failed to find Pthreads, set EVENT__DISABLE_THREAD_SUPPORT to disable")
endif()
# We use BEFORE here so we don't accidentally look in system directories
# first for some previous versions of the headers that are installed.
include_directories(BEFORE ${PROJECT_SOURCE_DIR}
${PROJECT_SOURCE_DIR}/compat
${PROJECT_SOURCE_DIR}/include)
# Generate the configure headers.
# (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__HAVE_PTHREADS)
set(SRC_PTHREADS evthread_pthread.c)
add_event_library(event_pthreads
INNER_LIBRARIES event_core
SOURCES ${SRC_PTHREADS})
endif()
# 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_event_library(event SOURCES ${SRC_CORE} ${SRC_EXTRA})
set(WIN32_GETOPT)
if (WIN32)
set(_TMPLIBS)
if (${EVENT_LIBRARY_STATIC})
list(APPEND _TMPLIBS event_core_static event_static)
endif()
if (${EVENT_LIBRARY_SHARED})
list(APPEND _TMPLIBS event_core_shared event_shared)
endif()
foreach(lib ${_TMPLIBS})
target_link_libraries(${lib} iphlpapi)
endforeach()
unset(_TMPLIBS)
if (WIN32)
list(APPEND SRC_REGRESS test/regress_iocp.c)
if (NOT EVENT__DISABLE_THREAD_SUPPORT)
list(APPEND SRC_REGRESS test/regress_thread.c)
endif()
elseif (EVENT__HAVE_PTHREADS)
list(APPEND SRC_REGRESS test/regress_thread.c)
endif()
if (ZLIB_LIBRARY AND ZLIB_INCLUDE_DIR)
list(APPEND SRC_REGRESS test/regress_zlib.c)
endif()
if (NOT EVENT__DISABLE_OPENSSL)
list(APPEND SRC_REGRESS test/regress_ssl.c)
endif()
add_executable(regress ${SRC_REGRESS})
target_link_libraries(regress
${LIB_APPS}
${LIB_PLATFORM}
event_core
event_extra)
if (NOT EVENT__DISABLE_OPENSSL)
target_link_libraries(regress event_openssl)
endif()
if (CMAKE_USE_PTHREADS_INIT)
target_link_libraries(regress event_pthreads)
endif()
else()
message(WARNING "No suitable Python interpreter found, cannot generate regress tests!")
endif()
endif()
#
# Test programs.
#
# all of these, including the cmakelists.txt should be moved
# into the dirctory 'tests' first.
#
# doing this, we can remove all the DISABLE_TESTS stuff, and simply
# do something like:
#
# add_custom_targets(tests)
# add_executable(... EXCLUDE_FROM_ALL ...c)
# add_dependencis(tests testa testb testc)
# add_test(....)
#
# then you can just run 'make tests' instead of them all
# auto-compile|running
# - ellzey
set(TESTPROGS test-changelist
test-eof
test-closed
test-fdleak
test-init
test-time
test-weof)
foreach (TESTPROG ${TESTPROGS} test-dumpevents)
add_test_prog(${TESTPROG})
endforeach()
if (UNIX)
add_test_prog(test-ratelim m)
else()
add_test_prog(test-ratelim)
endif()
#
# We run all tests with the different backends turned on one at a time.
#
# Add event backends based on system introspection result.
set(BACKENDS "")
if (EVENT__HAVE_EPOLL)
list(APPEND BACKENDS EPOLL)
endif()
if (EVENT__HAVE_SELECT)
list(APPEND BACKENDS SELECT)
endif()
if (EVENT__HAVE_POLL)
list(APPEND BACKENDS POLL)
endif()
if (EVENT__HAVE_KQUEUE)
list(APPEND BACKENDS KQUEUE)
endif()
if (EVENT__HAVE_EVENT_PORTS)
list(APPEND BACKENDS EVPORT)
endif()
if (EVENT__HAVE_DEVPOLL)
list(APPEND BACKENDS DEVPOLL)
endif()
if (WIN32)
list(APPEND BACKENDS WIN32)
endif()
# Default environment variables turns off all event systems,
# then we enable each one, one at a time when creating the tests.
set(DEFAULT_TEST_ENV_VARS)
foreach(BACKEND ${BACKENDS})
set(BACKEND_ENV_VAR "EVENT_NO${BACKEND}=1")
list(APPEND DEFAULT_TEST_ENV_VARS "${BACKEND_ENV_VAR}")
endforeach()
# Macro that creates the ctest test for a backend.
macro(add_backend_test BACKEND_TEST_NAME ENV_VARS)
set(TEST_NAMES "")
set_tests_properties(${TEST_NAME}
PROPERTIES ENVIRONMENT "${ENV_VARS}")
else()
message(WARNING "test-dumpevents will be run without output check since python was not found!")
set(TEST_NAME test-dumpevents__${BACKEND_TEST_NAME}_no_check)
# Add the tests for each backend.
foreach(BACKEND ${BACKENDS})
# Enable this backend only.
set(BACKEND_ENV_VARS ${DEFAULT_TEST_ENV_VARS})
list(REMOVE_ITEM BACKEND_ENV_VARS EVENT_NO${BACKEND}=1)
# Epoll has some extra settings.
if (${BACKEND} STREQUAL "EPOLL")
add_backend_test(timerfd_${BACKEND}
"${BACKEND_ENV_VARS};EVENT_PRECISE_TIMER=1")
# Connection limit and group limit with independent drain.
add_test(test-ratelim__group_con_lim_drain
${RL_BIN}
-c 1000
-g 35000
-n 30
-t 100
-G 500
--check-grouplimit 1000
--check-connlimit 50
--check-stddev 50)
# Add a "make verify" target, same as for autoconf.
# (Important! This will unset all EVENT_NO* environment variables.
# If they are set in the shell the tests are running using simply "ctest" or "make test" will fail)
if (WIN32)
# Windows doesn't have "unset". But you can use "set VAR=" instead.
# We need to guard against the possibility taht EVENT_NOWIN32 is set, and all test failing
# since no event backend being available.
file(TO_NATIVE_PATH ${CMAKE_CTEST_COMMAND} WINDOWS_CTEST_COMMAND)
file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/tmp/verify_tests.bat
"
set EVENT_NOWIN32=
\"${WINDOWS_CTEST_COMMAND}\"
")
add_custom_target(verify COMMAND "${VERIFY_PATH}"
DEPENDS event ${ALL_TESTPROGS})
else()
# On some platforms doing exec(unset) as CMake does won't work, so make sure
# we run the unset command in a shell instead.
# First we write the script contents.
file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/tmp/verify_tests.sh
"
#!/bin/bash
unset EVENT_NOEPOLL; unset EVENT_NOPOLL; unset EVENT_NOSELECT; unset EVENT_NOWIN32; unset EVENT_NOEVPORT; unset EVENT_NOKQUEUE; unset EVENT_NODEVPOLL
${CMAKE_CTEST_COMMAND}
")
# Then we copy the file (this allows us to set execute permission on it)
file(COPY ${CMAKE_CURRENT_BINARY_DIR}/tmp/verify_tests.sh
DESTINATION ${CMAKE_CURRENT_BINARY_DIR}
FILE_PERMISSIONS
OWNER_READ
OWNER_WRITE
OWNER_EXECUTE
GROUP_READ
GROUP_EXECUTE
WORLD_READ
WORLD_EXECUTE)
# Create the target that runs the script.
add_custom_target(verify
COMMAND ${CMAKE_CURRENT_BINARY_DIR}/verify_tests.sh
DEPENDS event ${ALL_TESTPROGS})
endif()
if (NOT EVENT__DISABLE_REGRESS AND __FOUND_USABLE_PYTHON)
add_dependencies(verify regress)
endif()
if (EVENT__COVERAGE)
include(CodeCoverage)
setup_target_for_coverage(
verify_coverage # Coverage target name "make verify_coverage"
make # Test runner.
coverage # Output directory.
verify) # Arguments passed to test runner. "make verify"
endif()
# Generate the config file for the build-tree.
set(EVENT__INCLUDE_DIRS
"${PROJECT_SOURCE_DIR}/include"
"${PROJECT_BINARY_DIR}/include")
set(LIBEVENT_INCLUDE_DIRS
${EVENT__INCLUDE_DIRS}
CACHE PATH "Libevent include directories")
gen_package_config(0)
# Generate the config file for the installation tree.
gen_package_config(1)
# Generate version info for both build-tree and install-tree.
configure_file(${PROJECT_SOURCE_DIR}/cmake/LibeventConfigVersion.cmake.in
${PROJECT_BINARY_DIR}/LibeventConfigVersion.cmake
@ONLY)
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.