1*a466cc55SCy Schubert# 2*a466cc55SCy Schubert# Libevent CMake project 3*a466cc55SCy Schubert# 4*a466cc55SCy Schubert# Based on initial work by: 5*a466cc55SCy Schubert# Alexey Ozeritsky 6*a466cc55SCy Schubert# 7*a466cc55SCy Schubert# Additional changes: 8*a466cc55SCy Schubert# Brodie Thiesfield 9*a466cc55SCy Schubert# Joakim Soderberg 10*a466cc55SCy Schubert# Trond Norbye 11*a466cc55SCy Schubert# Sergei Nikulov 12*a466cc55SCy Schubert# 13*a466cc55SCy Schubert# Build example: 14*a466cc55SCy Schubert# 15*a466cc55SCy Schubert# cd libevent 16*a466cc55SCy Schubert# md build 17*a466cc55SCy Schubert# cd build 18*a466cc55SCy Schubert# cmake -G "Visual Studio 10" .. 19*a466cc55SCy Schubert# start libevent.sln 20*a466cc55SCy Schubert# 21*a466cc55SCy Schubert 22*a466cc55SCy Schubertcmake_minimum_required(VERSION 3.1 FATAL_ERROR) 23*a466cc55SCy Schubert 24*a466cc55SCy Schubertif (POLICY CMP0054) 25*a466cc55SCy Schubert cmake_policy(SET CMP0054 NEW) 26*a466cc55SCy Schubertendif() 27*a466cc55SCy Schubertif (POLICY CMP0074) 28*a466cc55SCy Schubert cmake_policy(SET CMP0074 NEW) 29*a466cc55SCy Schubertendif() 30*a466cc55SCy Schubertif (POLICY CMP0075) 31*a466cc55SCy Schubert cmake_policy(SET CMP0075 NEW) 32*a466cc55SCy Schubertendif() 33*a466cc55SCy Schubert 34*a466cc55SCy Schubertif(NOT CMAKE_BUILD_TYPE) 35*a466cc55SCy Schubert set(CMAKE_BUILD_TYPE Release 36*a466cc55SCy Schubert CACHE STRING "Set build type to Debug o Release (default Release)" FORCE) 37*a466cc55SCy Schubertendif() 38*a466cc55SCy Schubertstring(TOLOWER "${CMAKE_BUILD_TYPE}" CMAKE_BUILD_TYPE_LOWER) 39*a466cc55SCy Schubert 40*a466cc55SCy Schubert# get rid of the extra default configurations 41*a466cc55SCy Schubert# what? why would you get id of other useful build types? - Ellzey 42*a466cc55SCy Schubertset(CMAKE_CONFIGURATION_TYPES "Debug;Release" CACHE STRING "Limited configurations" FORCE) 43*a466cc55SCy Schubert 44*a466cc55SCy Schubertset(EVENT__LIBRARY_TYPE DEFAULT CACHE STRING 45*a466cc55SCy Schubert "Set library type to SHARED/STATIC/BOTH (default SHARED for MSVC, otherwise BOTH)") 46*a466cc55SCy Schubert 47*a466cc55SCy Schubertproject(libevent C) 48*a466cc55SCy Schubert 49*a466cc55SCy Schubertlist(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake/") 50*a466cc55SCy Schubertstring(REGEX MATCH "SunOS" SOLARIS "${CMAKE_SYSTEM_NAME}") 51*a466cc55SCy Schubert 52*a466cc55SCy Schubert 53*a466cc55SCy Schubertinclude(CheckTypeSize) 54*a466cc55SCy Schubertinclude(CheckFileOffsetBits) 55*a466cc55SCy Schubertinclude(Macros) 56*a466cc55SCy Schubertinclude(CheckVariableExists) 57*a466cc55SCy Schubertinclude(CheckSymbolExists) 58*a466cc55SCy Schubertinclude(CheckStructHasMember) 59*a466cc55SCy Schubertinclude(CheckCSourceCompiles) 60*a466cc55SCy Schubertinclude(CheckPrototypeDefinition) 61*a466cc55SCy Schubertinclude(CheckFunctionKeywords) 62*a466cc55SCy Schubertinclude(CheckConstExists) 63*a466cc55SCy Schubertinclude(AddCompilerFlags) 64*a466cc55SCy Schubertinclude(VersionViaGit) 65*a466cc55SCy Schubert 66*a466cc55SCy Schubertevent_fuzzy_version_from_git() 67*a466cc55SCy Schubert 68*a466cc55SCy Schubertset(EVENT_VERSION_MAJOR ${EVENT_GIT___VERSION_MAJOR}) 69*a466cc55SCy Schubertset(EVENT_VERSION_MINOR ${EVENT_GIT___VERSION_MINOR}) 70*a466cc55SCy Schubertset(EVENT_VERSION_PATCH ${EVENT_GIT___VERSION_PATCH}) 71*a466cc55SCy Schubertset(EVENT_VERSION_STAGE ${EVENT_GIT___VERSION_STAGE}) 72*a466cc55SCy Schubert 73*a466cc55SCy Schubert 74*a466cc55SCy Schubertset(EVENT_ABI_MAJOR ${EVENT_VERSION_MAJOR}) 75*a466cc55SCy Schubertset(EVENT_ABI_MINOR ${EVENT_VERSION_MINOR}) 76*a466cc55SCy Schubertset(EVENT_ABI_PATCH ${EVENT_VERSION_PATCH}) 77*a466cc55SCy Schubert 78*a466cc55SCy Schubertset(EVENT_ABI_LIBVERSION 79*a466cc55SCy Schubert "${EVENT_ABI_MAJOR}.${EVENT_ABI_MINOR}.${EVENT_ABI_PATCH}") 80*a466cc55SCy Schubert 81*a466cc55SCy Schubertset(EVENT_PACKAGE_VERSION 82*a466cc55SCy Schubert "${EVENT_VERSION_MAJOR}.${EVENT_VERSION_MINOR}.${EVENT_VERSION_PATCH}") 83*a466cc55SCy Schubert 84*a466cc55SCy Schubertset(EVENT_NUMERIC_VERSION 0x02010c00) 85*a466cc55SCy Schubert# equals to VERSION_INFO in Makefile.am 86*a466cc55SCy Schubertset(EVENT_ABI_LIBVERSION_CURRENT 7) 87*a466cc55SCy Schubertset(EVENT_ABI_LIBVERSION_REVISION 1) 88*a466cc55SCy Schubertset(EVENT_ABI_LIBVERSION_AGE 0) 89*a466cc55SCy Schubert 90*a466cc55SCy Schubert# equals to RELEASE in Makefile.am 91*a466cc55SCy Schubertset(EVENT_PACKAGE_RELEASE 2.1) 92*a466cc55SCy Schubert 93*a466cc55SCy Schubert# only a subset of names can be used, defaults to "beta" 94*a466cc55SCy Schubertset(EVENT_STAGE_NAME ${EVENT_VERSION_STAGE}) 95*a466cc55SCy Schubert 96*a466cc55SCy Schubert# a list that defines what can set for EVENT_STAGE_VERSION 97*a466cc55SCy Schubertset(EVENT__ALLOWED_STAGE_NAMES 98*a466cc55SCy Schubert rc 99*a466cc55SCy Schubert beta 100*a466cc55SCy Schubert alpha 101*a466cc55SCy Schubert alpha-dev 102*a466cc55SCy Schubert release 103*a466cc55SCy Schubert stable 104*a466cc55SCy Schubert) 105*a466cc55SCy Schubertlist( 106*a466cc55SCy Schubert FIND EVENT__ALLOWED_STAGE_NAMES 107*a466cc55SCy Schubert "${EVENT_STAGE_NAME}" 108*a466cc55SCy Schubert EVENT__STAGE_RET 109*a466cc55SCy Schubert) 110*a466cc55SCy Schubertif (EVENT__STAGE_RET EQUAL -1) 111*a466cc55SCy Schubert message(WARNING 112*a466cc55SCy Schubert "stage ${EVENT_STAGE_NAME} is not allowed, reset to beta") 113*a466cc55SCy Schubert set(EVENT_STAGE_NAME beta) 114*a466cc55SCy Schubertendif() 115*a466cc55SCy Schubert 116*a466cc55SCy Schubertset(EVENT_VERSION 117*a466cc55SCy Schubert "${EVENT_VERSION_MAJOR}.${EVENT_VERSION_MINOR}.${EVENT_VERSION_PATCH}-${EVENT_STAGE_NAME}") 118*a466cc55SCy Schubert 119*a466cc55SCy Schubertoption(EVENT__DISABLE_DEBUG_MODE 120*a466cc55SCy Schubert "Define if libevent should build without support for a debug mode" OFF) 121*a466cc55SCy Schubert 122*a466cc55SCy Schubertoption(EVENT__ENABLE_VERBOSE_DEBUG 123*a466cc55SCy Schubert "Enables verbose debugging" OFF) 124*a466cc55SCy Schubert 125*a466cc55SCy Schubertoption(EVENT__DISABLE_MM_REPLACEMENT 126*a466cc55SCy Schubert "Define if libevent should not allow replacing the mm functions" OFF) 127*a466cc55SCy Schubert 128*a466cc55SCy Schubertoption(EVENT__DISABLE_THREAD_SUPPORT 129*a466cc55SCy Schubert "Define if libevent should not be compiled with thread support" OFF) 130*a466cc55SCy Schubert 131*a466cc55SCy Schubertoption(EVENT__DISABLE_OPENSSL 132*a466cc55SCy Schubert "Define if libevent should build without support for OpenSSL encryption" OFF) 133*a466cc55SCy Schubert 134*a466cc55SCy Schubertoption(EVENT__DISABLE_BENCHMARK 135*a466cc55SCy Schubert "Defines if libevent should build without the benchmark executables" OFF) 136*a466cc55SCy Schubert 137*a466cc55SCy Schubertoption(EVENT__DISABLE_TESTS 138*a466cc55SCy Schubert "If tests should be compiled or not" OFF) 139*a466cc55SCy Schubert 140*a466cc55SCy Schubertoption(EVENT__DISABLE_REGRESS 141*a466cc55SCy Schubert "Disable the regress tests" OFF) 142*a466cc55SCy Schubert 143*a466cc55SCy Schubertoption(EVENT__DISABLE_SAMPLES 144*a466cc55SCy Schubert "Disable sample files" OFF) 145*a466cc55SCy Schubert 146*a466cc55SCy Schubertoption(EVENT__DISABLE_CLOCK_GETTIME 147*a466cc55SCy Schubert "Do not use clock_gettime even if it is available" OFF) 148*a466cc55SCy Schubert 149*a466cc55SCy Schubertoption(EVENT__FORCE_KQUEUE_CHECK 150*a466cc55SCy Schubert "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) 151*a466cc55SCy Schubert 152*a466cc55SCy Schubert# TODO: Add --disable-largefile omit support for large files 153*a466cc55SCy Schubertoption(EVENT__COVERAGE 154*a466cc55SCy Schubert"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) 155*a466cc55SCy Schubert 156*a466cc55SCy Schubert# Put the libaries and binaries that get built into directories at the 157*a466cc55SCy Schubert# top of the build tree rather than in hard-to-find leaf directories. 158*a466cc55SCy Schubert# 159*a466cc55SCy Schubert# But only if this variables are not defined yet 160*a466cc55SCy Schubert# (i.e. libevent is used via add_subdirectory()) 161*a466cc55SCy Schubertif (NOT DEFINED CMAKE_RUNTIME_OUTPUT_DIRECTORY) 162*a466cc55SCy Schubert set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/bin) 163*a466cc55SCy Schubertendif() 164*a466cc55SCy Schubertif (NOT DEFINED CMAKE_LIBRARY_OUTPUT_DIRECTORY) 165*a466cc55SCy Schubert set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/lib) 166*a466cc55SCy Schubertendif() 167*a466cc55SCy Schubertif (NOT DEFINED CMAKE_ARCHIVE_OUTPUT_DIRECTORY) 168*a466cc55SCy Schubert set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/lib) 169*a466cc55SCy Schubertendif() 170*a466cc55SCy Schubert 171*a466cc55SCy Schubertif (EVENT__ENABLE_VERBOSE_DEBUG) 172*a466cc55SCy Schubert add_definitions(-DUSE_DEBUG=1) 173*a466cc55SCy Schubertendif() 174*a466cc55SCy Schubert 175*a466cc55SCy Schubert# make it colorful under ninja-build 176*a466cc55SCy Schubertif ("${CMAKE_GENERATOR}" STREQUAL "Ninja") 177*a466cc55SCy Schubert add_compiler_flags(-fdiagnostics-color=always) 178*a466cc55SCy Schubertendif() 179*a466cc55SCy Schubert 180*a466cc55SCy Schubert# Setup compiler flags for coverage. 181*a466cc55SCy Schubertif (EVENT__COVERAGE) 182*a466cc55SCy Schubert if (NOT "${CMAKE_BUILD_TYPE_LOWER}" STREQUAL "debug") 183*a466cc55SCy Schubert message(FATAL_ERROR "Coverage requires -DCMAKE_BUILD_TYPE=Debug") 184*a466cc55SCy Schubert endif() 185*a466cc55SCy Schubert 186*a466cc55SCy Schubert message(STATUS "Setting coverage compiler flags") 187*a466cc55SCy Schubert 188*a466cc55SCy Schubert set(CMAKE_REQUIRED_LIBRARIES "--coverage") 189*a466cc55SCy Schubert add_compiler_flags(-g -O0 --coverage) 190*a466cc55SCy Schubert set(CMAKE_REQUIRED_LIBRARIES "") 191*a466cc55SCy Schubertendif() 192*a466cc55SCy Schubert 193*a466cc55SCy Schubertset(GNUC 0) 194*a466cc55SCy Schubertset(CLANG 0) 195*a466cc55SCy Schubertset(MSVC 0) 196*a466cc55SCy Schubertif (("${CMAKE_C_COMPILER_ID}" STREQUAL "Clang") OR 197*a466cc55SCy Schubert ("${CMAKE_C_COMPILER_ID}" STREQUAL "AppleClang")) 198*a466cc55SCy Schubert set(CLANG 1) 199*a466cc55SCy Schubertendif() 200*a466cc55SCy Schubertif (("${CMAKE_C_COMPILER_ID}" STREQUAL "GNU") OR (${CLANG})) 201*a466cc55SCy Schubert set(GNUC 1) 202*a466cc55SCy Schubertendif() 203*a466cc55SCy Schubertif (("${CMAKE_C_COMPILER_ID}" STREQUAL "MSVC") OR (${CLANG})) 204*a466cc55SCy Schubert set(MSVC 1) 205*a466cc55SCy Schubertendif() 206*a466cc55SCy Schubert 207*a466cc55SCy Schubert# Detect library type 208*a466cc55SCy Schubertset(EVENT_LIBRARY_TYPE) 209*a466cc55SCy Schubertif ("${EVENT__LIBRARY_TYPE}" STREQUAL "DEFAULT") 210*a466cc55SCy Schubert if (${MSVC}) 211*a466cc55SCy Schubert set(EVENT_LIBRARY_TYPE SHARED) 212*a466cc55SCy Schubert else() 213*a466cc55SCy Schubert set(EVENT_LIBRARY_TYPE BOTH) 214*a466cc55SCy Schubert endif() 215*a466cc55SCy Schubertelse() 216*a466cc55SCy Schubert string(TOUPPER "${EVENT__LIBRARY_TYPE}" EVENT_LIBRARY_TYPE) 217*a466cc55SCy Schubertendif() 218*a466cc55SCy Schubertif ((${MSVC}) AND ("${EVENT_LIBRARY_TYPE}" STREQUAL "BOTH")) 219*a466cc55SCy Schubert message(WARNING 220*a466cc55SCy Schubert "Building SHARED and STATIC is not supported for MSVC " 221*a466cc55SCy Schubert "(due to conflicts in library name" 222*a466cc55SCy Schubert " between STATIC library and IMPORTED library for SHARED libraries)") 223*a466cc55SCy Schubertendif() 224*a466cc55SCy Schubertset(EVENT_LIBRARY_STATIC OFF) 225*a466cc55SCy Schubertset(EVENT_LIBRARY_SHARED OFF) 226*a466cc55SCy Schubertif ("${EVENT_LIBRARY_TYPE}" STREQUAL "BOTH") 227*a466cc55SCy Schubert set(EVENT_LIBRARY_STATIC ON) 228*a466cc55SCy Schubert set(EVENT_LIBRARY_SHARED ON) 229*a466cc55SCy Schubertelseif ("${EVENT_LIBRARY_TYPE}" STREQUAL "STATIC") 230*a466cc55SCy Schubert set(EVENT_LIBRARY_STATIC ON) 231*a466cc55SCy Schubertelseif ("${EVENT_LIBRARY_TYPE}" STREQUAL "SHARED") 232*a466cc55SCy Schubert set(EVENT_LIBRARY_SHARED ON) 233*a466cc55SCy Schubertelse() 234*a466cc55SCy Schubert message(FATAL_ERROR "${EVENT_LIBRARY_TYPE} is not supported") 235*a466cc55SCy Schubertendif() 236*a466cc55SCy Schubert 237*a466cc55SCy Schubertif (${MSVC}) 238*a466cc55SCy Schubert set(msvc_static_runtime OFF) 239*a466cc55SCy Schubert if ("${EVENT_LIBRARY_TYPE}" STREQUAL "STATIC") 240*a466cc55SCy Schubert set(msvc_static_runtime ON) 241*a466cc55SCy Schubert endif() 242*a466cc55SCy Schubert 243*a466cc55SCy Schubert # For more info: 244*a466cc55SCy Schubert # - https://docs.microsoft.com/en-us/cpp/build/reference/md-mt-ld-use-run-time-library?view=vs-2017 245*a466cc55SCy Schubert # - https://gitlab.kitware.com/cmake/community/wikis/FAQ#how-can-i-build-my-msvc-application-with-a-static-runtime 246*a466cc55SCy Schubert option(EVENT__MSVC_STATIC_RUNTIME 247*a466cc55SCy Schubert "Link static runtime libraries" 248*a466cc55SCy Schubert ${msvc_static_runtime}) 249*a466cc55SCy Schubert 250*a466cc55SCy Schubert if (EVENT__MSVC_STATIC_RUNTIME) 251*a466cc55SCy Schubert foreach (flag_var 252*a466cc55SCy Schubert CMAKE_C_FLAGS_DEBUG 253*a466cc55SCy Schubert CMAKE_C_FLAGS_RELEASE 254*a466cc55SCy Schubert CMAKE_C_FLAGS_MINSIZEREL 255*a466cc55SCy Schubert CMAKE_C_FLAGS_RELWITHDEBINFO 256*a466cc55SCy Schubert ) 257*a466cc55SCy Schubert if (${flag_var} MATCHES "/MD") 258*a466cc55SCy Schubert string(REGEX REPLACE "/MD" "/MT" ${flag_var} "${${flag_var}}") 259*a466cc55SCy Schubert endif() 260*a466cc55SCy Schubert endforeach() 261*a466cc55SCy Schubert endif() 262*a466cc55SCy Schubertendif() 263*a466cc55SCy Schubert 264*a466cc55SCy Schubert# GNUC specific options. 265*a466cc55SCy Schubertif (${GNUC}) 266*a466cc55SCy Schubert option(EVENT__DISABLE_GCC_WARNINGS "Disable verbose warnings with GCC" OFF) 267*a466cc55SCy Schubert option(EVENT__ENABLE_GCC_HARDENING "Enable compiler security checks" OFF) 268*a466cc55SCy Schubert option(EVENT__ENABLE_GCC_FUNCTION_SECTIONS "Enable gcc function sections" OFF) 269*a466cc55SCy Schubert option(EVENT__ENABLE_GCC_WARNINGS "Make all GCC warnings into errors" OFF) 270*a466cc55SCy Schubert 271*a466cc55SCy Schubert set(GCC_V ${CMAKE_C_COMPILER_VERSION}) 272*a466cc55SCy Schubert 273*a466cc55SCy Schubert list(APPEND __FLAGS 274*a466cc55SCy Schubert -Wall -Wextra -Wno-unused-parameter -Wstrict-aliasing -Wstrict-prototypes 275*a466cc55SCy Schubert 276*a466cc55SCy Schubert -fno-strict-aliasing # gcc 2.9.5+ 277*a466cc55SCy Schubert -Wmissing-prototypes 278*a466cc55SCy Schubert 279*a466cc55SCy Schubert # gcc 4 280*a466cc55SCy Schubert -Winit-self 281*a466cc55SCy Schubert -Wmissing-field-initializers 282*a466cc55SCy Schubert -Wdeclaration-after-statement 283*a466cc55SCy Schubert 284*a466cc55SCy Schubert # gcc 4.2 285*a466cc55SCy Schubert -Waddress 286*a466cc55SCy Schubert -Wnormalized=id 287*a466cc55SCy Schubert -Woverride-init 288*a466cc55SCy Schubert 289*a466cc55SCy Schubert # gcc 4.5 290*a466cc55SCy Schubert -Wlogical-op 291*a466cc55SCy Schubert 292*a466cc55SCy Schubert -Wwrite-strings 293*a466cc55SCy Schubert ) 294*a466cc55SCy Schubert 295*a466cc55SCy Schubert if (${CLANG}) 296*a466cc55SCy Schubert list(APPEND __FLAGS -Wno-unused-function) 297*a466cc55SCy Schubert endif() 298*a466cc55SCy Schubert 299*a466cc55SCy Schubert if (EVENT__DISABLE_GCC_WARNINGS) 300*a466cc55SCy Schubert list(APPEND __FLAGS -w) 301*a466cc55SCy Schubert endif() 302*a466cc55SCy Schubert 303*a466cc55SCy Schubert if (EVENT__ENABLE_GCC_HARDENING) 304*a466cc55SCy Schubert list(APPEND __FLAGS 305*a466cc55SCy Schubert -fstack-protector-all 306*a466cc55SCy Schubert -fwrapv 307*a466cc55SCy Schubert -fPIE 308*a466cc55SCy Schubert -Wstack-protector 309*a466cc55SCy Schubert "--param ssp-buffer-size=1") 310*a466cc55SCy Schubert 311*a466cc55SCy Schubert add_definitions(-D_FORTIFY_SOURCE=2) 312*a466cc55SCy Schubert endif() 313*a466cc55SCy Schubert 314*a466cc55SCy Schubert if (EVENT__ENABLE_GCC_FUNCTION_SECTIONS) 315*a466cc55SCy Schubert list(APPEND __FLAGS -ffunction-sections) 316*a466cc55SCy Schubert # TODO: Add --gc-sections support. We need some checks for NetBSD to ensure this works. 317*a466cc55SCy Schubert endif() 318*a466cc55SCy Schubert 319*a466cc55SCy Schubert if (EVENT__ENABLE_GCC_WARNINGS) 320*a466cc55SCy Schubert list(APPEND __FLAGS -Werror) 321*a466cc55SCy Schubert endif() 322*a466cc55SCy Schubert 323*a466cc55SCy Schubert add_compiler_flags(${__FLAGS}) 324*a466cc55SCy Schubertendif() 325*a466cc55SCy Schubert 326*a466cc55SCy Schubertif (APPLE) 327*a466cc55SCy Schubert # Get rid of deprecated warnings for OpenSSL on OSX 10.7 and greater. 328*a466cc55SCy Schubert add_compiler_flags( 329*a466cc55SCy Schubert -Wno-error=deprecated-declarations 330*a466cc55SCy Schubert -Qunused-arguments 331*a466cc55SCy Schubert ) 332*a466cc55SCy Schubertendif() 333*a466cc55SCy Schubert 334*a466cc55SCy Schubertif (MINGW OR CYGWIN) 335*a466cc55SCy Schubert set(WIN32 TRUE) 336*a466cc55SCy Schubertendif() 337*a466cc55SCy Schubert 338*a466cc55SCy Schubert# Winsock. 339*a466cc55SCy Schubertif(WIN32) 340*a466cc55SCy Schubert set(CMAKE_REQUIRED_LIBRARIES ws2_32 shell32 advapi32) 341*a466cc55SCy Schubert set(CMAKE_REQUIRED_DEFINITIONS -FIwinsock2.h -FIws2tcpip.h -D_WIN32_WINNT=0x0600) 342*a466cc55SCy Schubertendif() 343*a466cc55SCy Schubertif (SOLARIS) 344*a466cc55SCy Schubert set(CMAKE_REQUIRED_LIBRARIES socket nsl) 345*a466cc55SCy Schubertendif() 346*a466cc55SCy Schubert 347*a466cc55SCy Schubert# Check if _GNU_SOURCE is available. 348*a466cc55SCy Schubertif (NOT DEFINED _GNU_SOURCE) 349*a466cc55SCy Schubert CHECK_SYMBOL_EXISTS(__GNU_LIBRARY__ "features.h" _GNU_SOURCE) 350*a466cc55SCy Schubert 351*a466cc55SCy Schubert if (NOT _GNU_SOURCE) 352*a466cc55SCy Schubert unset(_GNU_SOURCE CACHE) 353*a466cc55SCy Schubert CHECK_SYMBOL_EXISTS(_GNU_SOURCE "features.h" _GNU_SOURCE) 354*a466cc55SCy Schubert endif() 355*a466cc55SCy Schubert 356*a466cc55SCy Schubert if (ANDROID) 357*a466cc55SCy Schubert set(_GNU_SOURCE TRUE) 358*a466cc55SCy Schubert endif() 359*a466cc55SCy Schubertendif() 360*a466cc55SCy Schubert 361*a466cc55SCy Schubertif (_GNU_SOURCE) 362*a466cc55SCy Schubert add_definitions(-D_GNU_SOURCE=1) 363*a466cc55SCy Schubert set(CMAKE_REQUIRED_DEFINITIONS -D_GNU_SOURCE) 364*a466cc55SCy Schubertendif() 365*a466cc55SCy Schubert 366*a466cc55SCy Schubert# Check if header files exist 367*a466cc55SCy Schubertlist(APPEND FILES_TO_CHECK 368*a466cc55SCy Schubert fcntl.h 369*a466cc55SCy Schubert inttypes.h 370*a466cc55SCy Schubert memory.h 371*a466cc55SCy Schubert signal.h 372*a466cc55SCy Schubert stdarg.h 373*a466cc55SCy Schubert stddef.h 374*a466cc55SCy Schubert stdint.h 375*a466cc55SCy Schubert stdlib.h 376*a466cc55SCy Schubert string.h 377*a466cc55SCy Schubert errno.h 378*a466cc55SCy Schubert unistd.h 379*a466cc55SCy Schubert time.h 380*a466cc55SCy Schubert sys/types.h 381*a466cc55SCy Schubert sys/stat.h 382*a466cc55SCy Schubert sys/time.h 383*a466cc55SCy Schubert sys/param.h 384*a466cc55SCy Schubert) 385*a466cc55SCy Schubertif (WIN32) 386*a466cc55SCy Schubert list(APPEND FILES_TO_CHECK 387*a466cc55SCy Schubert io.h 388*a466cc55SCy Schubert winsock2.h 389*a466cc55SCy Schubert ws2tcpip.h 390*a466cc55SCy Schubert afunix.h 391*a466cc55SCy Schubert ) 392*a466cc55SCy Schubertelse() 393*a466cc55SCy Schubert list(APPEND FILES_TO_CHECK 394*a466cc55SCy Schubert netdb.h 395*a466cc55SCy Schubert dlfcn.h 396*a466cc55SCy Schubert arpa/inet.h 397*a466cc55SCy Schubert poll.h 398*a466cc55SCy Schubert port.h 399*a466cc55SCy Schubert sys/socket.h 400*a466cc55SCy Schubert sys/random.h 401*a466cc55SCy Schubert sys/un.h 402*a466cc55SCy Schubert sys/devpoll.h 403*a466cc55SCy Schubert sys/epoll.h 404*a466cc55SCy Schubert sys/eventfd.h 405*a466cc55SCy Schubert sys/event.h 406*a466cc55SCy Schubert sys/ioctl.h 407*a466cc55SCy Schubert sys/mman.h 408*a466cc55SCy Schubert sys/queue.h 409*a466cc55SCy Schubert sys/select.h 410*a466cc55SCy Schubert sys/sendfile.h 411*a466cc55SCy Schubert sys/uio.h 412*a466cc55SCy Schubert sys/wait.h 413*a466cc55SCy Schubert sys/resource.h 414*a466cc55SCy Schubert sys/timerfd.h 415*a466cc55SCy Schubert netinet/in.h 416*a466cc55SCy Schubert netinet/in6.h 417*a466cc55SCy Schubert netinet/tcp.h 418*a466cc55SCy Schubert ifaddrs.h 419*a466cc55SCy Schubert ) 420*a466cc55SCy Schubertendif() 421*a466cc55SCy Schubert 422*a466cc55SCy Schubertif (NOT "${CMAKE_HOST_SYSTEM_NAME}" STREQUAL "Linux") 423*a466cc55SCy Schubert list(APPEND FILES_TO_CHECK sys/sysctl.h) 424*a466cc55SCy Schubertendif() 425*a466cc55SCy Schubert 426*a466cc55SCy Schubertif (APPLE) 427*a466cc55SCy Schubert list(APPEND FILES_TO_CHECK 428*a466cc55SCy Schubert mach/mach_time.h 429*a466cc55SCy Schubert mach/mach.h 430*a466cc55SCy Schubert ) 431*a466cc55SCy Schubertendif() 432*a466cc55SCy Schubert 433*a466cc55SCy Schubertforeach(FILE ${FILES_TO_CHECK}) 434*a466cc55SCy Schubert CHECK_INCLUDE_FILE_CONCAT(${FILE} "EVENT") 435*a466cc55SCy Schubertendforeach() 436*a466cc55SCy Schubertunset(FILES_TO_CHECK) 437*a466cc55SCy Schubert 438*a466cc55SCy Schubert# Check if functions exist 439*a466cc55SCy Schubertlist(APPEND SYMBOLS_TO_CHECK 440*a466cc55SCy Schubert getaddrinfo 441*a466cc55SCy Schubert getnameinfo 442*a466cc55SCy Schubert getprotobynumber 443*a466cc55SCy Schubert getservbyname 444*a466cc55SCy Schubert gethostbyname 445*a466cc55SCy Schubert inet_ntop 446*a466cc55SCy Schubert inet_pton 447*a466cc55SCy Schubert gettimeofday 448*a466cc55SCy Schubert signal 449*a466cc55SCy Schubert strtoll 450*a466cc55SCy Schubert splice 451*a466cc55SCy Schubert strlcpy 452*a466cc55SCy Schubert strsep 453*a466cc55SCy Schubert strtok_r 454*a466cc55SCy Schubert vasprintf 455*a466cc55SCy Schubert timerclear 456*a466cc55SCy Schubert timercmp 457*a466cc55SCy Schubert timerisset 458*a466cc55SCy Schubert timeradd 459*a466cc55SCy Schubert nanosleep 460*a466cc55SCy Schubert putenv 461*a466cc55SCy Schubert umask 462*a466cc55SCy Schubert) 463*a466cc55SCy Schubertif (NOT EVENT__DISABLE_CLOCK_GETTIME) 464*a466cc55SCy Schubert list(APPEND SYMBOLS_TO_CHECK clock_gettime) 465*a466cc55SCy Schubertendif() 466*a466cc55SCy Schubert 467*a466cc55SCy Schubertif (WIN32) 468*a466cc55SCy Schubert list(APPEND SYMBOLS_TO_CHECK 469*a466cc55SCy Schubert _gmtime64_s 470*a466cc55SCy Schubert _gmtime64 471*a466cc55SCy Schubert ) 472*a466cc55SCy Schubertelse() 473*a466cc55SCy Schubert list(APPEND SYMBOLS_TO_CHECK 474*a466cc55SCy Schubert getifaddrs 475*a466cc55SCy Schubert select 476*a466cc55SCy Schubert epoll_create 477*a466cc55SCy Schubert epoll_create1 478*a466cc55SCy Schubert epoll_ctl 479*a466cc55SCy Schubert eventfd 480*a466cc55SCy Schubert poll 481*a466cc55SCy Schubert port_create 482*a466cc55SCy Schubert kqueue 483*a466cc55SCy Schubert fcntl 484*a466cc55SCy Schubert mmap 485*a466cc55SCy Schubert pipe 486*a466cc55SCy Schubert pipe2 487*a466cc55SCy Schubert sendfile 488*a466cc55SCy Schubert sigaction 489*a466cc55SCy Schubert strsignal 490*a466cc55SCy Schubert sysctl 491*a466cc55SCy Schubert accept4 492*a466cc55SCy Schubert arc4random 493*a466cc55SCy Schubert arc4random_buf 494*a466cc55SCy Schubert arc4random_addrandom 495*a466cc55SCy Schubert getrandom 496*a466cc55SCy Schubert getegid 497*a466cc55SCy Schubert geteuid 498*a466cc55SCy Schubert issetugid 499*a466cc55SCy Schubert usleep 500*a466cc55SCy Schubert timerfd_create 501*a466cc55SCy Schubert setenv 502*a466cc55SCy Schubert unsetenv 503*a466cc55SCy Schubert setrlimit 504*a466cc55SCy Schubert gethostbyname_r 505*a466cc55SCy Schubert ) 506*a466cc55SCy Schubert if (APPLE) 507*a466cc55SCy Schubert list(APPEND SYMBOLS_TO_CHECK mach_absolute_time) 508*a466cc55SCy Schubert endif() 509*a466cc55SCy Schubertendif() 510*a466cc55SCy Schubert 511*a466cc55SCy Schubert# Add stdio.h for vasprintf 512*a466cc55SCy Schubertset(EVENT_INCLUDES ${EVENT_INCLUDES} stdio.h) 513*a466cc55SCy SchubertCHECK_SYMBOLS_EXIST("${SYMBOLS_TO_CHECK}" "${EVENT_INCLUDES}" "EVENT") 514*a466cc55SCy Schubertunset(SYMBOLS_TO_CHECK) 515*a466cc55SCy Schubertset(EVENT__HAVE_EPOLL ${EVENT__HAVE_EPOLL_CREATE}) 516*a466cc55SCy Schubert 517*a466cc55SCy Schubert# Get the gethostbyname_r prototype. 518*a466cc55SCy Schubertif(EVENT__HAVE_GETHOSTBYNAME_R) 519*a466cc55SCy Schubert CHECK_PROTOTYPE_DEFINITION(gethostbyname_r 520*a466cc55SCy Schubert "int gethostbyname_r(const char *name, struct hostent *hp, struct hostent_data *hdata)" 521*a466cc55SCy Schubert "0" 522*a466cc55SCy Schubert "netdb.h" 523*a466cc55SCy Schubert EVENT__HAVE_GETHOSTBYNAME_R_3_ARG) 524*a466cc55SCy Schubert 525*a466cc55SCy Schubert CHECK_PROTOTYPE_DEFINITION(gethostbyname_r 526*a466cc55SCy Schubert "struct hostent *gethostbyname_r(const char *name, struct hostent *hp, char *buf, size_t buflen, int *herr)" 527*a466cc55SCy Schubert "NULL" 528*a466cc55SCy Schubert "netdb.h" 529*a466cc55SCy Schubert EVENT__HAVE_GETHOSTBYNAME_R_5_ARG) 530*a466cc55SCy Schubert 531*a466cc55SCy Schubert CHECK_PROTOTYPE_DEFINITION(gethostbyname_r 532*a466cc55SCy Schubert "int gethostbyname_r(const char *name, struct hostent *hp, char *buf, size_t buflen, struct hostent **result, int *herr)" 533*a466cc55SCy Schubert "0" 534*a466cc55SCy Schubert "netdb.h" 535*a466cc55SCy Schubert EVENT__HAVE_GETHOSTBYNAME_R_6_ARG) 536*a466cc55SCy Schubertendif() 537*a466cc55SCy Schubert 538*a466cc55SCy Schubertif(HAVE_PORT_H AND HAVE_PORT_CREATE) 539*a466cc55SCy Schubert set(EVENT__HAVE_EVENT_PORTS 1) 540*a466cc55SCy Schubertendif() 541*a466cc55SCy Schubert 542*a466cc55SCy Schubert# Only `CHECK_TYPE_SIZE()' will use `CMAKE_EXTRA_INCLUDE_FILES' 543*a466cc55SCy Schubertset(CMAKE_EXTRA_INCLUDE_FILES ${EVENT_INCLUDES}) 544*a466cc55SCy Schubert 545*a466cc55SCy SchubertCHECK_TYPE_SIZE("struct sockaddr_un" EVENT__HAVE_STRUCT_SOCKADDR_UN) 546*a466cc55SCy SchubertCHECK_TYPE_SIZE("uint8_t" EVENT__HAVE_UINT8_T) 547*a466cc55SCy SchubertCHECK_TYPE_SIZE("uint16_t" EVENT__HAVE_UINT16_T) 548*a466cc55SCy SchubertCHECK_TYPE_SIZE("uint32_t" EVENT__HAVE_UINT32_T) 549*a466cc55SCy SchubertCHECK_TYPE_SIZE("uint64_t" EVENT__HAVE_UINT64_T) 550*a466cc55SCy SchubertCHECK_TYPE_SIZE("short" EVENT__SIZEOF_SHORT BUILTIN_TYPES_ONLY) 551*a466cc55SCy SchubertCHECK_TYPE_SIZE("int" EVENT__SIZEOF_INT BUILTIN_TYPES_ONLY) 552*a466cc55SCy SchubertCHECK_TYPE_SIZE("unsigned" EVENT__SIZEOF_UNSIGNED BUILTIN_TYPES_ONLY) 553*a466cc55SCy SchubertCHECK_TYPE_SIZE("unsigned int" EVENT__SIZEOF_UNSIGNED_INT BUILTIN_TYPES_ONLY) 554*a466cc55SCy SchubertCHECK_TYPE_SIZE("long" EVENT__SIZEOF_LONG BUILTIN_TYPES_ONLY) 555*a466cc55SCy SchubertCHECK_TYPE_SIZE("long long" EVENT__SIZEOF_LONG_LONG BUILTIN_TYPES_ONLY) 556*a466cc55SCy Schubert 557*a466cc55SCy Schubertif(WIN32) 558*a466cc55SCy Schubert # These aren't available until Windows Vista. 559*a466cc55SCy Schubert # But you can still link them. They just won't be found when running the exe. 560*a466cc55SCy Schubert set(EVENT__HAVE_INET_NTOP 0) 561*a466cc55SCy Schubert set(EVENT__HAVE_INET_PTON 0) 562*a466cc55SCy Schubertendif() 563*a466cc55SCy Schubert 564*a466cc55SCy Schubert# Check for different inline keyword versions. 565*a466cc55SCy Schubertcheck_function_keywords("inline" "__inline" "__inline__") 566*a466cc55SCy Schubert 567*a466cc55SCy Schubertif (HAVE_INLINE) 568*a466cc55SCy Schubert set(EVENT__inline inline) 569*a466cc55SCy Schubertelseif (HAVE___INLINE) 570*a466cc55SCy Schubert set(EVENT__inline __inline) 571*a466cc55SCy Schubertelseif(HAVE___INLINE__) 572*a466cc55SCy Schubert set(EVENT__inline __inline__) 573*a466cc55SCy Schubertelse() 574*a466cc55SCy Schubert set(EVENT__inline) 575*a466cc55SCy Schubertendif() 576*a466cc55SCy Schubert 577*a466cc55SCy Schubert# __func__/__FUNCTION__ is not a macros in general 578*a466cc55SCy SchubertCHECK_SYMBOL_EXISTS("__func__" "" EVENT__HAVE___func__) 579*a466cc55SCy SchubertCHECK_SYMBOL_EXISTS("__FUNCTION__" "" EVENT__HAVE___FUNCTION__) 580*a466cc55SCy Schubert 581*a466cc55SCy SchubertCHECK_SYMBOL_EXISTS(TAILQ_FOREACH sys/queue.h EVENT__HAVE_TAILQFOREACH) 582*a466cc55SCy SchubertCHECK_CONST_EXISTS(CTL_KERN sys/sysctl.h EVENT__HAVE_DECL_CTL_KERN) 583*a466cc55SCy SchubertCHECK_CONST_EXISTS(KERN_ARND sys/sysctl.h EVENT__HAVE_DECL_KERN_ARND) 584*a466cc55SCy SchubertCHECK_SYMBOL_EXISTS(F_SETFD fcntl.h EVENT__HAVE_SETFD) 585*a466cc55SCy Schubert 586*a466cc55SCy SchubertCHECK_TYPE_SIZE(fd_mask EVENT__HAVE_FD_MASK) 587*a466cc55SCy Schubert 588*a466cc55SCy SchubertCHECK_TYPE_SIZE(size_t EVENT__SIZEOF_SIZE_T) 589*a466cc55SCy Schubertif(NOT EVENT__SIZEOF_SIZE_T) 590*a466cc55SCy Schubert set(EVENT__size_t "unsigned") 591*a466cc55SCy Schubert set(EVENT__SIZEOF_SIZE_T ${EVENT__SIZEOF_UNSIGNED}) 592*a466cc55SCy Schubertelse() 593*a466cc55SCy Schubert set(EVENT__size_t size_t) 594*a466cc55SCy Schubertendif() 595*a466cc55SCy Schubert 596*a466cc55SCy SchubertCHECK_TYPE_SIZE("off_t" EVENT__SIZEOF_OFF_T LANGUAGE C) 597*a466cc55SCy Schubert 598*a466cc55SCy Schubert 599*a466cc55SCy Schubert# XXX we should functionalize these size and type sets. --elley 600*a466cc55SCy Schubert 601*a466cc55SCy Schubert# Winssck. 602*a466cc55SCy Schubertif (_MSC_VER) 603*a466cc55SCy Schubert list(APPEND CMAKE_EXTRA_INCLUDE_FILES BaseTsd.h) 604*a466cc55SCy Schubertendif() 605*a466cc55SCy SchubertCHECK_TYPE_SIZE("ssize_t" EVENT__SIZEOF_SSIZE_T_LOWER LANGUAGE C) 606*a466cc55SCy SchubertCHECK_TYPE_SIZE("SSIZE_T" EVENT__SIZEOF_SSIZE_T_UPPER LANGUAGE C) 607*a466cc55SCy Schubert 608*a466cc55SCy Schubertif (EVENT__SIZEOF_SSIZE_T_LOWER) 609*a466cc55SCy Schubert set(EVENT__ssize_t "ssize_t") 610*a466cc55SCy Schubert set(EVENT__SIZEOF_SSIZE_T ${EVENT__SIZEOF_SSIZE_T_LOWER}) 611*a466cc55SCy Schubertelseif (EVENT__SIZEOF_SSIZE_T_UPPER) 612*a466cc55SCy Schubert set(EVENT__ssize_t "SSIZE_T") 613*a466cc55SCy Schubert set(EVENT__SIZEOF_SSIZE_T ${EVENT__SIZEOF_SSIZE_T_UPPER}) 614*a466cc55SCy Schubertelse() 615*a466cc55SCy Schubert set(EVENT__ssize_t "int") 616*a466cc55SCy Schubert set(EVENT__SIZEOF_SSIZE_T ${EVENT__SIZEOF_INT}) 617*a466cc55SCy Schubertendif() 618*a466cc55SCy Schubert 619*a466cc55SCy SchubertCHECK_TYPE_SIZE(socklen_t EVENT__SIZEOF_SOCKLEN_T) 620*a466cc55SCy Schubertif(NOT EVENT__SIZEOF_SOCKLEN_T) 621*a466cc55SCy Schubert set(EVENT__socklen_t "unsigned int") 622*a466cc55SCy Schubert set(EVENT__SIZEOF_SOCKLEN_T ${EVENT__SIZEOF_UNSIGNED_INT}) 623*a466cc55SCy Schubertelse() 624*a466cc55SCy Schubert set(EVENT__socklen_t "socklen_t") 625*a466cc55SCy Schubertendif() 626*a466cc55SCy Schubert 627*a466cc55SCy SchubertCHECK_TYPE_SIZE(pid_t EVENT__SIZEOF_PID_T) 628*a466cc55SCy Schubertif(NOT EVENT__SIZEOF_PID_T) 629*a466cc55SCy Schubert set(EVENT__SIZEOF_PID_T ${EVENT__SIZEOF_INT}) 630*a466cc55SCy Schubertelse() 631*a466cc55SCy Schubert set(EVENT__SIZEOF_PID_T EVENT__SIZEOF_PID_T) 632*a466cc55SCy Schubertendif() 633*a466cc55SCy Schubert 634*a466cc55SCy Schubertif (NOT EVENT__DISABLE_THREAD_SUPPORT) 635*a466cc55SCy Schubert if (NOT WIN32) 636*a466cc55SCy Schubert list(APPEND CMAKE_EXTRA_INCLUDE_FILES pthread.h) 637*a466cc55SCy Schubert endif() 638*a466cc55SCy Schubert CHECK_TYPE_SIZE(pthread_t EVENT__SIZEOF_PTHREAD_T) 639*a466cc55SCy Schubertendif() 640*a466cc55SCy Schubert 641*a466cc55SCy Schubertif(EVENT__HAVE_CLOCK_GETTIME) 642*a466cc55SCy Schubert set(EVENT__DNS_USE_CPU_CLOCK_FOR_ID 1) 643*a466cc55SCy Schubertendif() 644*a466cc55SCy Schubert 645*a466cc55SCy Schubert# we're just getting lazy now. 646*a466cc55SCy SchubertCHECK_TYPE_SIZE("uintptr_t" EVENT__HAVE_UINTPTR_T) 647*a466cc55SCy SchubertCHECK_TYPE_SIZE("void *" EVENT__SIZEOF_VOID_P) 648*a466cc55SCy SchubertCHECK_TYPE_SIZE("time_t" EVENT__SIZEOF_TIME_T) 649*a466cc55SCy Schubert 650*a466cc55SCy Schubert# Tests file offset bits. 651*a466cc55SCy Schubert# TODO: Add AIX test for if -D_LARGE_FILES is needed. 652*a466cc55SCy Schubert 653*a466cc55SCy Schubert# XXX: Why is this here? we don't even use it. Well, we don't even use it 654*a466cc55SCy Schubert# on top of that, why is it set in the config.h?! IT_MAKES_NO_SENSE 655*a466cc55SCy Schubert# I'm commenting it out for now. 656*a466cc55SCy Schubert# - ellzey 657*a466cc55SCy Schubert 658*a466cc55SCy Schubert#CHECK_FILE_OFFSET_BITS() 659*a466cc55SCy Schubert 660*a466cc55SCy Schubert# Verify kqueue works with pipes. 661*a466cc55SCy Schubertif (EVENT__HAVE_KQUEUE) 662*a466cc55SCy Schubert if ((CMAKE_CROSSCOMPILING OR APPLE) AND NOT EVENT__FORCE_KQUEUE_CHECK) 663*a466cc55SCy Schubert 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)") 664*a466cc55SCy Schubert set(EVENT__HAVE_WORKING_KQUEUE 1) 665*a466cc55SCy Schubert else() 666*a466cc55SCy Schubert message(STATUS "Checking if kqueue works with pipes...") 667*a466cc55SCy Schubert include(CheckWorkingKqueue) 668*a466cc55SCy Schubert endif() 669*a466cc55SCy Schubertendif() 670*a466cc55SCy Schubert 671*a466cc55SCy Schubertif(EVENT__HAVE_NETDB_H) 672*a466cc55SCy Schubert list(APPEND CMAKE_EXTRA_INCLUDE_FILES netdb.h) 673*a466cc55SCy Schubert CHECK_TYPE_SIZE("struct addrinfo" EVENT__HAVE_STRUCT_ADDRINFO) 674*a466cc55SCy Schubertelseif(WIN32) 675*a466cc55SCy Schubert list(APPEND CMAKE_EXTRA_INCLUDE_FILES ws2tcpip.h) 676*a466cc55SCy Schubert CHECK_TYPE_SIZE("struct addrinfo" EVENT__HAVE_STRUCT_ADDRINFO) 677*a466cc55SCy Schubertendif() 678*a466cc55SCy Schubert 679*a466cc55SCy Schubert# Check for sockaddr structure sizes. 680*a466cc55SCy Schubertset(SOCKADDR_HEADERS) 681*a466cc55SCy Schubertif (WIN32) 682*a466cc55SCy Schubert set(CMAKE_REQUIRED_DEFINITIONS "-DWIN32_LEAN_AND_MEAN") 683*a466cc55SCy Schubert if (_MSC_VER LESS 1300) 684*a466cc55SCy Schubert set(SOCKADDR_HEADERS winsock.h) 685*a466cc55SCy Schubert else() 686*a466cc55SCy Schubert set(SOCKADDR_HEADERS winsock2.h ws2tcpip.h) 687*a466cc55SCy Schubert endif() 688*a466cc55SCy Schubertelse() 689*a466cc55SCy Schubert if (EVENT__HAVE_NETINET_IN_H) 690*a466cc55SCy Schubert set(SOCKADDR_HEADERS ${SOCKADDR_HEADERS} netinet/in.h) 691*a466cc55SCy Schubert endif() 692*a466cc55SCy Schubert 693*a466cc55SCy Schubert if (EVENT__HAVE_NETINET_IN6_H) 694*a466cc55SCy Schubert set(SOCKADDR_HEADERS ${SOCKADDR_HEADERS} netinet/in6.h) 695*a466cc55SCy Schubert endif() 696*a466cc55SCy Schubert 697*a466cc55SCy Schubert if (EVENT__HAVE_SYS_SOCKET_H) 698*a466cc55SCy Schubert set(SOCKADDR_HEADERS ${SOCKADDR_HEADERS} sys/socket.h) 699*a466cc55SCy Schubert endif() 700*a466cc55SCy Schubert 701*a466cc55SCy Schubert if (EVENT__HAVE_NETDB_H) 702*a466cc55SCy Schubert set(SOCKADDR_HEADERS ${SOCKADDR_HEADERS} netdb.h) 703*a466cc55SCy Schubert endif() 704*a466cc55SCy Schubertendif() 705*a466cc55SCy Schubert 706*a466cc55SCy SchubertCHECK_TYPE_SIZE("struct in6_addr" EVENT__HAVE_STRUCT_IN6_ADDR) 707*a466cc55SCy Schubertif(EVENT__HAVE_STRUCT_IN6_ADDR) 708*a466cc55SCy Schubert CHECK_STRUCT_HAS_MEMBER("struct in6_addr" 709*a466cc55SCy Schubert s6_addr16 "${SOCKADDR_HEADERS}" 710*a466cc55SCy Schubert EVENT__HAVE_STRUCT_IN6_ADDR_S6_ADDR16) 711*a466cc55SCy Schubert 712*a466cc55SCy Schubert CHECK_STRUCT_HAS_MEMBER("struct in6_addr" 713*a466cc55SCy Schubert s6_addr32 "${SOCKADDR_HEADERS}" 714*a466cc55SCy Schubert EVENT__HAVE_STRUCT_IN6_ADDR_S6_ADDR32) 715*a466cc55SCy Schubertendif() 716*a466cc55SCy Schubert 717*a466cc55SCy SchubertCHECK_TYPE_SIZE("sa_family_t" EVENT__HAVE_SA_FAMILY_T) 718*a466cc55SCy SchubertCHECK_TYPE_SIZE("struct sockaddr_in6" EVENT__HAVE_STRUCT_SOCKADDR_IN6) 719*a466cc55SCy Schubert 720*a466cc55SCy Schubertif(EVENT__HAVE_STRUCT_SOCKADDR_IN6) 721*a466cc55SCy Schubert CHECK_STRUCT_HAS_MEMBER("struct sockaddr_in6" 722*a466cc55SCy Schubert sin6_len "${SOCKADDR_HEADERS}" 723*a466cc55SCy Schubert EVENT__HAVE_STRUCT_SOCKADDR_IN6_SIN6_LEN) 724*a466cc55SCy Schubert 725*a466cc55SCy Schubert CHECK_STRUCT_HAS_MEMBER("struct sockaddr_in6" 726*a466cc55SCy Schubert sin_len "${SOCKADDR_HEADERS}" 727*a466cc55SCy Schubert EVENT__HAVE_STRUCT_SOCKADDR_IN_SIN_LEN) 728*a466cc55SCy Schubertendif() 729*a466cc55SCy Schubert 730*a466cc55SCy SchubertCHECK_TYPE_SIZE("struct sockaddr_storage" EVENT__HAVE_STRUCT_SOCKADDR_STORAGE) 731*a466cc55SCy Schubertif(EVENT__HAVE_STRUCT_SOCKADDR_STORAGE) 732*a466cc55SCy Schubert CHECK_STRUCT_HAS_MEMBER("struct sockaddr_storage" 733*a466cc55SCy Schubert ss_family "${SOCKADDR_HEADERS}" 734*a466cc55SCy Schubert EVENT__HAVE_STRUCT_SOCKADDR_STORAGE_SS_FAMILY) 735*a466cc55SCy Schubert 736*a466cc55SCy Schubert CHECK_STRUCT_HAS_MEMBER("struct sockaddr_storage" 737*a466cc55SCy Schubert __ss_family "${SOCKADDR_HEADERS}" EVENT__HAVE_STRUCT_SOCKADDR_STORAGE___SS_FAMILY) 738*a466cc55SCy Schubertendif() 739*a466cc55SCy Schubert 740*a466cc55SCy SchubertCHECK_TYPE_SIZE("struct linger" EVENT__HAVE_STRUCT_LINGER) 741*a466cc55SCy Schubert 742*a466cc55SCy Schubert# Group the source files. 743*a466cc55SCy Schubertset(HDR_PRIVATE 744*a466cc55SCy Schubert bufferevent-internal.h 745*a466cc55SCy Schubert changelist-internal.h 746*a466cc55SCy Schubert defer-internal.h 747*a466cc55SCy Schubert epolltable-internal.h 748*a466cc55SCy Schubert evbuffer-internal.h 749*a466cc55SCy Schubert event-internal.h 750*a466cc55SCy Schubert evmap-internal.h 751*a466cc55SCy Schubert evrpc-internal.h 752*a466cc55SCy Schubert evsignal-internal.h 753*a466cc55SCy Schubert evthread-internal.h 754*a466cc55SCy Schubert ht-internal.h 755*a466cc55SCy Schubert http-internal.h 756*a466cc55SCy Schubert iocp-internal.h 757*a466cc55SCy Schubert ipv6-internal.h 758*a466cc55SCy Schubert log-internal.h 759*a466cc55SCy Schubert minheap-internal.h 760*a466cc55SCy Schubert mm-internal.h 761*a466cc55SCy Schubert ratelim-internal.h 762*a466cc55SCy Schubert strlcpy-internal.h 763*a466cc55SCy Schubert util-internal.h 764*a466cc55SCy Schubert evconfig-private.h 765*a466cc55SCy Schubert compat/sys/queue.h) 766*a466cc55SCy Schubert 767*a466cc55SCy Schubertset(HDR_COMPAT 768*a466cc55SCy Schubert include/evdns.h 769*a466cc55SCy Schubert include/evrpc.h 770*a466cc55SCy Schubert include/event.h 771*a466cc55SCy Schubert include/evhttp.h 772*a466cc55SCy Schubert include/evutil.h) 773*a466cc55SCy Schubert 774*a466cc55SCy Schubertset(HDR_PUBLIC 775*a466cc55SCy Schubert include/event2/buffer.h 776*a466cc55SCy Schubert include/event2/bufferevent.h 777*a466cc55SCy Schubert include/event2/bufferevent_compat.h 778*a466cc55SCy Schubert include/event2/bufferevent_struct.h 779*a466cc55SCy Schubert include/event2/buffer_compat.h 780*a466cc55SCy Schubert include/event2/dns.h 781*a466cc55SCy Schubert include/event2/dns_compat.h 782*a466cc55SCy Schubert include/event2/dns_struct.h 783*a466cc55SCy Schubert include/event2/event.h 784*a466cc55SCy Schubert include/event2/event_compat.h 785*a466cc55SCy Schubert include/event2/event_struct.h 786*a466cc55SCy Schubert include/event2/http.h 787*a466cc55SCy Schubert include/event2/http_compat.h 788*a466cc55SCy Schubert include/event2/http_struct.h 789*a466cc55SCy Schubert include/event2/keyvalq_struct.h 790*a466cc55SCy Schubert include/event2/listener.h 791*a466cc55SCy Schubert include/event2/rpc.h 792*a466cc55SCy Schubert include/event2/rpc_compat.h 793*a466cc55SCy Schubert include/event2/rpc_struct.h 794*a466cc55SCy Schubert include/event2/tag.h 795*a466cc55SCy Schubert include/event2/tag_compat.h 796*a466cc55SCy Schubert include/event2/thread.h 797*a466cc55SCy Schubert include/event2/util.h 798*a466cc55SCy Schubert include/event2/visibility.h 799*a466cc55SCy Schubert ${PROJECT_BINARY_DIR}/include/event2/event-config.h) 800*a466cc55SCy Schubert 801*a466cc55SCy Schubertset(SRC_CORE 802*a466cc55SCy Schubert buffer.c 803*a466cc55SCy Schubert bufferevent.c 804*a466cc55SCy Schubert bufferevent_filter.c 805*a466cc55SCy Schubert bufferevent_pair.c 806*a466cc55SCy Schubert bufferevent_ratelim.c 807*a466cc55SCy Schubert bufferevent_sock.c 808*a466cc55SCy Schubert event.c 809*a466cc55SCy Schubert evmap.c 810*a466cc55SCy Schubert evthread.c 811*a466cc55SCy Schubert evutil.c 812*a466cc55SCy Schubert evutil_rand.c 813*a466cc55SCy Schubert evutil_time.c 814*a466cc55SCy Schubert listener.c 815*a466cc55SCy Schubert log.c 816*a466cc55SCy Schubert signal.c 817*a466cc55SCy Schubert strlcpy.c) 818*a466cc55SCy Schubert 819*a466cc55SCy Schubertif(EVENT__HAVE_SELECT) 820*a466cc55SCy Schubert list(APPEND SRC_CORE select.c) 821*a466cc55SCy Schubertendif() 822*a466cc55SCy Schubert 823*a466cc55SCy Schubertif(EVENT__HAVE_POLL) 824*a466cc55SCy Schubert list(APPEND SRC_CORE poll.c) 825*a466cc55SCy Schubertendif() 826*a466cc55SCy Schubert 827*a466cc55SCy Schubertif(EVENT__HAVE_KQUEUE) 828*a466cc55SCy Schubert list(APPEND SRC_CORE kqueue.c) 829*a466cc55SCy Schubertendif() 830*a466cc55SCy Schubert 831*a466cc55SCy Schubertif(EVENT__HAVE_DEVPOLL) 832*a466cc55SCy Schubert list(APPEND SRC_CORE devpoll.c) 833*a466cc55SCy Schubertendif() 834*a466cc55SCy Schubert 835*a466cc55SCy Schubertif(EVENT__HAVE_EPOLL) 836*a466cc55SCy Schubert list(APPEND SRC_CORE epoll.c) 837*a466cc55SCy Schubertendif() 838*a466cc55SCy Schubert 839*a466cc55SCy Schubertif(EVENT__HAVE_EVENT_PORTS) 840*a466cc55SCy Schubert list(APPEND SRC_CORE evport.c) 841*a466cc55SCy Schubertendif() 842*a466cc55SCy Schubert 843*a466cc55SCy Schubertif (NOT EVENT__DISABLE_OPENSSL) 844*a466cc55SCy Schubert find_package(OpenSSL REQUIRED) 845*a466cc55SCy Schubert 846*a466cc55SCy Schubert set(EVENT__HAVE_OPENSSL 1) 847*a466cc55SCy Schubert 848*a466cc55SCy Schubert message(STATUS "OpenSSL include: ${OPENSSL_INCLUDE_DIR}") 849*a466cc55SCy Schubert message(STATUS "OpenSSL lib: ${OPENSSL_LIBRARIES}") 850*a466cc55SCy Schubert 851*a466cc55SCy Schubert include_directories(${OPENSSL_INCLUDE_DIR}) 852*a466cc55SCy Schubert 853*a466cc55SCy Schubert list(APPEND SRC_OPENSSL bufferevent_openssl.c) 854*a466cc55SCy Schubert list(APPEND HDR_PUBLIC include/event2/bufferevent_ssl.h) 855*a466cc55SCy Schubert list(APPEND LIB_APPS ${OPENSSL_LIBRARIES}) 856*a466cc55SCy Schubertendif() 857*a466cc55SCy Schubert 858*a466cc55SCy Schubertif (NOT EVENT__DISABLE_THREAD_SUPPORT) 859*a466cc55SCy Schubert if (WIN32) 860*a466cc55SCy Schubert list(APPEND SRC_CORE evthread_win32.c) 861*a466cc55SCy Schubert else() 862*a466cc55SCy Schubert find_package(Threads REQUIRED) 863*a466cc55SCy Schubert if (NOT CMAKE_USE_PTHREADS_INIT) 864*a466cc55SCy Schubert message(FATAL_ERROR 865*a466cc55SCy Schubert "Failed to find Pthreads, set EVENT__DISABLE_THREAD_SUPPORT to disable") 866*a466cc55SCy Schubert endif() 867*a466cc55SCy Schubert 868*a466cc55SCy Schubert set(EVENT__HAVE_PTHREADS 1) 869*a466cc55SCy Schubert list(APPEND LIB_APPS ${CMAKE_THREAD_LIBS_INIT}) 870*a466cc55SCy Schubert endif() 871*a466cc55SCy Schubertendif() 872*a466cc55SCy Schubert 873*a466cc55SCy Schubertif (NOT EVENT__DISABLE_TESTS) 874*a466cc55SCy Schubert # Zlib is only used for testing. 875*a466cc55SCy Schubert find_package(ZLIB) 876*a466cc55SCy Schubert 877*a466cc55SCy Schubert if (ZLIB_LIBRARY AND ZLIB_INCLUDE_DIR) 878*a466cc55SCy Schubert include_directories(${ZLIB_INCLUDE_DIRS}) 879*a466cc55SCy Schubert 880*a466cc55SCy Schubert set(EVENT__HAVE_LIBZ 1) 881*a466cc55SCy Schubert list(APPEND LIB_APPS ${ZLIB_LIBRARIES}) 882*a466cc55SCy Schubert endif() 883*a466cc55SCy Schubertendif() 884*a466cc55SCy Schubert 885*a466cc55SCy Schubertset(SRC_EXTRA 886*a466cc55SCy Schubert event_tagging.c 887*a466cc55SCy Schubert http.c 888*a466cc55SCy Schubert evdns.c 889*a466cc55SCy Schubert evrpc.c) 890*a466cc55SCy Schubert 891*a466cc55SCy Schubertadd_definitions(-DHAVE_CONFIG_H) 892*a466cc55SCy Schubert 893*a466cc55SCy Schubert# We use BEFORE here so we don't accidentally look in system directories 894*a466cc55SCy Schubert# first for some previous versions of the headers that are installed. 895*a466cc55SCy Schubertinclude_directories(BEFORE ${PROJECT_SOURCE_DIR} 896*a466cc55SCy Schubert ${PROJECT_SOURCE_DIR}/compat 897*a466cc55SCy Schubert ${PROJECT_SOURCE_DIR}/include) 898*a466cc55SCy Schubert 899*a466cc55SCy Schubertif(WIN32) 900*a466cc55SCy Schubert list(APPEND SRC_CORE 901*a466cc55SCy Schubert buffer_iocp.c 902*a466cc55SCy Schubert bufferevent_async.c 903*a466cc55SCy Schubert event_iocp.c 904*a466cc55SCy Schubert win32select.c) 905*a466cc55SCy Schubert 906*a466cc55SCy Schubert list(APPEND HDR_PRIVATE WIN32-Code/getopt.h) 907*a466cc55SCy Schubert 908*a466cc55SCy Schubert set(EVENT__DNS_USE_FTIME_FOR_ID 1) 909*a466cc55SCy Schubert set(LIB_PLATFORM ws2_32 shell32 advapi32) 910*a466cc55SCy Schubert add_definitions( 911*a466cc55SCy Schubert -D_CRT_SECURE_NO_WARNINGS 912*a466cc55SCy Schubert -D_CRT_NONSTDC_NO_DEPRECATE) 913*a466cc55SCy Schubert 914*a466cc55SCy Schubert include_directories(./WIN32-Code) 915*a466cc55SCy Schubertendif() 916*a466cc55SCy Schubert 917*a466cc55SCy Schubertif (SOLARIS) 918*a466cc55SCy Schubert list(APPEND LIB_PLATFORM socket nsl) 919*a466cc55SCy Schubertendif() 920*a466cc55SCy Schubert 921*a466cc55SCy Schubertsource_group("Headers Private" FILES ${HDR_PRIVATE}) 922*a466cc55SCy Schubertsource_group("Header Compat" FILES ${HDR_COMPAT}) 923*a466cc55SCy Schubertsource_group("Headers Public" FILES ${HDR_PUBLIC}) 924*a466cc55SCy Schubertsource_group("Source Core" FILES ${SRC_CORE}) 925*a466cc55SCy Schubertsource_group("Source Extra" FILES ${SRC_EXTRA}) 926*a466cc55SCy Schubert 927*a466cc55SCy Schubert# Generate the configure headers. 928*a466cc55SCy Schubert# (Place them in the build dir so we don't polute the source tree with generated files). 929*a466cc55SCy Schubertinclude_directories(BEFORE ${CMAKE_CURRENT_BINARY_DIR}/include) 930*a466cc55SCy Schubert 931*a466cc55SCy Schubertif (${GNUC}) 932*a466cc55SCy Schubert set(EVENT_SHARED_FLAGS -fvisibility=hidden) 933*a466cc55SCy Schubertelseif ("${CMAKE_C_COMPILER_ID}" STREQUAL "SunPro") 934*a466cc55SCy Schubert set(EVENT_SHARED_FLAGS -xldscope=hidden) 935*a466cc55SCy Schubertendif() 936*a466cc55SCy Schubert 937*a466cc55SCy Schubertconfigure_file( 938*a466cc55SCy Schubert ${CMAKE_CURRENT_SOURCE_DIR}/event-config.h.cmake 939*a466cc55SCy Schubert ${CMAKE_CURRENT_BINARY_DIR}/include/event2/event-config.h 940*a466cc55SCy Schubert NEWLINE_STYLE UNIX) 941*a466cc55SCy Schubert 942*a466cc55SCy Schubertconfigure_file( 943*a466cc55SCy Schubert ${CMAKE_CURRENT_SOURCE_DIR}/evconfig-private.h.cmake 944*a466cc55SCy Schubert ${CMAKE_CURRENT_BINARY_DIR}/include/evconfig-private.h) 945*a466cc55SCy Schubert 946*a466cc55SCy Schubert# 947*a466cc55SCy Schubert# Create the libraries. 948*a466cc55SCy Schubert# 949*a466cc55SCy Schubertinclude(AddEventLibrary) 950*a466cc55SCy Schubertadd_event_library(event_core SOURCES ${SRC_CORE}) 951*a466cc55SCy Schubertadd_event_library(event_extra 952*a466cc55SCy Schubert INNER_LIBRARIES event_core 953*a466cc55SCy Schubert SOURCES ${SRC_EXTRA}) 954*a466cc55SCy Schubert 955*a466cc55SCy Schubertif (NOT EVENT__DISABLE_OPENSSL) 956*a466cc55SCy Schubert add_event_library(event_openssl 957*a466cc55SCy Schubert INNER_LIBRARIES event_core 958*a466cc55SCy Schubert OUTER_INCLUDES ${OPENSSL_INCLUDE_DIR} 959*a466cc55SCy Schubert LIBRARIES ${OPENSSL_LIBRARIES} 960*a466cc55SCy Schubert SOURCES ${SRC_OPENSSL}) 961*a466cc55SCy Schubertendif() 962*a466cc55SCy Schubert 963*a466cc55SCy Schubertif (EVENT__HAVE_PTHREADS) 964*a466cc55SCy Schubert set(SRC_PTHREADS evthread_pthread.c) 965*a466cc55SCy Schubert add_event_library(event_pthreads 966*a466cc55SCy Schubert INNER_LIBRARIES event_core 967*a466cc55SCy Schubert SOURCES ${SRC_PTHREADS}) 968*a466cc55SCy Schubertendif() 969*a466cc55SCy Schubert 970*a466cc55SCy Schubert# library exists for historical reasons; it contains the contents of 971*a466cc55SCy Schubert# both libevent_core and libevent_extra. You shouldn’t use it; it may 972*a466cc55SCy Schubert# go away in a future version of Libevent. 973*a466cc55SCy Schubertadd_event_library(event SOURCES ${SRC_CORE} ${SRC_EXTRA}) 974*a466cc55SCy Schubert 975*a466cc55SCy Schubertset(WIN32_GETOPT) 976*a466cc55SCy Schubertif (WIN32) 977*a466cc55SCy Schubert set(_TMPLIBS) 978*a466cc55SCy Schubert if (${EVENT_LIBRARY_STATIC}) 979*a466cc55SCy Schubert list(APPEND _TMPLIBS event_core_static event_static) 980*a466cc55SCy Schubert endif() 981*a466cc55SCy Schubert if (${EVENT_LIBRARY_SHARED}) 982*a466cc55SCy Schubert list(APPEND _TMPLIBS event_core_shared event_shared) 983*a466cc55SCy Schubert endif() 984*a466cc55SCy Schubert foreach(lib ${_TMPLIBS}) 985*a466cc55SCy Schubert target_link_libraries(${lib} iphlpapi) 986*a466cc55SCy Schubert endforeach() 987*a466cc55SCy Schubert unset(_TMPLIBS) 988*a466cc55SCy Schubert 989*a466cc55SCy Schubert list(APPEND WIN32_GETOPT 990*a466cc55SCy Schubert WIN32-Code/getopt.c 991*a466cc55SCy Schubert WIN32-Code/getopt_long.c) 992*a466cc55SCy Schubertendif() 993*a466cc55SCy Schubert 994*a466cc55SCy Schubert# 995*a466cc55SCy Schubert# Samples. 996*a466cc55SCy Schubert# 997*a466cc55SCy Schubertmacro(add_sample_prog ssl name) 998*a466cc55SCy Schubert add_executable(${name} ${ARGN}) 999*a466cc55SCy Schubert 1000*a466cc55SCy Schubert target_link_libraries(${name} 1001*a466cc55SCy Schubert event_extra 1002*a466cc55SCy Schubert event_core 1003*a466cc55SCy Schubert ${LIB_APPS} 1004*a466cc55SCy Schubert ${LIB_PLATFORM}) 1005*a466cc55SCy Schubert 1006*a466cc55SCy Schubert if (${ssl}) 1007*a466cc55SCy Schubert target_link_libraries(${name} event_openssl) 1008*a466cc55SCy Schubert if(WIN32) 1009*a466cc55SCy Schubert target_link_libraries(${name} crypt32) 1010*a466cc55SCy Schubert endif() 1011*a466cc55SCy Schubert endif() 1012*a466cc55SCy Schubertendmacro() 1013*a466cc55SCy Schubertif (NOT EVENT__DISABLE_SAMPLES) 1014*a466cc55SCy Schubert set(SAMPLES 1015*a466cc55SCy Schubert event-read-fifo 1016*a466cc55SCy Schubert hello-world 1017*a466cc55SCy Schubert signal-test 1018*a466cc55SCy Schubert http-connect 1019*a466cc55SCy Schubert time-test) 1020*a466cc55SCy Schubert 1021*a466cc55SCy Schubert foreach(SAMPLE ${SAMPLES}) 1022*a466cc55SCy Schubert add_sample_prog(OFF ${SAMPLE} sample/${SAMPLE}.c) 1023*a466cc55SCy Schubert endforeach() 1024*a466cc55SCy Schubert 1025*a466cc55SCy Schubert if (NOT EVENT__DISABLE_OPENSSL) 1026*a466cc55SCy Schubert add_sample_prog(ON https-client 1027*a466cc55SCy Schubert sample/https-client.c 1028*a466cc55SCy Schubert sample/openssl_hostname_validation.c 1029*a466cc55SCy Schubert sample/hostcheck.c) 1030*a466cc55SCy Schubert add_sample_prog(ON le-proxy 1031*a466cc55SCy Schubert sample/le-proxy.c) 1032*a466cc55SCy Schubert endif() 1033*a466cc55SCy Schubert 1034*a466cc55SCy Schubert set(SAMPLES_WOPT 1035*a466cc55SCy Schubert dns-example 1036*a466cc55SCy Schubert http-server 1037*a466cc55SCy Schubert ) 1038*a466cc55SCy Schubert foreach (SAMPLE ${SAMPLES_WOPT}) 1039*a466cc55SCy Schubert add_sample_prog(OFF ${SAMPLE} sample/${SAMPLE}.c ${WIN32_GETOPT}) 1040*a466cc55SCy Schubert endforeach() 1041*a466cc55SCy Schubertendif() 1042*a466cc55SCy Schubert 1043*a466cc55SCy Schubert# 1044*a466cc55SCy Schubert# Benchmarks 1045*a466cc55SCy Schubert# 1046*a466cc55SCy Schubertmacro(add_bench_prog prog) 1047*a466cc55SCy Schubert add_executable(${prog} ${ARGN}) 1048*a466cc55SCy Schubert target_link_libraries(${prog} 1049*a466cc55SCy Schubert event_extra 1050*a466cc55SCy Schubert event_core 1051*a466cc55SCy Schubert ${LIB_APPS} 1052*a466cc55SCy Schubert ${LIB_PLATFORM}) 1053*a466cc55SCy Schubertendmacro() 1054*a466cc55SCy Schubertif (NOT EVENT__DISABLE_BENCHMARK) 1055*a466cc55SCy Schubert foreach (BENCHMARK bench_http bench_httpclient) 1056*a466cc55SCy Schubert add_bench_prog(${BENCHMARK} test/${BENCHMARK}.c) 1057*a466cc55SCy Schubert endforeach() 1058*a466cc55SCy Schubert 1059*a466cc55SCy Schubert add_bench_prog(bench test/bench.c ${WIN32_GETOPT}) 1060*a466cc55SCy Schubert add_bench_prog(bench_cascade test/bench_cascade.c ${WIN32_GETOPT}) 1061*a466cc55SCy Schubertendif() 1062*a466cc55SCy Schubert 1063*a466cc55SCy Schubert# 1064*a466cc55SCy Schubert# Tests 1065*a466cc55SCy Schubert# 1066*a466cc55SCy Schubertmacro(add_test_prog prog) 1067*a466cc55SCy Schubert add_executable(${prog} test/${prog}.c) 1068*a466cc55SCy Schubert target_link_libraries(${prog} 1069*a466cc55SCy Schubert ${LIB_APPS} 1070*a466cc55SCy Schubert ${LIB_PLATFORM} 1071*a466cc55SCy Schubert event_core 1072*a466cc55SCy Schubert event_extra 1073*a466cc55SCy Schubert ${ARGN}) 1074*a466cc55SCy Schubertendmacro() 1075*a466cc55SCy Schubertif (NOT EVENT__DISABLE_TESTS) 1076*a466cc55SCy Schubert # 1077*a466cc55SCy Schubert # Generate Regress tests. 1078*a466cc55SCy Schubert # 1079*a466cc55SCy Schubert if (NOT EVENT__DISABLE_REGRESS) 1080*a466cc55SCy Schubert # (We require python to generate the regress tests) 1081*a466cc55SCy Schubert find_package(PythonInterp 3) 1082*a466cc55SCy Schubert 1083*a466cc55SCy Schubert if (PYTHONINTERP_FOUND) 1084*a466cc55SCy Schubert set(__FOUND_USABLE_PYTHON 1) 1085*a466cc55SCy Schubert else() 1086*a466cc55SCy Schubert find_package(PythonInterp 2) 1087*a466cc55SCy Schubert if (PYTHONINTERP_FOUND) 1088*a466cc55SCy Schubert set(__FOUND_USABLE_PYTHON 1) 1089*a466cc55SCy Schubert else() 1090*a466cc55SCy Schubert message(ERROR "No suitable Python version found, bailing...") 1091*a466cc55SCy Schubert endif() 1092*a466cc55SCy Schubert endif() 1093*a466cc55SCy Schubert 1094*a466cc55SCy Schubert if (__FOUND_USABLE_PYTHON) 1095*a466cc55SCy Schubert message(STATUS "Generating regress tests...") 1096*a466cc55SCy Schubert 1097*a466cc55SCy Schubert add_definitions(-DTINYTEST_LOCAL) 1098*a466cc55SCy Schubert 1099*a466cc55SCy Schubert add_custom_command( 1100*a466cc55SCy Schubert OUTPUT 1101*a466cc55SCy Schubert ${CMAKE_CURRENT_SOURCE_DIR}/test/regress.gen.c 1102*a466cc55SCy Schubert ${CMAKE_CURRENT_SOURCE_DIR}/test/regress.gen.h 1103*a466cc55SCy Schubert DEPENDS 1104*a466cc55SCy Schubert event_rpcgen.py 1105*a466cc55SCy Schubert test/regress.rpc 1106*a466cc55SCy Schubert COMMAND ${PYTHON_EXECUTABLE} ../event_rpcgen.py --quiet regress.rpc 1107*a466cc55SCy Schubert WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/test) 1108*a466cc55SCy Schubert 1109*a466cc55SCy Schubert list(APPEND SRC_REGRESS 1110*a466cc55SCy Schubert test/regress.c 1111*a466cc55SCy Schubert test/regress.gen.c 1112*a466cc55SCy Schubert test/regress.gen.h 1113*a466cc55SCy Schubert test/regress_buffer.c 1114*a466cc55SCy Schubert test/regress_bufferevent.c 1115*a466cc55SCy Schubert test/regress_dns.c 1116*a466cc55SCy Schubert test/regress_et.c 1117*a466cc55SCy Schubert test/regress_finalize.c 1118*a466cc55SCy Schubert test/regress_http.c 1119*a466cc55SCy Schubert test/regress_listener.c 1120*a466cc55SCy Schubert test/regress_main.c 1121*a466cc55SCy Schubert test/regress_minheap.c 1122*a466cc55SCy Schubert test/regress_rpc.c 1123*a466cc55SCy Schubert test/regress_testutils.c 1124*a466cc55SCy Schubert test/regress_testutils.h 1125*a466cc55SCy Schubert test/regress_util.c 1126*a466cc55SCy Schubert test/tinytest.c) 1127*a466cc55SCy Schubert 1128*a466cc55SCy Schubert if (WIN32) 1129*a466cc55SCy Schubert list(APPEND SRC_REGRESS test/regress_iocp.c) 1130*a466cc55SCy Schubert if (NOT EVENT__DISABLE_THREAD_SUPPORT) 1131*a466cc55SCy Schubert list(APPEND SRC_REGRESS test/regress_thread.c) 1132*a466cc55SCy Schubert endif() 1133*a466cc55SCy Schubert elseif (EVENT__HAVE_PTHREADS) 1134*a466cc55SCy Schubert list(APPEND SRC_REGRESS test/regress_thread.c) 1135*a466cc55SCy Schubert endif() 1136*a466cc55SCy Schubert 1137*a466cc55SCy Schubert if (ZLIB_LIBRARY AND ZLIB_INCLUDE_DIR) 1138*a466cc55SCy Schubert list(APPEND SRC_REGRESS test/regress_zlib.c) 1139*a466cc55SCy Schubert endif() 1140*a466cc55SCy Schubert 1141*a466cc55SCy Schubert if (NOT EVENT__DISABLE_OPENSSL) 1142*a466cc55SCy Schubert list(APPEND SRC_REGRESS test/regress_ssl.c) 1143*a466cc55SCy Schubert endif() 1144*a466cc55SCy Schubert 1145*a466cc55SCy Schubert add_executable(regress ${SRC_REGRESS}) 1146*a466cc55SCy Schubert 1147*a466cc55SCy Schubert target_link_libraries(regress 1148*a466cc55SCy Schubert ${LIB_APPS} 1149*a466cc55SCy Schubert ${LIB_PLATFORM} 1150*a466cc55SCy Schubert event_core 1151*a466cc55SCy Schubert event_extra) 1152*a466cc55SCy Schubert if (NOT EVENT__DISABLE_OPENSSL) 1153*a466cc55SCy Schubert target_link_libraries(regress event_openssl) 1154*a466cc55SCy Schubert endif() 1155*a466cc55SCy Schubert if (CMAKE_USE_PTHREADS_INIT) 1156*a466cc55SCy Schubert target_link_libraries(regress event_pthreads) 1157*a466cc55SCy Schubert endif() 1158*a466cc55SCy Schubert else() 1159*a466cc55SCy Schubert message(WARNING "No suitable Python interpreter found, cannot generate regress tests!") 1160*a466cc55SCy Schubert endif() 1161*a466cc55SCy Schubert endif() 1162*a466cc55SCy Schubert 1163*a466cc55SCy Schubert # 1164*a466cc55SCy Schubert # Test programs. 1165*a466cc55SCy Schubert # 1166*a466cc55SCy Schubert # all of these, including the cmakelists.txt should be moved 1167*a466cc55SCy Schubert # into the dirctory 'tests' first. 1168*a466cc55SCy Schubert # 1169*a466cc55SCy Schubert # doing this, we can remove all the DISABLE_TESTS stuff, and simply 1170*a466cc55SCy Schubert # do something like: 1171*a466cc55SCy Schubert # 1172*a466cc55SCy Schubert # add_custom_targets(tests) 1173*a466cc55SCy Schubert # add_executable(... EXCLUDE_FROM_ALL ...c) 1174*a466cc55SCy Schubert # add_dependencis(tests testa testb testc) 1175*a466cc55SCy Schubert # add_test(....) 1176*a466cc55SCy Schubert # 1177*a466cc55SCy Schubert # then you can just run 'make tests' instead of them all 1178*a466cc55SCy Schubert # auto-compile|running 1179*a466cc55SCy Schubert # - ellzey 1180*a466cc55SCy Schubert set(TESTPROGS test-changelist 1181*a466cc55SCy Schubert test-eof 1182*a466cc55SCy Schubert test-closed 1183*a466cc55SCy Schubert test-fdleak 1184*a466cc55SCy Schubert test-init 1185*a466cc55SCy Schubert test-time 1186*a466cc55SCy Schubert test-weof) 1187*a466cc55SCy Schubert 1188*a466cc55SCy Schubert foreach (TESTPROG ${TESTPROGS} test-dumpevents) 1189*a466cc55SCy Schubert add_test_prog(${TESTPROG}) 1190*a466cc55SCy Schubert endforeach() 1191*a466cc55SCy Schubert if (UNIX) 1192*a466cc55SCy Schubert add_test_prog(test-ratelim m) 1193*a466cc55SCy Schubert else() 1194*a466cc55SCy Schubert add_test_prog(test-ratelim) 1195*a466cc55SCy Schubert endif() 1196*a466cc55SCy Schubert 1197*a466cc55SCy Schubert set(ALL_TESTPROGS 1198*a466cc55SCy Schubert ${TESTPROGS} 1199*a466cc55SCy Schubert test-dumpevents 1200*a466cc55SCy Schubert test-ratelim 1201*a466cc55SCy Schubert ) 1202*a466cc55SCy Schubert 1203*a466cc55SCy Schubert # 1204*a466cc55SCy Schubert # We run all tests with the different backends turned on one at a time. 1205*a466cc55SCy Schubert # 1206*a466cc55SCy Schubert 1207*a466cc55SCy Schubert # Add event backends based on system introspection result. 1208*a466cc55SCy Schubert set(BACKENDS "") 1209*a466cc55SCy Schubert 1210*a466cc55SCy Schubert if (EVENT__HAVE_EPOLL) 1211*a466cc55SCy Schubert list(APPEND BACKENDS EPOLL) 1212*a466cc55SCy Schubert endif() 1213*a466cc55SCy Schubert 1214*a466cc55SCy Schubert if (EVENT__HAVE_SELECT) 1215*a466cc55SCy Schubert list(APPEND BACKENDS SELECT) 1216*a466cc55SCy Schubert endif() 1217*a466cc55SCy Schubert 1218*a466cc55SCy Schubert if (EVENT__HAVE_POLL) 1219*a466cc55SCy Schubert list(APPEND BACKENDS POLL) 1220*a466cc55SCy Schubert endif() 1221*a466cc55SCy Schubert 1222*a466cc55SCy Schubert if (EVENT__HAVE_KQUEUE) 1223*a466cc55SCy Schubert list(APPEND BACKENDS KQUEUE) 1224*a466cc55SCy Schubert endif() 1225*a466cc55SCy Schubert 1226*a466cc55SCy Schubert if (EVENT__HAVE_EVENT_PORTS) 1227*a466cc55SCy Schubert list(APPEND BACKENDS EVPORT) 1228*a466cc55SCy Schubert endif() 1229*a466cc55SCy Schubert 1230*a466cc55SCy Schubert if (EVENT__HAVE_DEVPOLL) 1231*a466cc55SCy Schubert list(APPEND BACKENDS DEVPOLL) 1232*a466cc55SCy Schubert endif() 1233*a466cc55SCy Schubert 1234*a466cc55SCy Schubert if (WIN32) 1235*a466cc55SCy Schubert list(APPEND BACKENDS WIN32) 1236*a466cc55SCy Schubert endif() 1237*a466cc55SCy Schubert 1238*a466cc55SCy Schubert 1239*a466cc55SCy Schubert # Default environment variables turns off all event systems, 1240*a466cc55SCy Schubert # then we enable each one, one at a time when creating the tests. 1241*a466cc55SCy Schubert set(DEFAULT_TEST_ENV_VARS) 1242*a466cc55SCy Schubert foreach(BACKEND ${BACKENDS}) 1243*a466cc55SCy Schubert set(BACKEND_ENV_VAR "EVENT_NO${BACKEND}=1") 1244*a466cc55SCy Schubert list(APPEND DEFAULT_TEST_ENV_VARS "${BACKEND_ENV_VAR}") 1245*a466cc55SCy Schubert endforeach() 1246*a466cc55SCy Schubert 1247*a466cc55SCy Schubert # Macro that creates the ctest test for a backend. 1248*a466cc55SCy Schubert macro(add_backend_test BACKEND_TEST_NAME ENV_VARS) 1249*a466cc55SCy Schubert set(TEST_NAMES "") 1250*a466cc55SCy Schubert 1251*a466cc55SCy Schubert foreach (TESTPROG ${TESTPROGS}) 1252*a466cc55SCy Schubert set(TEST_NAME ${TESTPROG}__${BACKEND_TEST_NAME}) 1253*a466cc55SCy Schubert 1254*a466cc55SCy Schubert add_test(${TEST_NAME} 1255*a466cc55SCy Schubert ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${TESTPROG}) 1256*a466cc55SCy Schubert 1257*a466cc55SCy Schubert list(APPEND TEST_NAMES ${TEST_NAME}) 1258*a466cc55SCy Schubert 1259*a466cc55SCy Schubert set_tests_properties(${TEST_NAME} 1260*a466cc55SCy Schubert PROPERTIES ENVIRONMENT "${ENV_VARS}") 1261*a466cc55SCy Schubert endforeach() 1262*a466cc55SCy Schubert 1263*a466cc55SCy Schubert # Dump events test. 1264*a466cc55SCy Schubert if (__FOUND_USABLE_PYTHON) 1265*a466cc55SCy Schubert set(TEST_NAME test-dumpevents__${BACKEND_TEST_NAME}) 1266*a466cc55SCy Schubert 1267*a466cc55SCy Schubert add_test(${TEST_NAME} 1268*a466cc55SCy Schubert ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/test-dumpevents | 1269*a466cc55SCy Schubert ${PYTHON_EXECUTABLE} 1270*a466cc55SCy Schubert ${CMAKE_CURRENT_SOURCE_DIR}/test/check-dumpevents.py) 1271*a466cc55SCy Schubert 1272*a466cc55SCy Schubert set_tests_properties(${TEST_NAME} 1273*a466cc55SCy Schubert PROPERTIES ENVIRONMENT "${ENV_VARS}") 1274*a466cc55SCy Schubert else() 1275*a466cc55SCy Schubert message(WARNING "test-dumpevents will be run without output check since python was not found!") 1276*a466cc55SCy Schubert set(TEST_NAME test-dumpevents__${BACKEND_TEST_NAME}_no_check) 1277*a466cc55SCy Schubert 1278*a466cc55SCy Schubert add_test(${TEST_NAME} 1279*a466cc55SCy Schubert ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/test-dumpevents) 1280*a466cc55SCy Schubert 1281*a466cc55SCy Schubert set_tests_properties(${TEST_NAME} 1282*a466cc55SCy Schubert PROPERTIES ENVIRONMENT "${ENV_VARS}") 1283*a466cc55SCy Schubert endif() 1284*a466cc55SCy Schubert 1285*a466cc55SCy Schubert # Regress tests. 1286*a466cc55SCy Schubert if (NOT EVENT__DISABLE_REGRESS AND __FOUND_USABLE_PYTHON) 1287*a466cc55SCy Schubert set(TEST_NAME regress__${BACKEND_TEST_NAME}) 1288*a466cc55SCy Schubert 1289*a466cc55SCy Schubert add_test(${TEST_NAME} 1290*a466cc55SCy Schubert ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/regress --quiet) 1291*a466cc55SCy Schubert 1292*a466cc55SCy Schubert set_tests_properties(${TEST_NAME} 1293*a466cc55SCy Schubert PROPERTIES ENVIRONMENT "${ENV_VARS}") 1294*a466cc55SCy Schubert 1295*a466cc55SCy Schubert add_test(${TEST_NAME}_debug 1296*a466cc55SCy Schubert ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/regress --quiet) 1297*a466cc55SCy Schubert 1298*a466cc55SCy Schubert set_tests_properties(${TEST_NAME}_debug 1299*a466cc55SCy Schubert PROPERTIES ENVIRONMENT "${ENV_VARS};EVENT_DEBUG_MODE=1") 1300*a466cc55SCy Schubert endif() 1301*a466cc55SCy Schubert endmacro() 1302*a466cc55SCy Schubert 1303*a466cc55SCy Schubert # Add the tests for each backend. 1304*a466cc55SCy Schubert foreach(BACKEND ${BACKENDS}) 1305*a466cc55SCy Schubert # Enable this backend only. 1306*a466cc55SCy Schubert set(BACKEND_ENV_VARS ${DEFAULT_TEST_ENV_VARS}) 1307*a466cc55SCy Schubert list(REMOVE_ITEM BACKEND_ENV_VARS EVENT_NO${BACKEND}=1) 1308*a466cc55SCy Schubert 1309*a466cc55SCy Schubert # Epoll has some extra settings. 1310*a466cc55SCy Schubert if (${BACKEND} STREQUAL "EPOLL") 1311*a466cc55SCy Schubert add_backend_test(timerfd_${BACKEND} 1312*a466cc55SCy Schubert "${BACKEND_ENV_VARS};EVENT_PRECISE_TIMER=1") 1313*a466cc55SCy Schubert 1314*a466cc55SCy Schubert add_backend_test(changelist_${BACKEND} 1315*a466cc55SCy Schubert "${BACKEND_ENV_VARS};EVENT_EPOLL_USE_CHANGELIST=yes") 1316*a466cc55SCy Schubert 1317*a466cc55SCy Schubert add_backend_test(timerfd_changelist_${BACKEND} 1318*a466cc55SCy Schubert "${BACKEND_ENV_VARS};EVENT_EPOLL_USE_CHANGELIST=yes;EVENT_PRECISE_TIMER=1") 1319*a466cc55SCy Schubert else() 1320*a466cc55SCy Schubert add_backend_test(${BACKEND} "${BACKEND_ENV_VARS}") 1321*a466cc55SCy Schubert endif() 1322*a466cc55SCy Schubert endforeach() 1323*a466cc55SCy Schubert 1324*a466cc55SCy Schubert # 1325*a466cc55SCy Schubert # Rate limiter tests. 1326*a466cc55SCy Schubert # 1327*a466cc55SCy Schubert 1328*a466cc55SCy Schubert # Group limits, no connection limit. 1329*a466cc55SCy Schubert set(RL_BIN ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/test-ratelim) 1330*a466cc55SCy Schubert 1331*a466cc55SCy Schubert add_test(test-ratelim__group_lim 1332*a466cc55SCy Schubert ${RL_BIN} 1333*a466cc55SCy Schubert -g 30000 1334*a466cc55SCy Schubert -n 30 1335*a466cc55SCy Schubert -t 100 1336*a466cc55SCy Schubert --check-grouplimit 1000 1337*a466cc55SCy Schubert --check-stddev 100) 1338*a466cc55SCy Schubert 1339*a466cc55SCy Schubert # Connection limit, no group limit. 1340*a466cc55SCy Schubert add_test(test-ratelim__con_lim 1341*a466cc55SCy Schubert ${RL_BIN} 1342*a466cc55SCy Schubert -c 1000 1343*a466cc55SCy Schubert -n 30 1344*a466cc55SCy Schubert -t 100 1345*a466cc55SCy Schubert --check-connlimit 50 1346*a466cc55SCy Schubert --check-stddev 50) 1347*a466cc55SCy Schubert 1348*a466cc55SCy Schubert # Connection limit and group limit. 1349*a466cc55SCy Schubert add_test(test-ratelim__group_con_lim 1350*a466cc55SCy Schubert ${RL_BIN} 1351*a466cc55SCy Schubert -c 1000 1352*a466cc55SCy Schubert -g 30000 1353*a466cc55SCy Schubert -n 30 1354*a466cc55SCy Schubert -t 100 1355*a466cc55SCy Schubert --check-grouplimit 1000 1356*a466cc55SCy Schubert --check-connlimit 50 1357*a466cc55SCy Schubert --check-stddev 50) 1358*a466cc55SCy Schubert 1359*a466cc55SCy Schubert # Connection limit and group limit with independent drain. 1360*a466cc55SCy Schubert add_test(test-ratelim__group_con_lim_drain 1361*a466cc55SCy Schubert ${RL_BIN} 1362*a466cc55SCy Schubert -c 1000 1363*a466cc55SCy Schubert -g 35000 1364*a466cc55SCy Schubert -n 30 1365*a466cc55SCy Schubert -t 100 1366*a466cc55SCy Schubert -G 500 1367*a466cc55SCy Schubert --check-grouplimit 1000 1368*a466cc55SCy Schubert --check-connlimit 50 1369*a466cc55SCy Schubert --check-stddev 50) 1370*a466cc55SCy Schubert 1371*a466cc55SCy Schubert # Add a "make verify" target, same as for autoconf. 1372*a466cc55SCy Schubert # (Important! This will unset all EVENT_NO* environment variables. 1373*a466cc55SCy Schubert # If they are set in the shell the tests are running using simply "ctest" or "make test" will fail) 1374*a466cc55SCy Schubert if (WIN32) 1375*a466cc55SCy Schubert # Windows doesn't have "unset". But you can use "set VAR=" instead. 1376*a466cc55SCy Schubert # We need to guard against the possibility taht EVENT_NOWIN32 is set, and all test failing 1377*a466cc55SCy Schubert # since no event backend being available. 1378*a466cc55SCy Schubert file(TO_NATIVE_PATH ${CMAKE_CTEST_COMMAND} WINDOWS_CTEST_COMMAND) 1379*a466cc55SCy Schubert 1380*a466cc55SCy Schubert file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/tmp/verify_tests.bat 1381*a466cc55SCy Schubert " 1382*a466cc55SCy Schubert set EVENT_NOWIN32= 1383*a466cc55SCy Schubert \"${WINDOWS_CTEST_COMMAND}\" 1384*a466cc55SCy Schubert ") 1385*a466cc55SCy Schubert 1386*a466cc55SCy Schubert message(STATUS "${WINDOWS_CTEST_COMMAND}") 1387*a466cc55SCy Schubert 1388*a466cc55SCy Schubert file(COPY ${CMAKE_CURRENT_BINARY_DIR}/tmp/verify_tests.bat 1389*a466cc55SCy Schubert DESTINATION ${CMAKE_CURRENT_BINARY_DIR} 1390*a466cc55SCy Schubert FILE_PERMISSIONS 1391*a466cc55SCy Schubert OWNER_READ 1392*a466cc55SCy Schubert OWNER_WRITE 1393*a466cc55SCy Schubert OWNER_EXECUTE 1394*a466cc55SCy Schubert GROUP_READ 1395*a466cc55SCy Schubert GROUP_EXECUTE 1396*a466cc55SCy Schubert WORLD_READ WORLD_EXECUTE) 1397*a466cc55SCy Schubert 1398*a466cc55SCy Schubert file(TO_NATIVE_PATH 1399*a466cc55SCy Schubert "${CMAKE_CURRENT_BINARY_DIR}/verify_tests.bat" VERIFY_PATH) 1400*a466cc55SCy Schubert 1401*a466cc55SCy Schubert add_custom_target(verify COMMAND "${VERIFY_PATH}" 1402*a466cc55SCy Schubert DEPENDS event ${ALL_TESTPROGS}) 1403*a466cc55SCy Schubert else() 1404*a466cc55SCy Schubert # On some platforms doing exec(unset) as CMake does won't work, so make sure 1405*a466cc55SCy Schubert # we run the unset command in a shell instead. 1406*a466cc55SCy Schubert # First we write the script contents. 1407*a466cc55SCy Schubert file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/tmp/verify_tests.sh 1408*a466cc55SCy Schubert " 1409*a466cc55SCy Schubert #!/bin/bash 1410*a466cc55SCy Schubert unset EVENT_NOEPOLL; unset EVENT_NOPOLL; unset EVENT_NOSELECT; unset EVENT_NOWIN32; unset EVENT_NOEVPORT; unset EVENT_NOKQUEUE; unset EVENT_NODEVPOLL 1411*a466cc55SCy Schubert ${CMAKE_CTEST_COMMAND} 1412*a466cc55SCy Schubert ") 1413*a466cc55SCy Schubert 1414*a466cc55SCy Schubert # Then we copy the file (this allows us to set execute permission on it) 1415*a466cc55SCy Schubert file(COPY ${CMAKE_CURRENT_BINARY_DIR}/tmp/verify_tests.sh 1416*a466cc55SCy Schubert DESTINATION ${CMAKE_CURRENT_BINARY_DIR} 1417*a466cc55SCy Schubert FILE_PERMISSIONS 1418*a466cc55SCy Schubert OWNER_READ 1419*a466cc55SCy Schubert OWNER_WRITE 1420*a466cc55SCy Schubert OWNER_EXECUTE 1421*a466cc55SCy Schubert GROUP_READ 1422*a466cc55SCy Schubert GROUP_EXECUTE 1423*a466cc55SCy Schubert WORLD_READ 1424*a466cc55SCy Schubert WORLD_EXECUTE) 1425*a466cc55SCy Schubert 1426*a466cc55SCy Schubert # Create the target that runs the script. 1427*a466cc55SCy Schubert add_custom_target(verify 1428*a466cc55SCy Schubert COMMAND ${CMAKE_CURRENT_BINARY_DIR}/verify_tests.sh 1429*a466cc55SCy Schubert DEPENDS event ${ALL_TESTPROGS}) 1430*a466cc55SCy Schubert endif() 1431*a466cc55SCy Schubert 1432*a466cc55SCy Schubert if (NOT EVENT__DISABLE_REGRESS AND __FOUND_USABLE_PYTHON) 1433*a466cc55SCy Schubert add_dependencies(verify regress) 1434*a466cc55SCy Schubert endif() 1435*a466cc55SCy Schubert 1436*a466cc55SCy Schubert if (EVENT__COVERAGE) 1437*a466cc55SCy Schubert include(CodeCoverage) 1438*a466cc55SCy Schubert 1439*a466cc55SCy Schubert setup_target_for_coverage( 1440*a466cc55SCy Schubert verify_coverage # Coverage target name "make verify_coverage" 1441*a466cc55SCy Schubert make # Test runner. 1442*a466cc55SCy Schubert coverage # Output directory. 1443*a466cc55SCy Schubert verify) # Arguments passed to test runner. "make verify" 1444*a466cc55SCy Schubert endif() 1445*a466cc55SCy Schubert 1446*a466cc55SCy Schubert enable_testing() 1447*a466cc55SCy Schubert 1448*a466cc55SCy Schubert include(CTest) 1449*a466cc55SCy Schubertendif() 1450*a466cc55SCy Schubert 1451*a466cc55SCy Schubert# 1452*a466cc55SCy Schubert# Installation preparation. 1453*a466cc55SCy Schubert# 1454*a466cc55SCy Schubert 1455*a466cc55SCy Schubertset(EVENT_INSTALL_CMAKE_DIR 1456*a466cc55SCy Schubert "${CMAKE_INSTALL_PREFIX}/lib/cmake/libevent") 1457*a466cc55SCy Schubert 1458*a466cc55SCy Schubertexport(PACKAGE libevent) 1459*a466cc55SCy Schubert 1460*a466cc55SCy Schubertfunction(gen_package_config forinstall) 1461*a466cc55SCy Schubert if(${forinstall}) 1462*a466cc55SCy Schubert set(CONFIG_FOR_INSTALL_TREE 1) 1463*a466cc55SCy Schubert set(dir "${PROJECT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}") 1464*a466cc55SCy Schubert else() 1465*a466cc55SCy Schubert set(CONFIG_FOR_INSTALL_TREE 0) 1466*a466cc55SCy Schubert set(dir "${PROJECT_BINARY_DIR}") 1467*a466cc55SCy Schubert endif() 1468*a466cc55SCy Schubert configure_file(${PROJECT_SOURCE_DIR}/cmake/LibeventConfig.cmake.in 1469*a466cc55SCy Schubert "${dir}/LibeventConfig.cmake" 1470*a466cc55SCy Schubert @ONLY) 1471*a466cc55SCy Schubertendfunction() 1472*a466cc55SCy Schubert 1473*a466cc55SCy Schubert# Generate the config file for the build-tree. 1474*a466cc55SCy Schubertset(EVENT__INCLUDE_DIRS 1475*a466cc55SCy Schubert "${PROJECT_SOURCE_DIR}/include" 1476*a466cc55SCy Schubert "${PROJECT_BINARY_DIR}/include") 1477*a466cc55SCy Schubert 1478*a466cc55SCy Schubertset(LIBEVENT_INCLUDE_DIRS 1479*a466cc55SCy Schubert ${EVENT__INCLUDE_DIRS} 1480*a466cc55SCy Schubert CACHE PATH "Libevent include directories") 1481*a466cc55SCy Schubert 1482*a466cc55SCy Schubertgen_package_config(0) 1483*a466cc55SCy Schubert 1484*a466cc55SCy Schubert# Generate the config file for the installation tree. 1485*a466cc55SCy Schubertgen_package_config(1) 1486*a466cc55SCy Schubert 1487*a466cc55SCy Schubert# Generate version info for both build-tree and install-tree. 1488*a466cc55SCy Schubertconfigure_file(${PROJECT_SOURCE_DIR}/cmake/LibeventConfigVersion.cmake.in 1489*a466cc55SCy Schubert ${PROJECT_BINARY_DIR}/LibeventConfigVersion.cmake 1490*a466cc55SCy Schubert @ONLY) 1491*a466cc55SCy Schubert 1492*a466cc55SCy Schubert# Install compat headers 1493*a466cc55SCy Schubertinstall(FILES ${HDR_COMPAT} 1494*a466cc55SCy Schubert DESTINATION "include" 1495*a466cc55SCy Schubert COMPONENT dev) 1496*a466cc55SCy Schubert 1497*a466cc55SCy Schubert# Install public headers 1498*a466cc55SCy Schubertinstall(FILES ${HDR_PUBLIC} 1499*a466cc55SCy Schubert DESTINATION "include/event2" 1500*a466cc55SCy Schubert COMPONENT dev) 1501*a466cc55SCy Schubert 1502*a466cc55SCy Schubert# Install the configs. 1503*a466cc55SCy Schubertinstall(FILES 1504*a466cc55SCy Schubert ${PROJECT_BINARY_DIR}/${CMAKE_FILES_DIRECTORY}/LibeventConfig.cmake 1505*a466cc55SCy Schubert ${PROJECT_BINARY_DIR}/LibeventConfigVersion.cmake 1506*a466cc55SCy Schubert DESTINATION "${EVENT_INSTALL_CMAKE_DIR}" 1507*a466cc55SCy Schubert COMPONENT dev) 1508*a466cc55SCy Schubert 1509*a466cc55SCy Schubert# Install exports for the install-tree. 1510*a466cc55SCy Schubertmacro(install_export type) 1511*a466cc55SCy Schubert install(EXPORT LibeventTargets-${type} 1512*a466cc55SCy Schubert NAMESPACE ${PROJECT_NAME}:: 1513*a466cc55SCy Schubert DESTINATION "${EVENT_INSTALL_CMAKE_DIR}" 1514*a466cc55SCy Schubert COMPONENT dev) 1515*a466cc55SCy Schubertendmacro() 1516*a466cc55SCy Schubert 1517*a466cc55SCy Schubertif (${EVENT_LIBRARY_STATIC}) 1518*a466cc55SCy Schubert install_export(static) 1519*a466cc55SCy Schubertendif() 1520*a466cc55SCy Schubertif (${EVENT_LIBRARY_SHARED}) 1521*a466cc55SCy Schubert install_export(shared) 1522*a466cc55SCy Schubertendif() 1523*a466cc55SCy Schubert 1524*a466cc55SCy Schubert# Install the scripts. 1525*a466cc55SCy Schubertinstall(PROGRAMS 1526*a466cc55SCy Schubert ${CMAKE_CURRENT_SOURCE_DIR}/event_rpcgen.py 1527*a466cc55SCy Schubert DESTINATION "bin" 1528*a466cc55SCy Schubert COMPONENT runtime) 1529*a466cc55SCy Schubert 1530*a466cc55SCy Schubert# Create documents with doxygen. 1531*a466cc55SCy Schubertoption(EVENT__DOXYGEN 1532*a466cc55SCy Schubert "Enables doxygen documentation" OFF) 1533*a466cc55SCy Schubertif (EVENT__DOXYGEN) 1534*a466cc55SCy Schubert include(UseDoxygen) 1535*a466cc55SCy Schubert UseDoxygen() 1536*a466cc55SCy Schubertendif() 1537*a466cc55SCy Schubert 1538*a466cc55SCy Schubert 1539*a466cc55SCy Schubertif (NOT TARGET uninstall) 1540*a466cc55SCy Schubert # Create the uninstall target. 1541*a466cc55SCy Schubert # https://gitlab.kitware.com/cmake/community/wikis/FAQ#can-i-do-make-uninstall-with-cmake 1542*a466cc55SCy Schubert configure_file(${PROJECT_SOURCE_DIR}/cmake/Uninstall.cmake.in 1543*a466cc55SCy Schubert ${PROJECT_BINARY_DIR}/Uninstall.cmake 1544*a466cc55SCy Schubert @ONLY) 1545*a466cc55SCy Schubert 1546*a466cc55SCy Schubert add_custom_target(uninstall 1547*a466cc55SCy Schubert COMMAND ${CMAKE_COMMAND} -P ${PROJECT_BINARY_DIR}/Uninstall.cmake) 1548*a466cc55SCy Schubertendif() 1549*a466cc55SCy Schubert 1550*a466cc55SCy Schubertmessage(STATUS "") 1551*a466cc55SCy Schubertmessage(STATUS " ---( Libevent " ${EVENT_VERSION} " )---") 1552*a466cc55SCy Schubertmessage(STATUS "") 1553*a466cc55SCy Schubertmessage(STATUS "Available event backends: ${BACKENDS}") 1554*a466cc55SCy Schubertmessage(STATUS "CMAKE_BINARY_DIR: ${CMAKE_BINARY_DIR}") 1555*a466cc55SCy Schubertmessage(STATUS "CMAKE_CURRENT_BINARY_DIR: ${CMAKE_CURRENT_BINARY_DIR}") 1556*a466cc55SCy Schubertmessage(STATUS "CMAKE_SOURCE_DIR: ${CMAKE_SOURCE_DIR}") 1557*a466cc55SCy Schubertmessage(STATUS "CMAKE_CURRENT_SOURCE_DIR: ${CMAKE_CURRENT_SOURCE_DIR}") 1558*a466cc55SCy Schubertmessage(STATUS "PROJECT_BINARY_DIR: ${PROJECT_BINARY_DIR}") 1559*a466cc55SCy Schubertmessage(STATUS "PROJECT_SOURCE_DIR: ${PROJECT_SOURCE_DIR}") 1560*a466cc55SCy Schubertmessage(STATUS "CMAKE_MODULE_PATH: ${CMAKE_MODULE_PATH}") 1561*a466cc55SCy Schubertmessage(STATUS "CMAKE_COMMAND: ${CMAKE_COMMAND}") 1562*a466cc55SCy Schubertmessage(STATUS "CMAKE_ROOT: ${CMAKE_ROOT}") 1563*a466cc55SCy Schubertmessage(STATUS "CMAKE_SYSTEM: ${CMAKE_SYSTEM}") 1564*a466cc55SCy Schubertmessage(STATUS "CMAKE_SYSTEM_NAME: ${CMAKE_SYSTEM_NAME}") 1565*a466cc55SCy Schubertmessage(STATUS "CMAKE_SYSTEM_VERSION: ${CMAKE_SYSTEM_VERSION}") 1566*a466cc55SCy Schubertmessage(STATUS "CMAKE_SYSTEM_PROCESSOR: ${CMAKE_SYSTEM_PROCESSOR}") 1567*a466cc55SCy Schubertmessage(STATUS "CMAKE_SKIP_RPATH: ${CMAKE_SKIP_RPATH}") 1568*a466cc55SCy Schubertmessage(STATUS "CMAKE_VERBOSE_MAKEFILE: ${CMAKE_VERBOSE_MAKEFILE}") 1569*a466cc55SCy Schubertmessage(STATUS "CMAKE_C_FLAGS: ${CMAKE_C_FLAGS}") 1570*a466cc55SCy Schubertmessage(STATUS "CMAKE_BUILD_TYPE: ${CMAKE_BUILD_TYPE}") 1571*a466cc55SCy Schubertmessage(STATUS "CMAKE_C_COMPILER: ${CMAKE_C_COMPILER} (id ${CMAKE_C_COMPILER_ID}, clang ${CLANG}, GNUC ${GNUC})") 1572*a466cc55SCy Schubertmessage(STATUS "CMAKE_AR: ${CMAKE_AR}") 1573*a466cc55SCy Schubertmessage(STATUS "CMAKE_RANLIB: ${CMAKE_RANLIB}") 1574*a466cc55SCy Schubertmessage(STATUS "") 1575*a466cc55SCy Schubert 1576