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
Initially 6.9 and 7.1 had been added, however due to some issues (you can read
about them below) 6.9 had been disabled.
netbsd 6.9 does not have correct library namings for autotools:
2022-08-17T04:59:58.8339420Z libtool: link: (cd ".libs" && rm -f "libevent.so.1.0" && ln -s "libevent-2.2.so.1.0" "libevent.so.1.0")
$ grep ^library_names= libevent.la·
library_names='libevent-2.2.so.1.0 libevent.so.1.0'
# And this is wrong, it should be:
libtool: link: (cd ".libs" && rm -f "libevent-2.2.so.1" && ln -s "libevent-2.2.so.1.0.0" "libevent-2.2.so.1")
libtool: link: (cd ".libs" && rm -f "libevent.so" && ln -s "libevent-2.2.so.1.0.0" "libevent.so")
library_names='libevent-2.2.so.1.0.0 libevent-2.2.so.1 libevent.so'
**And I think that 7.1 should also fail, however it has system-wide libevent installed with evdns in the libevent.so**
Also there are some issues with `TEST_EXPORT_SHARED` test, because of libraries naming:
2022-09-13T06:38:29.2150790Z [test-export] test for install tree(in system-wide path)
2022-09-13T06:38:29.2151500Z [test-export] fail: link core and run core expects success but gets failure.
2022-09-13T06:38:29.2063870Z /usr/bin/cc CMakeFiles/test-export.dir/test-export.c.o -o test-export -L/usr/local/lib -Wl,-z,origin,-rpath,/usr/local/lib -levent_core-2.2 -lpthread -Wl,-rpath-link,/usr/X11R6/lib:/usr/local/lib·
2022-09-13T06:38:29.2152190Z ld: error: unable to find library -levent_core-2.2
2022-09-13T06:38:28.3915680Z -- Install configuration: "Release"
2022-09-13T06:38:28.3916700Z -- Up-to-date: /usr/local/lib/libevent_core-2.2.so.1.0.0
2022-09-13T06:38:28.3917110Z -- Up-to-date: /usr/local/lib/libevent_core-2.2.so.1
2022-09-13T06:38:28.3917480Z -- Up-to-date: /usr/local/lib/libevent_core.so
# no libevent_core-2.2.so
So I have to disable it too.
Co-authored-by: Azat Khuzhin <azat@libevent.org>
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