Skip to content

Commit

Permalink
Add rtmp feature to curl
Browse files Browse the repository at this point in the history
Signed-off-by: Tal Regev <[email protected]>
  • Loading branch information
talregev committed Jan 15, 2025
1 parent 6220088 commit 389df00
Show file tree
Hide file tree
Showing 12 changed files with 228 additions and 81 deletions.
2 changes: 2 additions & 0 deletions ports/curl/portfile.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ vcpkg_from_github(
export-components.patch
dependencies.patch
cmake-config.patch
rtmp.patch
)

vcpkg_check_features(OUT_FEATURE_OPTIONS FEATURE_OPTIONS
Expand All @@ -36,6 +37,7 @@ vcpkg_check_features(OUT_FEATURE_OPTIONS FEATURE_OPTIONS
gssapi CURL_USE_GSSAPI
gsasl CURL_USE_GSASL
gnutls CURL_USE_GNUTLS
rtmp USE_LIBRTMP
INVERTED_FEATURES
ldap CURL_DISABLE_LDAP
ldap CURL_DISABLE_LDAPS
Expand Down
29 changes: 29 additions & 0 deletions ports/curl/rtmp.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
diff --git a/CMake/curl-config.cmake.in b/CMake/curl-config.cmake.in
index c290064daa..4122b260f2 100644
--- a/CMake/curl-config.cmake.in
+++ b/CMake/curl-config.cmake.in
@@ -50,6 +50,9 @@ endif()
if("@HAVE_ZSTD@")
find_dependency(zstd CONFIG)
endif()
+if("@USE_LIBRTMP@")
+ find_dependency(unofficial-librtmp CONFIG)
+endif()

include("${CMAKE_CURRENT_LIST_DIR}/@[email protected]")
check_required_components("@PROJECT_NAME@")
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 0cba6f626b..e4a5f05ade 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1309,6 +1309,10 @@ endif()

option(USE_LIBRTMP "Enable librtmp from rtmpdump" OFF)
if(USE_LIBRTMP)
+ find_package(OpenSSL REQUIRED)
+ find_package(unofficial-librtmp CONFIG REQUIRED)
+ list(APPEND CURL_LIBS unofficial::librtmp::librtmp)
+elseif(0)
set(_extra_libs "rtmp")
if(WIN32)
list(APPEND _extra_libs "winmm")
7 changes: 7 additions & 0 deletions ports/curl/vcpkg.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"name": "curl",
"version": "8.11.1",
"port-version": 1,
"description": "A library for transferring data with URLs",
"homepage": "https://curl.se/",
"license": "curl AND ISC AND BSD-3-Clause",
Expand Down Expand Up @@ -136,6 +137,12 @@
"libpsl"
]
},
"rtmp": {
"description": "rtmpDump support (librtmp)",
"dependencies": [
"librtmp"
]
},
"schannel": {
"description": "SSL support (Secure Channel)",
"supports": "windows & !uwp",
Expand Down
12 changes: 12 additions & 0 deletions ports/librtmp/0006-typedef-off_t.diff
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
diff --git a/librtmp/rtmp_sys.h b/librtmp/rtmp_sys.h
index 5b3eb54e86767a45a91f941014113ca9e62b5b74..5b4c1e98a12b2b2dc3009fee007ac140fd2745f8 100644
--- a/librtmp/rtmp_sys.h
+++ b/librtmp/rtmp_sys.h
@@ -43,6 +43,7 @@
#define sleep(n) Sleep(n*1000)
#define msleep(n) Sleep(n)
#define SET_RCVTIMEO(tv,s) int tv = s*1000
+#include <sys/types.h>
#else /* !_WIN32 */
#include <sys/types.h>
#include <sys/socket.h>
171 changes: 117 additions & 54 deletions ports/librtmp/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,70 +1,133 @@
cmake_minimum_required(VERSION 3.10)
# Unofficial librtmp CMakeLists.txt from Makefile of https://git.ffmpeg.org/gitweb/rtmpdump.git/blob/6f6bb1353fc84f4cc37138baa99f586750028a01:/librtmp/Makefile
cmake_minimum_required(VERSION 3.29)

project(librtmp C)
project(librtmp
VERSION ${VERSION}
DESCRIPTION "RTMP implementation"
HOMEPAGE_URL "http://rtmpdump.mplayerhq.hu"
LANGUAGES C
)
set(LIBRTMP_SO_VERSION ${LIBRTMP_SO_VERSION})

find_package(ZLIB REQUIRED)
find_package(OpenSSL REQUIRED)
# options switch `LIBRTMP_CRYPTO` and string `LIBRTMP_SSL` of "NOSSL;POLARSSL;OPENSSL;GNUTLS"
option(LIBRTMP_CRYPTO "" ON)
if(LIBRTMP_CRYPTO)
set(LIBRTMP_SSL "OPENSSL" CACHE STRING "")
set(LIBRTMP_SSL_ITEMS "NOSSL" "POLARSSL" "OPENSSL" "GNUTLS")
set_property(CACHE LIBRTMP_SSL PROPERTY STRINGS ${LIBRTMP_SSL_ITEMS})
if(NOT LIBRTMP_SSL IN_LIST LIBRTMP_SSL_ITEMS)
message(FATAL_ERROR "String option LIBRTMP_SSL must be one of ${LIBRTMP_SSL_ITEMS}")
endif()
endif()

include_directories(${ZLIB_INCLUDE_DIRS})
include_directories(${CMAKE_CURRENT_SOURCE_DIR})
# target librtmp
set(librtmp_target "librtmp")
add_library(${librtmp_target})
set_target_properties(${librtmp_target} PROPERTIES VERSION ${PROJECT_VERSION} SOVERSION ${LIBRTMP_SO_VERSION})
if(WIN32)
target_sources(${librtmp_target} PRIVATE "librtmp.def")
endif()

set(CMAKE_DEBUG_POSTFIX "d")
# target librtmp_public
set(librtmp_public "librtmp_public")
add_library(${librtmp_public} INTERFACE)
target_compile_definitions(${librtmp_public} INTERFACE "RTMPDUMP_VERSION=\"${PROJECT_VERSION}\"")

if(MSVC)
add_definitions(-D_CRT_SECURE_NO_DEPRECATE)
add_definitions(-D_CRT_NONSTDC_NO_DEPRECATE)
add_definitions(-D_WINSOCK_DEPRECATED_NO_WARNINGS)
endif()
# target librtmp_local
set(librtmp_local "librtmp_local")
add_library(${librtmp_local} INTERFACE)
target_compile_definitions(${librtmp_local} INTERFACE "LIBRTMP_ONLY")

add_definitions(-DLIBRTMP_ONLY)

# List the header files
set(HEADERS librtmp/amf.h
librtmp/bytes.h
librtmp/dh.h
librtmp/dhgroups.h
librtmp/handshake.h
librtmp/http.h
librtmp/log.h
librtmp/rtmp.h
librtmp/rtmp_sys.h
)
# target librtmp_transitive
set(librtmp_transitive "librtmp_transitive")
add_library(${librtmp_transitive} INTERFACE)

# List the source files
set(SRCS librtmp/amf.c
librtmp/hashswf.c
librtmp/log.c
librtmp/parseurl.c
librtmp/rtmp.c
)
# dependency zlib
find_package(ZLIB REQUIRED)
target_link_libraries(${librtmp_transitive} INTERFACE ZLIB::ZLIB)

if(MSVC)
set(SRCS_MSVC "librtmp/librtmp.def")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /wd4996")
# dependency crypto
if(NOT LIBRTMP_CRYPTO)
target_compile_definitions(${librtmp_public} INTERFACE "NO_CRYPTO")
else()
if(LIBRTMP_SSL STREQUAL "OPENSSL")
target_compile_definitions(${librtmp_public} INTERFACE "USE_OPENSSL")
find_package(OpenSSL CONFIG REQUIRED)
target_link_libraries(${librtmp_transitive} INTERFACE OpenSSL::SSL OpenSSL::Crypto)
else()
message(FATAL_ERROR "Unsupported LIBRTMP_SSL: ${LIBRTMP_SSL}")
endif()
endif()

add_library(rtmp ${SRCS} ${HEADERS} ${SRCS_MSVC})

target_include_directories(rtmp PRIVATE ./librtmp)
target_link_libraries(rtmp PRIVATE ${ZLIB_LIBRARIES} ${OPENSSL_LIBRARIES})
if(MSVC OR MINGW)
target_link_libraries(rtmp PRIVATE Ws2_32.lib Winmm.lib)
# dependency system
if(WIN32)
target_link_libraries(${librtmp_transitive} INTERFACE ws2_32 winmm)
endif()

set(libdir [[${prefix}/lib]])
set(VERSION 2.6) # from ChangeLog
set(CRYPTO_REQ "libssl,libcrypto")
if(MSVC OR MINGW)
set(PRIVATE_LIBS "-lWS2_32 -lWinMM")
# target objects
set(librtmp_obj_list "log" "rtmp" "amf" "hashswf" "parseurl")
add_library(log OBJECT)
target_sources(log PRIVATE "log.c" PUBLIC FILE_SET HEADERS FILES "log.h")
add_library(rtmp OBJECT)
target_sources(rtmp PRIVATE "rtmp.c" PUBLIC FILE_SET HEADERS FILES "rtmp.h" "rtmp_sys.h" "handshake.h" "dh.h" "log.h" "amf.h")
add_library(amf OBJECT)
target_sources(amf PRIVATE "amf.c" PUBLIC FILE_SET HEADERS FILES "amf.h" "bytes.h" "log.h")
add_library(hashswf OBJECT)
target_sources(hashswf PRIVATE "hashswf.c" PUBLIC FILE_SET HEADERS FILES "http.h" "rtmp.h" "rtmp_sys.h")
add_library(parseurl OBJECT)
target_sources(parseurl PRIVATE "parseurl.c" PUBLIC FILE_SET HEADERS FILES "rtmp.h" "rtmp_sys.h" "log.h")

# link
foreach(obj IN LISTS librtmp_obj_list)
target_link_libraries(${obj} PUBLIC ${librtmp_public} PRIVATE ${librtmp_transitive} $<BUILD_LOCAL_INTERFACE:${librtmp_local}>)
endforeach()
target_link_libraries(${librtmp_target} PUBLIC ${librtmp_obj_list})

# === Install ===

# install settings
include(GNUInstallDirs)
set(librtmp_package_name "unofficial-librtmp")
set(librtmp_namespace "unofficial::librtmp::")
set(librtmp_target_list "${librtmp_target};${librtmp_obj_list};${librtmp_public};${librtmp_transitive}")
set(librtmp_export_targets "librtmp-targets")
set(librtmp_install_include "${CMAKE_INSTALL_INCLUDEDIR}/librtmp")
set(librtmp_install_share "${CMAKE_INSTALL_DATAROOTDIR}/${librtmp_package_name}")
set(librtmp_config_filename "${librtmp_package_name}-config.cmake")
set(librtmp_config_template_path "${CMAKE_CURRENT_BINARY_DIR}/Config.cmake.in")

# install targets
install(TARGETS ${librtmp_target_list}
EXPORT "${librtmp_export_targets}"
FILE_SET HEADERS DESTINATION "${librtmp_install_include}"
)

install(EXPORT "${librtmp_export_targets}"
NAMESPACE "${librtmp_namespace}"
DESTINATION "${librtmp_install_share}"
)

# generate configs
file(WRITE "${librtmp_config_template_path}"
[[@PACKAGE_INIT@
set(LIBRTMP_CRYPTO @LIBRTMP_CRYPTO@)
set(LIBRTMP_SSL @LIBRTMP_SSL@)
include(CMakeFindDependencyMacro)
find_dependency(ZLIB REQUIRED)
if(LIBRTMP_CRYPTO AND LIBRTMP_SSL STREQUAL "OPENSSL")
find_dependency(OpenSSL CONFIG REQUIRED)
endif()
configure_file(librtmp/librtmp.pc.in librtmp.pc @ONLY)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/librtmp.pc
DESTINATION lib/pkgconfig
include("${CMAKE_CURRENT_LIST_DIR}/@[email protected]")
]]
)
include(CMakePackageConfigHelpers)
configure_package_config_file("${librtmp_config_template_path}"
"${librtmp_config_filename}"
INSTALL_DESTINATION "${librtmp_install_share}"
)

install(TARGETS rtmp
RUNTIME DESTINATION bin
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib)
# install configs
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/${librtmp_config_filename}" DESTINATION "${librtmp_install_share}")

install(DIRECTORY ${PROJECT_SOURCE_DIR}/librtmp DESTINATION include FILES_MATCHING PATTERN "*.h")
# install man
install(FILES "librtmp.3" "librtmp.3.html" DESTINATION "${CMAKE_INSTALL_MANDIR}/man3")
38 changes: 26 additions & 12 deletions ports/librtmp/portfile.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,37 @@ vcpkg_from_github(
fix_strncasecmp.patch
hide_netstackdump.patch
pkgconfig.patch
0006-typedef-off_t.diff
)

file(COPY "${CMAKE_CURRENT_LIST_DIR}/CMakeLists.txt" DESTINATION "${SOURCE_PATH}")
file(COPY "${CMAKE_CURRENT_LIST_DIR}/librtmp.def" DESTINATION "${SOURCE_PATH}/librtmp")
file(COPY
"${CMAKE_CURRENT_LIST_DIR}/CMakeLists.txt"
"${CMAKE_CURRENT_LIST_DIR}/librtmp.def"
DESTINATION "${SOURCE_PATH}/librtmp"
)

vcpkg_cmake_configure(
SOURCE_PATH "${SOURCE_PATH}"
vcpkg_check_features(OUT_FEATURE_OPTIONS FEATURE_OPTIONS
FEATURES
crypto LIBRTMP_CRYPTO
)
if(LIBRTMP_CRYPTO)
list(APPEND FEATURE_OPTIONS "-DLIBRTMP_SSL=OPENSSL")
endif()

vcpkg_cmake_install()
vcpkg_fixup_pkgconfig()
include(CMakePrintHelpers)
cmake_print_variables(FEATURE_OPTIONS)
vcpkg_cmake_configure(SOURCE_PATH "${SOURCE_PATH}/librtmp"
OPTIONS
-DVERSION=2.3
-DLIBRTMP_SO_VERSION=1
${FEATURE_OPTIONS}
)

file(REMOVE_RECURSE "${CURRENT_PACKAGES_DIR}/debug/include")
vcpkg_cmake_install()
vcpkg_copy_pdbs()

# License and man
file(INSTALL "${SOURCE_PATH}/librtmp/COPYING" DESTINATION "${CURRENT_PACKAGES_DIR}/share/${PORT}" RENAME copyright)
file(COPY "${CURRENT_PORT_DIR}/usage" DESTINATION "${CURRENT_PACKAGES_DIR}/share/${PORT}")
file(INSTALL "${SOURCE_PATH}/librtmp/librtmp.3.html" DESTINATION "${CURRENT_PACKAGES_DIR}/share/${PORT}")
vcpkg_cmake_config_fixup(PACKAGE_NAME "unofficial-librtmp")
file(REMOVE_RECURSE "${CURRENT_PACKAGES_DIR}/debug/include" "${CURRENT_PACKAGES_DIR}/debug/share")

vcpkg_copy_pdbs()
configure_file("${CMAKE_CURRENT_LIST_DIR}/usage" "${CURRENT_PACKAGES_DIR}/share/${PORT}/usage")
vcpkg_install_copyright(FILE_LIST "${SOURCE_PATH}/librtmp/COPYING")
9 changes: 4 additions & 5 deletions ports/librtmp/usage
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
librtmp can be imported via CMake FindPkgConfig module:

find_package(PkgConfig REQUIRED)
pkg_check_modules(librtmp REQUIRED IMPORTED_TARGET librtmp)
target_link_libraries(main PkgConfig::librtmp)
@PORT@ provides CMake targets:

find_package(unofficial-librtmp CONFIG REQUIRED)
target_link_libraries(main PRIVATE unofficial::librtmp::librtmp)
20 changes: 18 additions & 2 deletions ports/librtmp/vcpkg.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,30 @@
{
"name": "librtmp",
"version-date": "2024-03-01",
"port-version": 1,
"description": "RTMPDump Real-Time Messaging Protocol API",
"homepage": "https://rtmpdump.mplayerhq.hu",
"license": "LGPL-2.1-only",
"dependencies": [
"openssl",
{
"name": "vcpkg-cmake",
"host": true
},
{
"name": "vcpkg-cmake-config",
"host": true
},
"zlib"
]
],
"default-features": [
"crypto"
],
"features": {
"crypto": {
"description": "Build librtmp with CRYPTO and SSL support",
"dependencies": [
"openssl"
]
}
}
}
7 changes: 1 addition & 6 deletions scripts/test_ports/vcpkg-ci-curl/vcpkg.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,12 @@
"homepage": "https://github.com/microsoft/vcpkg",
"license": "MIT",
"dependencies": [
{
"name": "curl",
"features": [
"idn"
]
},
{
"name": "curl",
"features": [
"c-ares",
"http2",
"idn",
"zstd"
]
},
Expand Down
4 changes: 2 additions & 2 deletions versions/baseline.json
Original file line number Diff line number Diff line change
Expand Up @@ -2122,7 +2122,7 @@
},
"curl": {
"baseline": "8.11.1",
"port-version": 0
"port-version": 1
},
"curlcpp": {
"baseline": "3.1",
Expand Down Expand Up @@ -5058,7 +5058,7 @@
},
"librtmp": {
"baseline": "2024-03-01",
"port-version": 0
"port-version": 1
},
"librtpi": {
"baseline": "1.0.1",
Expand Down
Loading

0 comments on commit 389df00

Please sign in to comment.