cmake: add librtmp Find module

The new detection method also allows to enable librtmp without using
OpenSSL as a curl TLS backend at the same time.

Also:
- implement manual version detection for librtmp.
  Version info is in hex. With CMake 3.13 and newer, extract it as a hex
  number. With earlier CMake version, just strip the leading zeroes.
  Doing more here seems overkill because librtmp has been standing
  at 2.3/2.4 for a decade now. Bumping into hex digits seems unlikely
  before deprecating CMake 3.13 support.
  librtmp advertises v2.4 via its `pkg-config` module, and v2.3 via
  its public header. The latter shows up in `curl -V` and either can
  be shown at configure-time depending on detection method.
  This isn't a curl bug.
- GHA/macos: enable rtmp in a job.
- apply the "half-detection" fix to the Find module.
  `librtmp` is also affected (in CI too), because it depends on libssl and
  libcrypto.

Closes #15832
This commit is contained in:
Viktor Szakats 2024-12-26 11:34:24 +01:00
parent 5e1700d167
commit 421e592db2
No known key found for this signature in database
GPG Key ID: B5ABD165E2AEF201
6 changed files with 128 additions and 32 deletions

1
.github/labeler.yml vendored
View File

@ -377,6 +377,7 @@ RTMP:
- all:
- changed-files:
- any-glob-to-all-files: "{\
CMake/FindLibrtmp.cmake,\
lib/curl_rtmp.*\
}"

View File

@ -128,9 +128,9 @@ jobs:
configure: --enable-debug --disable-ldap --with-openssl=$(brew --prefix openssl)
macos-version-min: '10.15'
# cmake
- name: 'OpenSSL gsasl AppleIDN'
install: gsasl
generate: -DOPENSSL_ROOT_DIR=$(brew --prefix openssl) -DCURL_USE_GSASL=ON -DUSE_APPLE_IDN=ON
- name: 'OpenSSL gsasl rtmp AppleIDN'
install: gsasl rtmpdump
generate: -DOPENSSL_ROOT_DIR=$(brew --prefix openssl) -DCURL_USE_GSASL=ON -DUSE_LIBRTMP=ON -DUSE_APPLE_IDN=ON
- name: 'OpenSSL +static libssh +examples'
install: libssh
generate: -DOPENSSL_ROOT_DIR=$(brew --prefix openssl) -DBUILD_STATIC_LIBS=ON -DCURL_USE_LIBSSH2=OFF -DCURL_USE_LIBSSH=ON

102
CMake/FindLibrtmp.cmake Normal file
View File

