74 Commits

Author SHA1 Message Date
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
Azat Khuzhin
abc114e3c8 Bump default version when git tag is incorrect
Fixes: #1457
2023-05-21 12:49:34 +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
Tobias Mayer
16be768dac Make sure exported include dirs are correct
CMake config files don't need any logic to detect the location of
installed headers or DSOs, because these locations are already
determined at project configuration time. They also don't need
to distinguish between build and install trees, because that is
already handled by the generated `LibeventTargets-*.cmake` files.
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
Haowei Hsu
80c1e0b745 Search library name of Debug for find_event_lib. 2022-08-07 11:14:40 +02:00
William Marlow
384c52e6be Initial Mbed-TLS 3 support to get the GitHub Actions working again
mingw has upgraded to Mbed-TLS 3.1.0, so all the mingw tests that need
Mbed-TLS currently don't work.

v2: add missing mbedtls/version.h into test/regress_mbedtls.c
v3: suppress #warning "Including compat-2.x.h is deprecated" for mbedtls/compat-2.x.h
2022-07-09 20:47:04 +03:00
Azat Khuzhin
35e12a8175 Support build dir of the MbedTLS 2022-07-09 20:47:04 +03:00
Azat Khuzhin
6d09efe868 Set RPATH only if installation is done into non system directory
v2: use CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES

Fixes: #1245
2022-01-15 22:10:36 +03:00
Christopher Chavez
89505f8513 CheckWorkingKqueue.cmake: fix missing headers
Avoid implicitly declaring functions memset() and exit()
as it is considered an error by some compilers
(e.g. Xcode clang 12 and later)
2021-11-11 21:28:10 -06:00
Biswapriyo Nath
1fe8b3d6a4 cmake: Fix generted pkgconfig files.
Use lowercase 'L' option for library names because uppercase 'L' is used with library search directory.
2021-05-05 01:26:17 +05:30
Loïc Yhuel
657e180694 cmake: do not link libevent with libevent_core
When add_event_library macro was called without the INNER_LIBRARIES parameter, it reused the
value set by a previous call, since the INNER_LIBRARIES variable was not reset.
2020-11-23 17:24:36 +01:00
Azat Khuzhin
19d0bdfe0c Change prefix for man pages from "le_" to "libevent_"
As pointed by @kloczek:
  "With only two characters it would be harder to guess under what kind of name are libevent lvl 3 man pages.
   Longer name with bash/fix/zsh tab competition should not be a problem :)"

Refs: #1099
2020-10-04 22:59:12 +03:00
Azat Khuzhin
21b91692da Add prefix (le_) for man pages
This will:
- avoid overlapping (since there is util.h.3 page)
- group everything under some prefix (man le_<TAB><TAB> will show everything)

Fixes: #1099
2020-10-04 21:33:00 +03:00
Azat Khuzhin
3012c43808 Drop DOXYGEN_MAN_LINKS unsupported cmake flag
MAN_LINKS is not a variable in Doxyfile anyway.
2020-10-04 19:48:34 +03:00
okhowang(王沛文)
028385f685 fix build system and add test and cleanup code 2020-07-22 22:53:23 +03:00
Jesse Fang
8218777d44 mbed TLS cmake support
FindMbedTLS.cmake is come from https://github.com/AVSystem/avs_commons/blob/master/cmake/FindMbedTLS.cmake, which is licensed under Apache 2.0

alternatives:
  https://github.com/curl/curl/blob/master/CMake/FindMbedTLS.cmake   without variable MBEDTLS_ROOT_DIR
  https://github.com/libgit2/libgit2/blob/master/cmake/Modules/FindmbedTLS.cmake  GPLv2 with a special Linking Exception
2020-07-22 22:53:23 +03:00
yuangongji
a9aa2b3607 remove FindGit.cmake, improve git describe command 2020-05-28 20:10:47 +08:00
yuangongji
86eafc0343
cmake: set a default value for LIBEVENT_STATIC_LINK 2020-05-01 09:51:29 +08:00
yuangongji
41d1d75a84 cmake: replace CheckFunctionExists with CheckSymbolExists
Checking functions with `CheckFunctionExists` may
get wrong results, we should replace it with
`CheckSymbolExists`, which is recommended by the cmake
official documentation.
Before using `CheckSymbolExists`, we use
`CheckIncludeFiles` to check header files and save the
available header files in a variable that guarantees
`CheckSymbolExists` and `CheckTypeSize` to work correctly.
This approach is modeled after the cmake scripts of `curl`.

