git: 986cbcf341d6 - main - net/libwebsockets: Fix build with LibreSSL

From: Felix Palmen <zirias_at_FreeBSD.org>
Date: Fri, 19 May 2023 21:19:25 UTC
The branch main has been updated by zirias:

URL: https://cgit.FreeBSD.org/ports/commit/?id=986cbcf341d665b3c0ca454f76fb98e6c5a690cb

commit 986cbcf341d665b3c0ca454f76fb98e6c5a690cb
Author:     Felix Palmen <zirias@FreeBSD.org>
AuthorDate: 2023-05-19 07:06:06 +0000
Commit:     Felix Palmen <zirias@FreeBSD.org>
CommitDate: 2023-05-19 21:19:02 +0000

    net/libwebsockets: Fix build with LibreSSL
    
    The build system uses both cmake and pkg-config to find OpenSSL and just
    combines the results. Our base OpenSSL didn't provide a pkg-config file
    until recently, but the LibreSSL port does. From the cmake detection, we
    get absolute library paths, from pkg-config just library names (-lssl).
    The latter are found in base during linking. The result is linking both
    OpenSSL and LibreSSL.
    
    Therefore add a patch that just skips pkg-config for OpenSSL and remove
    the broken workaround from the port Makefile.
    
    PR:             271495
    Approved by:    tcberner (mentor, implicit)
---
 net/libwebsockets/Makefile                           |  8 +-------
 net/libwebsockets/files/patch-lib_tls_CMakeLists.txt | 19 +++++++++++++++++++
 2 files changed, 20 insertions(+), 7 deletions(-)

diff --git a/net/libwebsockets/Makefile b/net/libwebsockets/Makefile
index 639b07bfdeaf..77d3ff45b19e 100644
--- a/net/libwebsockets/Makefile
+++ b/net/libwebsockets/Makefile
@@ -1,6 +1,7 @@
 PORTNAME=	libwebsockets
 DISTVERSIONPREFIX=	v
 DISTVERSION=	4.3.2
+PORTREVISION=	1
 CATEGORIES=	net devel
 MASTER_SITES=	https://libwebsockets.org/git/libwebsockets/snapshot/
 
@@ -80,11 +81,4 @@ LIBEVENT_CMAKE_BOOL=	LWS_WITH_LIBEVENT
 LIBUV_LIB_DEPENDS=	libuv.so:devel/libuv
 LIBUV_CMAKE_BOOL=	LWS_WITH_LIBUV
 
-.include <bsd.port.options.mk>
-
-# Allow usage of LibreSSL via OPENSSL option
-.if ${PORT_OPTIONS:MOPENSSL} && ${SSL_DEFAULT} == libressl
-CMAKE_ARGS+=	-DLWS_OPENSSL_LIBRARIES='${OPENSSLLIB}/libtls.so;${OPENSSLLIB}/libssl.so;${OPENSSLLIB}/libcrypto.so' -DLWS_OPENSSL_INCLUDE_DIRS=${OPENSSLINC}/ssl
-.endif
-
 .include <bsd.port.mk>
diff --git a/net/libwebsockets/files/patch-lib_tls_CMakeLists.txt b/net/libwebsockets/files/patch-lib_tls_CMakeLists.txt
new file mode 100644
index 000000000000..ac872cf1aee1
--- /dev/null
+++ b/net/libwebsockets/files/patch-lib_tls_CMakeLists.txt
@@ -0,0 +1,19 @@
+Disable usage of pkg-config for OpenSSL to avoid linking two different versions.
+See PRs: 258345, 271495
+
+--- lib/tls/CMakeLists.txt.orig	2023-05-19 06:48:43 UTC
++++ lib/tls/CMakeLists.txt
+@@ -264,10 +264,10 @@ if (LWS_WITH_SSL)
+ 		if (NOT OPENSSL_FOUND AND NOT LWS_WITH_BORINGSSL)
+ 			# TODO: Add support for STATIC also.
+ 			if (NOT LWS_PLAT_FREERTOS)
+-				find_package(PkgConfig QUIET)
+-				pkg_check_modules(PC_OPENSSL openssl QUIET)
++				#find_package(PkgConfig QUIET)
++				#pkg_check_modules(PC_OPENSSL openssl QUIET)
+ 				find_package(OpenSSL REQUIRED)
+-				list(APPEND OPENSSL_LIBRARIES ${PC_OPENSSL_LIBRARIES})
++				#list(APPEND OPENSSL_LIBRARIES ${PC_OPENSSL_LIBRARIES})
+ 				set(OPENSSL_LIBRARIES ${OPENSSL_LIBRARIES} PARENT_SCOPE)
+ 			endif()
+ 			set(OPENSSL_INCLUDE_DIRS "${OPENSSL_INCLUDE_DIR}")