@ -0,0 +1,102 @@
#***************************************************************************
# _ _ ____ _
# Project ___| | | | _ \| |
# / __| | | | |_) | |
# | (__| |_| | _ <| |___
# \___|\___/|_| \_\_____|
#
# Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
#
# This software is licensed as described in the file COPYING, which
# you should have received as part of this distribution. The terms
# are also available at https://curl.se/docs/copyright.html.
#
# You may opt to use, copy, modify, merge, publish, distribute and/or sell
# copies of the Software, and permit persons to whom the Software is
# furnished to do so, under the terms of the COPYING file.
#
# This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
# KIND, either express or implied.
#
# SPDX-License-Identifier: curl
#
###########################################################################
# Find the librtmp library
#
# Input variables:
#
# - `LIBRTMP_INCLUDE_DIR`: The librtmp include directory.
# - `LIBRTMP_LIBRARY`: Path to `librtmp` library.
#
# Result variables:
#
# - `LIBRTMP_FOUND`: System has librtmp.
# - `LIBRTMP_INCLUDE_DIRS`: The librtmp include directories.
# - `LIBRTMP_LIBRARIES`: The librtmp library names.
# - `LIBRTMP_LIBRARY_DIRS`: The librtmp library directories.
# - `LIBRTMP_PC_REQUIRES`: The librtmp pkg-config packages.
# - `LIBRTMP_CFLAGS`: Required compiler flags.
# - `LIBRTMP_VERSION`: Version of librtmp.
set(LIBRTMP_PC_REQUIRES "librtmp")
if(CURL_USE_PKGCONFIG AND
NOT DEFINED LIBRTMP_INCLUDE_DIR AND
NOT DEFINED LIBRTMP_LIBRARY)
find_package(PkgConfig QUIET)
pkg_check_modules(LIBRTMP ${LIBRTMP_PC_REQUIRES})
endif()
if(LIBRTMP_FOUND AND LIBRTMP_INCLUDE_DIRS)
string(REPLACE ";" " " LIBRTMP_CFLAGS "${LIBRTMP_CFLAGS}")
message(STATUS "Found Librtmp (via pkg-config): ${LIBRTMP_INCLUDE_DIRS} (found version \"${LIBRTMP_VERSION}\")")
else()
find_path(LIBRTMP_INCLUDE_DIR NAMES "librtmp/rtmp.h")
find_library(LIBRTMP_LIBRARY NAMES "rtmp")
unset(LIBRTMP_VERSION CACHE)
if(LIBRTMP_INCLUDE_DIR AND EXISTS "${LIBRTMP_INCLUDE_DIR}/librtmp/rtmp.h")
set(_version_regex "#[\t ]*define[\t ]+RTMP_LIB_VERSION[\t ]+0x([0-9a-fA-F][0-9a-fA-F])([0-9a-fA-F][0-9a-fA-F]).*")
file(STRINGS "${LIBRTMP_INCLUDE_DIR}/librtmp/rtmp.h" _version_str REGEX "${_version_regex}")
string(REGEX REPLACE "${_version_regex}" "\\1" _version_str1 "${_version_str}")
string(REGEX REPLACE "${_version_regex}" "\\2" _version_str2 "${_version_str}")
if(CMAKE_VERSION VERSION_LESS 3.13)
# No support for hex version numbers, just strip leading zeroes
string(REGEX REPLACE "^0" "" _version_str1 "${_version_str1}")
string(REGEX REPLACE "^0" "" _version_str2 "${_version_str2}")
else()
math(EXPR _version_str1 "0x${_version_str1}" OUTPUT_FORMAT DECIMAL)
math(EXPR _version_str2 "0x${_version_str2}" OUTPUT_FORMAT DECIMAL)
endif()
set(LIBRTMP_VERSION "${_version_str1}.${_version_str2}")
unset(_version_regex)
unset(_version_str1)
unset(_version_str2)
endif()
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(Librtmp
REQUIRED_VARS
LIBRTMP_INCLUDE_DIR
LIBRTMP_LIBRARY
VERSION_VAR
LIBRTMP_VERSION
)
if(LIBRTMP_FOUND)
set(LIBRTMP_INCLUDE_DIRS ${LIBRTMP_INCLUDE_DIR})
set(LIBRTMP_LIBRARIES ${LIBRTMP_LIBRARY})
endif()
mark_as_advanced(LIBRTMP_INCLUDE_DIR LIBRTMP_LIBRARY)
# Necessary when linking a static librtmp
find_package(OpenSSL)
if(OPENSSL_FOUND)
list(APPEND LIBRTMP_LIBRARIES OpenSSL::SSL OpenSSL::Crypto)
endif()
endif()
if(WIN32)
list(APPEND LIBRTMP_LIBRARIES "winmm")
endif()

View File

