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