The following functions or files were not found before
modification, they can now be found:
- msys2 + mingw-8.1.0 on Windows10 or mingw-7.3.0 on Ubuntu-18.04
timerclear
timercmp
timerisset

- windows10
getaddrinfo
getnameinfo
getprotobynumber
getservbyname
putenv
strtoll
timerclear
timercmp
timerisset

- ubuntu-18.04
sys/sysctl.h
timeradd
timerclear
timercmp
timerisset

- MacOS 10.13
sys/random.h
timeradd
timerclear
timercmp
timerisset
2020-03-22 22:22:51 +08:00
Mario Emmenlauer
1675a55620 LibeventConfig.cmake: restore CMAKE_FIND_LIBRARY_SUFFIXES and LIBEVENT_STATIC_LINK default
The current cmake/LibeventConfig.cmake.in has a few problems and I'm not
sure how cleanly developed it is. It seems rater complex for the little
things I would assume it needs to do.

I found two problems that are fixed in this PR:

- If the downstream user does not explicitly set LIBEVENT_STATIC_LINK
  before calling find_package(libevent) then they will not be able to
  detect the static library, even if its the only one that exists. Since
  this may be rather strict, I've changed the behavior so that
  LIBEVENT_STATIC_LINK can be set to ON or OFF, but if unset, it defaults
  to whatever configuration libevent was built as.

- The other problem is a bug. The package configuration needs to unset
  CMAKE_FIND_LIBRARY_SUFFIXES after use, otherwise all packages that are
  detected after libevent will be "infected" by this setting. This was a
  significant problem for us, and is very hard to detect in downstream
  project, because the order of dependencies will lead to different search
  results.
2020-03-17 21:49:53 +03:00
yuangongji
503ba1d365 cmake: fix getaddrinfo checking error
Using `CheckFunctionExists` on Windows to check `getaddrinfo`
will get `not found`, but it actually exists. Using `CheckSymbolExists`
with headers will get correct results. Other functions such as
`getnameinfo`,`inet_ntop`,etc. have the same issue.
2020-03-17 21:43:39 +03:00
yuangongji
61c5c19bfd cmake: remove CheckFunctionExistsEx
`CheckFunctionExistsEx` is copied from the cmake modules before
3.1.2, which is the minimum required version of libevent.
The internal module `CheckFunctionExists`of cmake can completely
replace it.
2020-03-17 21:43:39 +03:00
yuangongji
ce8be2385b cmake: set rpath for libraries on linux 2020-01-24 07:52:06 +03:00
yuangongji
1a99f9b25c coverage: 'lcov --remove' need full path 2020-01-24 07:52:06 +03:00
Azat Khuzhin
b9f442e2d7 cmake: use CMAKE_LIBRARY_OUTPUT_DIRECTORY for the final shared library symlink
Fixes: 669a53f3 ("cmake: set library names to be the same as with autotools")
2019-11-30 15:54:56 +03:00
yuangongji
dc4be869d5 cmake: improve package config file 2019-11-14 18:09:31 +08:00
yuangongji
5fe83d7433 cmake: eliminate duplicate installation of public headers 2019-10-25 21:54:13 +08:00
yuangongji
620a3fa1d5 Doxygen documentation improvements
- Documentation for `bufferevent_compat.h` and `rpc.h` is not generated
  since the `@file` command is missing. It can be fixed by adding
  `@file` in file comment block.
- The briefs of buffer.h,bufferevent.h and some other files are missing.
  Adding `@brief` command can fix it.
- The parameters in the function declaration are different from the
  parameters following the `@param` command.We should change them to the
  same.
- Documentation of `watch.h` is not generated since `watch.h` has not
  been added to the Doxyfile `INPUT` tag.

- Add link to the watch.h in event.h
2019-08-29 23:08:12 +03:00
yuangongji
1d1c19091f cmake: attach doxygen target into all target
v2: Disable non-html generator for doxygen by default
v3: convert cmake option to doxygen config
2019-08-28 01:23:26 +03:00
Azat Khuzhin
55d1e20e1a
cmake: install shared library only if it was requested
$ cmake -DEVENT__LIBRARY_TYPE=static ..
  ...
  CMake Error:
  Error evaluating generator expression:

    $<TARGET_FILE_DIR:event_core_shared>

  No target "event_core_shared"