@ -867,7 +867,7 @@ if(ZSTD_FOUND)
endif()
# Check symbol in an OpenSSL-like TLS backend, or in _extra_libs depending on it.
macro(curl_openssl_check_symbol_exists _symbol _files _variable _extra_libs)
macro(curl_openssl_check_symbol_exists _symbol _files _variable)
cmake_push_check_state()
if(USE_OPENSSL)
list(APPEND CMAKE_REQUIRED_INCLUDES "${OPENSSL_INCLUDE_DIR}")
@ -893,7 +893,6 @@ macro(curl_openssl_check_symbol_exists _symbol _files _variable _extra_libs)
endif()
list(APPEND CMAKE_REQUIRED_DEFINITIONS "-DHAVE_UINTPTR_T") # to pull in stdint.h (as of wolfSSL v5.5.4)
endif()
list(APPEND CMAKE_REQUIRED_LIBRARIES "${_extra_libs}")
check_symbol_exists("${_symbol}" "${_files}" "${_variable}")
cmake_pop_check_state()
endmacro()
@ -902,11 +901,11 @@ endmacro()
macro(curl_openssl_check_quic)
if(NOT DEFINED HAVE_SSL_CTX_SET_QUIC_METHOD)
if(USE_OPENSSL)
curl_openssl_check_symbol_exists("SSL_CTX_set_quic_method" "openssl/ssl.h" HAVE_SSL_CTX_SET_QUIC_METHOD "")
curl_openssl_check_symbol_exists("SSL_CTX_set_quic_method" "openssl/ssl.h" HAVE_SSL_CTX_SET_QUIC_METHOD)
endif()
if(USE_WOLFSSL)
curl_openssl_check_symbol_exists("wolfSSL_set_quic_method" "wolfssl/options.h;wolfssl/openssl/ssl.h"
HAVE_SSL_CTX_SET_QUIC_METHOD "")
HAVE_SSL_CTX_SET_QUIC_METHOD)
endif()
endif()
if(NOT HAVE_SSL_CTX_SET_QUIC_METHOD)
@ -915,18 +914,17 @@ macro(curl_openssl_check_quic)
endmacro()
if(USE_WOLFSSL)
curl_openssl_check_symbol_exists("wolfSSL_DES_ecb_encrypt" "wolfssl/options.h;wolfssl/openssl/des.h" HAVE_WOLFSSL_DES_ECB_ENCRYPT
"")
curl_openssl_check_symbol_exists("wolfSSL_BIO_new" "wolfssl/options.h;wolfssl/ssl.h" HAVE_WOLFSSL_BIO "")
curl_openssl_check_symbol_exists("wolfSSL_BIO_set_shutdown" "wolfssl/options.h;wolfssl/ssl.h" HAVE_WOLFSSL_FULL_BIO "")
curl_openssl_check_symbol_exists("wolfSSL_DES_ecb_encrypt" "wolfssl/options.h;wolfssl/openssl/des.h" HAVE_WOLFSSL_DES_ECB_ENCRYPT)
curl_openssl_check_symbol_exists("wolfSSL_BIO_new" "wolfssl/options.h;wolfssl/ssl.h" HAVE_WOLFSSL_BIO)
curl_openssl_check_symbol_exists("wolfSSL_BIO_set_shutdown" "wolfssl/options.h;wolfssl/ssl.h" HAVE_WOLFSSL_FULL_BIO)
endif()
if(USE_OPENSSL OR USE_WOLFSSL)
if(NOT DEFINED HAVE_SSL_SET0_WBIO)
curl_openssl_check_symbol_exists("SSL_set0_wbio" "openssl/ssl.h" HAVE_SSL_SET0_WBIO "")
curl_openssl_check_symbol_exists("SSL_set0_wbio" "openssl/ssl.h" HAVE_SSL_SET0_WBIO)
endif()
if(NOT DEFINED HAVE_OPENSSL_SRP AND NOT CURL_DISABLE_SRP)
curl_openssl_check_symbol_exists("SSL_CTX_set_srp_username" "openssl/ssl.h" HAVE_OPENSSL_SRP "")
curl_openssl_check_symbol_exists("SSL_CTX_set_srp_username" "openssl/ssl.h" HAVE_OPENSSL_SRP)
endif()
endif()
@ -937,14 +935,12 @@ if(USE_ECH)
# Be sure that the TLS library actually supports ECH.
if(USE_WOLFSSL)
curl_openssl_check_symbol_exists("wolfSSL_CTX_GenerateEchConfig" "wolfssl/options.h;wolfssl/ssl.h"
HAVE_WOLFSSL_CTX_GENERATEECHCONFIG "")
HAVE_WOLFSSL_CTX_GENERATEECHCONFIG)
endif()
if(HAVE_BORINGSSL OR HAVE_AWSLC)
curl_openssl_check_symbol_exists("SSL_set1_ech_config_list" "openssl/ssl.h"
HAVE_SSL_SET1_ECH_CONFIG_LIST "")
curl_openssl_check_symbol_exists("SSL_set1_ech_config_list" "openssl/ssl.h" HAVE_SSL_SET1_ECH_CONFIG_LIST)
elseif(HAVE_OPENSSL)
curl_openssl_check_symbol_exists("SSL_ech_set1_echconfig" "openssl/ech.h"
HAVE_SSL_ECH_SET1_ECHCONFIG "")
curl_openssl_check_symbol_exists("SSL_ech_set1_echconfig" "openssl/ech.h" HAVE_SSL_ECH_SET1_ECHCONFIG)
endif()
if(HAVE_WOLFSSL_CTX_GENERATEECHCONFIG OR
HAVE_SSL_SET1_ECH_CONFIG_LIST OR
@ -1364,20 +1360,14 @@ endif()
option(USE_LIBRTMP "Enable librtmp from rtmpdump" OFF)
if(USE_LIBRTMP)
set(_extra_libs "rtmp")
if(WIN32)
list(APPEND _extra_libs "winmm")
endif()
curl_openssl_check_symbol_exists("RTMP_Init" "librtmp/rtmp.h" HAVE_LIBRTMP "${_extra_libs}")
if(HAVE_LIBRTMP)
list(APPEND CURL_LIBS "rtmp")
list(APPEND LIBCURL_PC_REQUIRES_PRIVATE "librtmp")
if(WIN32)
list(APPEND CURL_LIBS "winmm")
endif()
else()
message(WARNING "librtmp has been requested, but not found or missing OpenSSL. Skipping.")
set(USE_LIBRTMP OFF)
find_package(Librtmp REQUIRED)
list(APPEND CURL_LIBS ${LIBRTMP_LIBRARIES})
list(APPEND CURL_LIBDIRS ${LIBRTMP_LIBRARY_DIRS})
list(APPEND LIBCURL_PC_REQUIRES_PRIVATE ${LIBRTMP_PC_REQUIRES})
include_directories(SYSTEM ${LIBRTMP_INCLUDE_DIRS})
link_directories(${LIBRTMP_LIBRARY_DIRS})
if(LIBRTMP_CFLAGS)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${LIBRTMP_CFLAGS}")
endif()
endif()

View File

@ -40,6 +40,7 @@ CMAKE_DIST = \
CMake/FindLibgsasl.cmake \
CMake/FindLibidn2.cmake \
CMake/FindLibpsl.cmake \
CMake/FindLibrtmp.cmake \
CMake/FindLibssh.cmake \
CMake/FindLibssh2.cmake \
CMake/FindLibuv.cmake \

View File

@ -324,6 +324,8 @@ Details via CMake
- `LIBIDN2_LIBRARY`: Path to `libidn2` library.
- `LIBPSL_INCLUDE_DIR`: The libpsl include directory.
- `LIBPSL_LIBRARY`: Path to `libpsl` library.
- `LIBRTMP_INCLUDE_DIR`: The librtmp include directory.
- `LIBRTMP_LIBRARY`: Path to `librtmp` library.
- `LIBSSH_INCLUDE_DIR`: The libssh include directory.
- `LIBSSH_LIBRARY`: Path to `libssh` library.
- `LIBSSH2_INCLUDE_DIR`: The libssh2 include directory.