214 Commits

Author SHA1 Message Date
Azat Khuzhin
68e18761ae Move find_dependency() directly to LibeventConfig.cmake
Patch-by: @ahuj9
Fixes: https://github.com/libevent/libevent/issues/1711
Follow-up for: https://github.com/libevent/libevent/pull/1544 (cc @kurtlau)
2024-10-03 21:27:17 +02:00
Kirill Rodriguez
ccb18f5b0c fix cmake build error for android: threads not found 2024-09-21 23:39:58 +03:00
Cœur
e5181b153e
Cleanup EVENT_HAVE_ macros (#1645) 2024-06-23 21:37:49 +02:00
Cœur
a0fc31bfe3 Sort symbols to check in cmake/autotools lexicographically 2024-06-02 10:25:55 +03:00
Andy Pan
aef201a9fc
Change ident for EVFILT_USER to 0 and add a test (#1582)
Conventionally, ident for EVFILT_USER is set to 0 to avoid
collision of file descriptors, which is what other renowned
networking frameworks like netty(java), mio(rust), gnet(go),
swift-nio(swift), etc. do currently.

Co-authored-by: Azat Khuzhin <azat@libevent.org>
2024-04-29 07:35:33 +02:00
Cœur
a942694155 Fix CMake Deprecation Warning 2024-04-29 08:17:43 +03:00
Hennadii Stepanov
71d41cdf37 build: Add Iphlpapi to Libs.private in *.pc files on Windows
It has been required since https://github.com/libevent/libevent/pull/923
at least for the `if_nametoindex` call.
2024-04-25 09:44:01 +02:00
Ramon Ortega de Voor
ed35b30feb Fix two compiler errors for unused variable and undefined function
In buffer.c a variable "flags" and a label "done" are defined but
never used if "EVENT__HAVEMMAP" is not defined.

The code does not work on platforms which do not provide
the function `socketpair()`. Introduce EVENT__HAVE_SOCKETPAIR flag
which determines if `socketpair()` or `evutil_ersatz_socketpair()`
is used.
2024-02-19 08:19:24 +01:00
kurtliu
7870e85ecb install DESTINATION use CMAKE_INSTALL_<dir> 2024-01-24 10:20:47 +01:00
kurtlau
b698e6c4b0
Make MbedTLS and OpenSSL dependencies configurable (#1544)
As acfac7a#r124469888 mentioned, LibeventConfig.cmake is looking for MBedTLS package, even if libevent is not configured to use MBedTLS.

This PR makes MbedTLS and OpenSSL dependencies configurable.

Fixes: #1543
2024-01-22 21:29:04 +01:00
Michael Davidsaver
c9ec6aafb6 Update cmake policy wrt. RPATH on OSX
Previous settings caused install outside CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES
to use install_name "lib/" in place of the expected (and useful) "@rpath/".
2023-08-02 21:05:54 +02:00
Michael Davidsaver
3c29a81b8b fixup RPATH computation
Handle cases where ${CMAKE_INSTALL_LIBDIR} is not ${CMAKE_INSTALL_PREFIX}/lib .
Also, preserve user provided ${CMAKE_INSTALL_RPATH} .

fixup for 41a7393f3ecd1e9f58331df4653dac2e6739304e
2023-07-31 10:51:20 +02:00
Azat Khuzhin
57d9eec641 Disable signalfd by default
signalfd may behave differently to sigaction/signal, so to avoid
breaking libevent users (like [1], [2]) disable it by default.

  [1]: https://github.com/tmux/tmux/pull/3621
  [2]: https://github.com/tmux/tmux/pull/3626

Also signalfd is not that perfect:
- you need to SIG_BLOCK the signal before
  - blocked signals are not reset on exec
  - blocked signals are allowed to coalesce - so in case of multiple
    signals sent you may get the signal only once (ok for most of the
    signals, but may be a problem for SIGCHLD, though you may call
    waitpid() in a loop or use pidfd)
- and also one implementation problem -
  sigprocmask is unspecified in a multithreaded process

Refs:
- https://lwn.net/Articles/415684/
- https://ldpreload.com/blog/signalfd-is-useless

Refs: https://github.com/libevent/libevent/issues/1460
Refs: #1342 (cc @dmantipov)
2023-07-13 21:21:09 +02:00
Krzysztof Dynowski
13366d2711 Test timer - synchronize clock before tv_timeout calculation. 2023-06-21 09:47:07 +02:00
Michael Davidsaver
9ce6ae78af Add option to auto-detect OpenSSL and MbedTLS 2023-06-07 11:10:14 -07:00
Azat Khuzhin
283a371f51 cmake: log when CMAKE_DEBUG_POSTFIX/CMAKE_BUILD_TYPE is changed 2023-05-23 21:46:14 +02:00
Daniel Engberg
4effaee523 cmake: Fix .pc files when building in Release mode
Don't define CMAKE_DEBUG_POSTFIX as this breaks Release builds, only apply when doing debug builds.
2023-05-22 08:14:42 +02:00
Azat Khuzhin
1c06b68fee Add a note about the last number in NUMERIC_VERSION 2023-05-21 10:10:18 +02:00
Azat Khuzhin
8d1388a372 Bump version to 2.2.1 2023-05-21 08:47:42 +02:00
Azat Khuzhin
2c2ffb8d6e Revert "cmake: Only use relative paths for install DESTINATION option (#1405)"
After rebasing I broke the initial intention of this patch, so it simply
should be reverted.

This reverts commit 81c6b8823c1b58d7837e827bb1098aa5f9e5956b.
2023-05-20 16:00:44 +02:00
Ingo Bauersachs
acfac7ae4a Make dependency paths relocatable
The generated configurations for both CMake and pkg-config included
absolute paths to dependencies (OpenSSL, MbedTLS). This is contrary
to the general CMake advise to create relocatable packages [1].

Additionally, when building both mbedtls and libevent via CMake's
FetchContent in the same project, loading the project would fail with

  INTERFACE_INCLUDE_DIRECTORIES property contains path:
    "/home/user/project/cmake-build/_deps/mbedtls-build/include"
  which is prefixed in the source directory.

The required changes include:
- Adding the outer includes only to the BUILD_INTERFACE solves the
  makes the CMake paths relocatable and thus solves the FetchContent
  problem.
- Updates to libevent_*.pc.in fixes the relocatable issues for
  pkg-config and properly declares currently missing dependencies.
- Using components for linking to OpenSSL (requiring CMake 3.4)
  and MbedTLS. The new MbedTLS target names now match the component
  names of the MbedTLS' CMake project.
- Use the Threads CMake library reference instead of a direct
  reference to support both built-in pthread and -lpthread.

v2 (azat): get back CMAKE_REQUIRED_LIBRARIES

[1] https://cmake.org/cmake/help/v3.25/manual/cmake-packages.7.html#creating-relocatable-packages
2023-05-16 07:46:56 +02:00
Jeremy W. Murphy
81c6b8823c
cmake: Only use relative paths for install DESTINATION option (#1405)
As described in #1404, the explicit use of CMAKE_INSTALL_PREFIX conflicts with using command-line --prefix.

This simply removes all explicit use of CMAKE_INSTALL_PREFIX.

Otherwise this path will be duplicated:

    $ cmake -DCMAKE_BUILD_TYPE=debug -DCMAKE_EXPORT_COMPILE_COMMANDS=ON -DCMAKE_INSTALL_PREFIX=inst ..
    $ DESTDIR=inst ninja install
    ...
    -- Installing: inst/src/le/libevent/.cmake-debug/inst/include/event2/util.h
    -- Installing: inst/src/le/libevent/.cmake-debug/inst/include/event2/ws.h
    ...

Fixes: #1404
Co-authored-by: Jeremy Murphy <jeremymu@blackmagicdesign.com>
2023-05-15 21:07:36 +02:00
Azat Khuzhin
41a7393f3e Fix Configure_RPATH() 2023-05-14 22:43:47 +02:00
Jonathan Ringer
be03bf385b Install LibeventConfig.cmake similar to other cmake files
- Don't destroy cmake file between test case invocations
2023-05-14 22:43:47 +02:00
Jonathan Ringer
1f1593ff27 Use GNUInstallDirs for mapping installation directories 2023-05-14 22:43:47 +02:00
Azat Khuzhin
f04d90b121 Fix building with -Wstack-protector due to VLA and fobid them
It is not a thankless task to fix such issues on and on, let's just
prohibit this cases, and our build with -Werror on CI will show new
issues from now on.

Fixes: #1434
2023-04-04 22:17:14 +02:00
fanquake
1878232bd5 build: split kqueue warning message into cross-compile and apple
This is output when compiling (natively) on macOS systems, which is
confusing, because no cross-compilation is involved.

Split the message into separate cases.
2023-04-04 22:04:17 +02:00
Michael Ford
185e2f009b
build: improve mbedtls searching on macOS with brew for cmake (#1419)
This just copies the same logic used to find OpenSSL on macOS using homebrew, for finding mbedtls via brew. Without it, the build will fail out the box with a brew installed mbedtls.
2023-03-05 16:58:22 +01:00
fanquake
38cd76f09c
build: use FORTIFY_SOURCE=3 in CMake build 2023-02-13 16:05:58 +00:00
Azat Khuzhin
4d85d28acd Fix pthread detection for regress tests on Android
Fixes: #1403
2023-01-28 13:28:52 +01:00
Dmitry Antipov
0b79a0024f buffer: use pread() for evbuffer_file_segment_materialize()
If pread(2) is available, prefer it over double lseek(2)
and read(2) in evbuffer_file_segment_materialize().

Signed-off-by: Dmitry Antipov <dantipov@cloudlinux.com>
2023-01-02 17:12:14 +03:00
mdavidsaver
1fe626c4da
Allow CLI override of CMAKE_DEBUG_POSTFIX (#1391)
Allows cmake -DCMAKE_BUILD_TYPE=DEBUG -DCMAKE_DEBUG_POSTFIX= for a debug build with the regular library names.
2022-12-16 11:34:25 +03:00
Azat Khuzhin
82af0ea4ee cmake: remove redundant _GNU_SOURCE definition
As reported by @francoisk:

    `_GNU_SOURCE` is defined in the private config header but also on the
    compiler command-line for every object.

Fixes: #1333
2022-11-20 22:19:21 +01:00
Azat Khuzhin
650d861969 cmake: do influence CMAKE_DEBUG_POSTFIX of the outer project (if any)
Consider the following example:

    $ touch lib.c
    $ cat > CMakeLists.txt <<EOL
    add_subdirectory(/src/le/libevent libevent EXCLUDE_FROM_ALL)
    add_library(lib lib.c)
    EOL
    $ mkdir .cmake
    $ cmake -DCMAKE_BUILD_TYPE=debug -G Ninja ..
    $ ninja
    $ ls *.a
    liblibd.a

So now outer project also has "d" prefix for libraries.

Let's avoid this by setting non-cached variable.

Fixes: #1371
2022-11-20 14:54:08 +01:00
Dmitry Antipov
1af745d033 signal: new signal handling backend based on signalfd
Linux-specific signal handling backend based on signalfd(2)
system call, and public function event_base_get_signal_method()
to obtain an underlying kernel signal handling mechanism.

Signed-off-by: Dmitry Antipov <dantipov@cloudlinux.com>
2022-11-12 21:14:48 +01:00
Azat Khuzhin
9e346936d4 Ignore unknown pragmas
Since new compilers has new checks (like -Wdangling-pointer), and so to
avoid extra checks in cmake/autotools, simply suppress if the pragma is
unknown.
2022-11-12 19:00:10 +01:00
Azat Khuzhin
c8c730c8dc cmake: tiny cleanup 2022-11-12 18:56:03 +01:00
Ryan Pavlik
8f47d8de28 cmake: Fix Android build.
Android/Bionic C library needs no special flags to have threading support.
Found when trying to build with vcpkg.
2022-10-08 19:27:21 +03:00
Dmitry Antipov
117ee9a03f epoll: use epoll_pwait2() if available
On GNU/Linux with epoll backend, prefer epoll_pwait2() if available,
which is useful to support the timeout with microsecond precision.
2022-09-27 22:07:43 +03:00
Dmitry Ilyin
211c6653ae Add manual CMAKE_C_BYTE_ORDER set for old CMake 2022-09-26 21:42:02 +03:00
Dmitry Ilyin
e8313084f9
Add minimal WebSocket server implementation for evhttp (#1322)
This adds few functions to use evhttp-based webserver to handle incoming
WebSockets connections. We've tried to use both libevent and libwebsockets in
our application, but found that we need to have different ports at the same
time to handle standard HTTP and WebSockets traffic. This change can help to
stick only with libevent library.

Implementation was inspired by modified Libevent source code in ipush project
[1].

  [1]: https://github.com/sqfasd/ipush/tree/master/deps/libevent-2.0.21-stable

Also, WebSocket-based chat server was added as a sample.
2022-09-12 22:16:56 +03:00
Azat Khuzhin
039e8d96a4 Add openssl-compat.h into HDR_PRIVATE
Fixes: #1334
2022-09-11 22:08:32 +02:00
Borys Smejda
86b5d2e951 Fixed CMake configuration failure (libevent#1321)
Deleted usage of CMake feature 'file(REAL_PATH'
which is available from version 3.19
with an old 'get_filename_component' so that
older version of CMake can still be used
to configure the project.
2022-08-13 20:15:06 +02:00
Dmitry Ilyin
99fd68abde Add check of mmap64 function and use it when available rather that mmap
There can be issues on 32-bit architectures to mmap 2+GiB file, and to
make this portable between different version of glibc, mmap64 was
prefered over _FILE_OFFSET_BITS
2022-08-09 00:18:10 +02:00
Haowei Hsu
dd610b7781 Add postfix for Debug configuration. 2022-08-07 11:14:40 +02:00
Azat Khuzhin
3960449374 Detech -Wno-unused-functions for GCC too
Otherwise build fails [1]:

    /home/runner/work/libevent/libevent/dist/libevent-2.2.0-alpha-dev/minheap-internal.h:64:6: error: ‘min_heap_ctor_’ defined but not used [-Werror=unused-function]
     void min_heap_ctor_(min_heap_t* s) { s->p = 0; s->n = 0; s->a = 0; }
          ^~~~~~~~~~~~~~
    In file included from /home/runner/work/libevent/libevent/dist/libevent-2.2.0-alpha-dev/buffer.c:91:0:
    /home/runner/work/libevent/libevent/dist/libevent-2.2.0-alpha-dev/bufferevent-internal.h:414:1: error: ‘bufferevent_trigger_nolock_’ defined but not used [-Werror=unused-function]
     bufferevent_trigger_nolock_(struct bufferevent *bufev, short iotype, int options)
     ^~~~~~~~~~~~~~~~~~~~~~~~~~~
    In file included from /home/runner/work/libevent/libevent/dist/libevent-2.2.0-alpha-dev/buffer.c:89:0:
    /home/runner/work/libevent/libevent/dist/libevent-2.2.0-alpha-dev/evthread-internal.h:140:1: error: ‘EVLOCK_TRY_LOCK_’ defined but not used [-Werror=unused-function]
     EVLOCK_TRY_LOCK_(void *lock)

  [1]: https://github.com/libevent/libevent/runs/7263518180?check_suite_focus=true
2022-07-09 17:17:06 +03:00
Azat Khuzhin
92b73c7d55 cmake: add compiler version to the status message 2022-07-09 17:17:06 +03:00
Azat Khuzhin
f5ad737d73 Add -Wundef for cmake and fix EVENT__SIZEOF_TIME_T usage
Note, autotools already supports it.
2022-07-09 17:16:56 +03:00
fanquake
bf3ce77f6c build: only try silence options if they exist
Otherwise GCC will warn. i.e:
```bash
  CCLD     libevent_openssl.la
cc1: note: unrecognized command-line option ‘-Wno-void-pointer-to-enum-cast’
	may have been intended to silence earlier diagnostics
  CCLD     libevent_mbedtls.la
```
2022-06-30 22:06:51 +03:00
Azat Khuzhin
6349e94a0a Do not install RPATH for install tree by default
In ce8be2385b5fee16859a630fca0c98ad290c8e21 ("cmake: set rpath for
libraries on linux") RPATH was first instroduced.

Later in 6d09efe8686de824adf3d8810bbe0d5c386643e4 ("Set RPATH only if
installation is done into non system directory") it was set only if it
was installed to non system directory.

But absolute RPATH not a good default, let's change this.

Fixes: #920
2022-03-10 23:54:58 +03:00