Fixes: #853
Fixes: 669a53f3 ("cmake: set library names to be the same as with autotools")
2019-07-12 00:02:12 +03:00
yuangongji
669a53f341
cmake: set library names to be the same as with autotools
libtool has VERSION_INFO [1], cmake has SOVERSION/VERSION instead
(although it has different format). Also libtool has RELEASE [2] while
cmake do not have analog yet [3], hence manual symlinks should be
created.

  [1]: https://www.gnu.org/software/libtool/manual/html_node/Libtool-versioning.html
  [2]: https://www.gnu.org/software/libtool/manual/html_node/Release-numbers.html
  [3]: https://gitlab.kitware.com/cmake/cmake/issues/17652

Plus osx has compatibility_version/current_version dylib properties and
cmake do not have separate properties for them [4], hence manual LINK_FLAGS.
And also there INSTALL_NAME_DIR property which should be adjusted too.

  [4]: https://public.kitware.com/Bug/view.php?id=4383

So after all changes, here is an example before/after for osx and linux:

  # osx
    # autotools
    .libs/libevent_pthreads-2.2.1.dylib
    .libs/libevent_pthreads.dylib -> libevent_pthreads-2.2.1.dylib
    /usr/local/lib/libevent_pthreads-2.2.1.dylib (compatibility version 2.0.0, current version 2.0.0)
    # cmake
      # before patch
      lib/libevent_pthreads.2.2.0.dylib
      lib/libevent_pthreads.dylib -> libevent_pthreads.2.2.0.dylib
      @rpath/libevent_pthreads.2.2.0.dylib (compatibility version 2.2.0, current version 0.0.0)
      # after patch
      lib/libevent_pthreads-2.2.1.dylib
      lib/libevent_pthreads.dylib -> libevent_pthreads-2.2.1.dylib
      /vagrant/.cmake/inst/lib/libevent_pthreads-2.2.1.dylib (compatibility version 2.0.0, current version 2.0.0)

  # linux
    # autotools
    .libs/libevent_pthreads-2.2.so.1 -> libevent_pthreads-2.2.so.1.0.0
    .libs/libevent_pthreads-2.2.so.1.0.0
    .libs/libevent_pthreads.so -> libevent_pthreads-2.2.so.1.0.0
    # cmake
      # before patch
      lib/libevent_pthreads.so -> libevent_pthreads.so.2.2.0
      lib/libevent_pthreads.so.2.2.0
      # after patch
      lib/libevent_pthreads-2.2.so -> libevent_pthreads-2.2.so.1
      lib/libevent_pthreads-2.2.so.1 -> libevent_pthreads-2.2.so.1.0.0
      lib/libevent_pthreads-2.2.so.1.0.0
      lib/libevent_pthreads.so -> libevent_pthreads-2.2.so.1.0.0

Closes: #838 (cherry-picked)
Closes: #760
2019-07-11 10:11:38 +03:00
yuangongji
7201062f3e
cmake: add missing autotools targets (doxygen, uninstall, event_rpcgen.py)
Close: #832 (cherry-picked)
2019-06-13 21:57:39 +03:00
Enji Cooper
0b468bb07e Fix typos in a comment describing the purpose of VersionViaGit.cmake
Signed-off-by: Enji Cooper <yaneurabeya@gmail.com>
2019-02-28 17:35:02 -08:00
Azat Khuzhin
c9a073eae8
cmake: introduce EVENT__LIBRARY_TYPE option
Long time ago in [1] cmake build was forced to compile both libraries
(SHARED and STATIC), since this is how our autotools build works.

  [1]: 7182c2f561570cd9ceb704623ebe9ae3608c7b43 ("cmake: build SHARED and STATIC libraries (like autoconf does)")

And there is no way to configure this (and indeed you need to do this
for MSVC for example), so let's introduce option for this --
EVENT__LIBRARY_TYPE.

Plus now we have INTERFACE libraries, that we can use internally in
libevent's cmake rules to avoid strict to _shared/_static variant of the
libraries to link with samples/tests (we prefer SHARED over STATIC for
linking).

Also bump minimal cmake required version to 3.1 by the following
reasons:
- 3.1 is required for RPATH configuration under APPLE
- 3.0 is required for add_library(INTERFACE) (did not found it in 2.8.x
documentation)
- remove extra conditions
(anyway 3.1 was release 4 years ago, so I guess that most of the systems
will have it)
2018-11-23 00:02:18 +03:00
Azat Khuzhin
4c61a04cd5
Make cmake's check_const_exists() rely on cache 2018-10-18 23:16:05 +03:00
Azat Khuzhin
accf383e04 Fix CheckFunctionExistsEx() cmake macro on win32
For example under mingw64 it could not detect that strtok_r() exists,
because it checks with:
  void *p = func_name;

And for this you need the function to be defined, so just sync our
CheckFunctionExistsEx.c with CheckFunctionExists.c from cmake (and later
we should drop them out) since it does correct things to detech
functions existence.

Also for WIN32 there is -FIwinsock2.h -FIws2tcpip.h, and I guess that is
not works for mingw gcc (since -F in gcc is framework, and in windows
-FI is like -include in gcc). But looks like we do not need them
already (due to fixed CheckFunctionExistsEx()).

Refs: #605
2018-04-26 01:14:49 +03:00
Philip Herron
0fa43c99fb cmake: ensure windows dll's are installed as well as lib files
Closes: #621
2018-04-09 00:15:03 +03:00
Carlo Marcelo Arenas Belón
1dfec8a970 configure: avoid false positive in DragonFlyBSD
by default, the max buffer size is 16K and histeresis is at 50%, so
a bigger read is needed to unlock writes than you would expect from
other BSD (512 bytes)

this doesn't introduce any regression on FreeBSD 11.1, OpenBSD 6.1, NetBSD 7.1,
macOS 10.12.6 and of course DragonFlyBSD 4.8.1, and most of them show
a max pipe size of 64K, so the read call should drain them all regardless
of how conservative they are on the free pipe space they will require
(usually 512 bytes) before kevent reports the fd as ready for write.

I couldn't find a reference to which bug this code was trying to look for
and it seems to be there from the beginning of git history so it might be
no longer relevant.

Issue: #548
2017-09-11 01:48:35 +03:00
Azat Khuzhin
b1e8a4138f cmake: use APPEND during exporting targets (for old cmake)
On centos with cmake 2.8.12.2:
  CMake Error at cmake/AddEventLibrary.cmake:92 (export):
    export called with target "event_extra_shared" which requires target
    "event_core_shared" that is not in the export list.

    If the required target is not easy to reference in this call, consider
    using the APPEND option with multiple separate calls.

But on newer cmake I guess everything is ok.

Fixes: 7182c2f561570cd9ceb704623ebe9ae3608c7b43 ("cmake: build SHARED
and STATIC libraries (like autoconf does)")
2017-03-14 13:37:59 +03:00
Azat Khuzhin
882f537c40 cmake: fix pkgconfig generation (copy-paste typo) 2017-03-13 21:41:10 +03:00
Azat Khuzhin
fd5a3fc036 cmake: fix export absolute path and relative path and cleanup a bit
Remove next vars, since I don't think that somebody want to change it:
- bin
- lib
- include

And fix exports problem:
  CMake Error: INSTALL(EXPORT "LibeventTargets") given absolute DESTINATION "/usr/lib/cmake/libevent" but the export references an installation of target "event_core_static" which has relative DESTINATION "lib".
2017-03-13 16:20:40 +03:00
Azat Khuzhin
86c7357525 cmake: generate and install pkgconfig files
Fixes: #443
2017-03-13 16:20:40 +03:00
Azat Khuzhin
7182c2f561 cmake: build SHARED and STATIC libraries (like autoconf does)
Since they are useful for debugging, and if autotools build them then
cmamke has to do this too, to make migration more simple.

And now:
- tests: uses shared libraries (since this is upstreams one)
- other binaries: uses static libraries

This removes next private config:
- EVENT__NEED_DLLIMPORT
2017-03-13 16:20:40 +03:00
Azat Khuzhin
72ef9d1652 cmake: add missing event_openssl/event_pthreads libraries
This will remove openssl requirement if you don't use it (i.e. if you
not link with openssl_pthreads).

Plus it fixes some linking dependencies:
- libm required only for test-ratelim

And fix some coding style alignment issues.

Refs: #246
2017-03-13 12:57:22 +03:00
Azat Khuzhin
d65e3e1dbe cmake: fix extracting of the version from git (check for number of matches) 2017-03-08 13:31:55 +03:00
Azat Khuzhin
66a4eb0c3a Check for WNOWAIT in waitpid() in runtime (not in cmake/configure)
Because checking in cmake breaks cross-compiling.

Introduced-in: 43eb56c7c738e3642f0981e3dd6ab9e082eec798.
Fixes: #482
Fixes: #462
Refs: #475

v2: use waitid() with WNOWAIT
v3: use WNOWAIT only if it available in waitpid(), because not all netbsd
    supports it
2017-03-08 13:31:55 +03:00
Azat Khuzhin
fa135bdcd9 cmake: Fix checking of enum values from sysctl.h
CheckSymbolExists do not do this, so add new CheckConstExists that will
use CheckCSourceCompiles() to check this.

v2: use set() instead of string(APPEND)
2017-03-08 12:47:22 +03:00