From 45aa41df2e393e77df5808e1e7a8864e70184c6f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miko=C5=82aj=20Ma=C5=82ecki?= Date: Mon, 2 Oct 2023 14:04:15 +0200 Subject: [PATCH 1/3] Added macros resolved in srt.h to pkg-config file --- CMakeLists.txt | 25 +++++++++++++++++++++++++ scripts/srt.pc.in | 2 +- 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 4611f0ca2..db26d3cd9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -83,6 +83,27 @@ endif() message(STATUS "BUILD TYPE: ${CMAKE_BUILD_TYPE}") +set (SRT_FIXED_DEFINES + ENABLE_BONDING + ENABLE_AEAD_API_PREVIEW + ENABLE_MAXREXMITBW) + +set (PKGCONFIG_ADD_DEFINES "") + +macro (CheckFixedDefines defname) + # We only support boolean enabler flags + # Pity no IN_LIST operator available in 2.18 + # The same can be achieved here by using the searched + # macro name as a regex expression + string(REGEX MATCH ${defname} CheckFixedDefines_DEFNAME ${SRT_FIXED_DEFINES}) + if (${defname} STREQUAL ${CheckFixedDefines_DEFNAME}) + string(APPEND PKGCONFIG_ADD_DEFINES " -D${defname}=1") + endif() +endmacro () + +# Since now, every flag that is normally added as "compile definitions" and +# is found in this pool, must be pasted into PKGCONFIG_ADD_DEFINES + getVarsWith(ENFORCE_ enforcers) foreach(ef ${enforcers}) set (val ${${ef}}) @@ -95,6 +116,7 @@ foreach(ef ${enforcers}) string(SUBSTRING ${ef} ${pflen} ${alen} ef) message(STATUS "FORCED PP VARIABLE: ${ef}${val}") add_definitions(-D${ef}${val}) + CheckFixedDefines(${ef}) endforeach() # NOTE: Known options you can change using ENFORCE_ variables: @@ -488,6 +510,7 @@ if (ENABLE_ENCRYPTION) if (ENABLE_AEAD_API_PREVIEW) if (("${USE_ENCLIB}" STREQUAL "openssl-evp") OR ("${USE_ENCLIB}" STREQUAL "botan")) add_definitions(-DENABLE_AEAD_API_PREVIEW) + CheckFixedDefines("ENABLE_AEAD_API_PREVIEW") message(STATUS "ENCRYPTION AEAD API: ENABLED") else() message(FATAL_ERROR "ENABLE_AEAD_API_PREVIEW is only available with USE_ENCLIB=[openssl-evp | botan]!") @@ -510,6 +533,7 @@ endif() if (ENABLE_MAXREXMITBW) add_definitions(-DENABLE_MAXREXMITBW) + CheckFixedDefines("ENABLE_MAXREXMITBW") message(STATUS "MAXREXMITBW API: ENABLED") else() message(STATUS "MAXREXMITBW API: DISABLED") @@ -823,6 +847,7 @@ endif() if (ENABLE_BONDING) list(APPEND SRT_EXTRA_CFLAGS "-DENABLE_BONDING=1") + CheckFixedDefines("ENABLE_BONDING") message(STATUS "ENABLE_BONDING: ON") else() message(STATUS "ENABLE_BONDING: OFF") diff --git a/scripts/srt.pc.in b/scripts/srt.pc.in index 98d1e0997..0b92cb6bc 100644 --- a/scripts/srt.pc.in +++ b/scripts/srt.pc.in @@ -8,5 +8,5 @@ Description: SRT library set Version: @SRT_VERSION@ Libs: -L${libdir} -l@TARGET_srt@ @IFNEEDED_LINK_HAICRYPT@ @IFNEEDED_SRTBASE@ @IFNEEDED_SRT_LDFLAGS@ Libs.private: @SRT_LIBS_PRIVATE@ -Cflags: -I${includedir} -I${includedir}/srt +Cflags: -I${includedir} -I${includedir}/srt @PKGCONFIG_ADD_DEFINES@ Requires.private: @SSL_REQUIRED_MODULES@ From 2d88093b66f7b2d27817b0111be1eb462fbf098a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miko=C5=82aj=20Ma=C5=82ecki?= Date: Wed, 4 Oct 2023 18:48:24 +0200 Subject: [PATCH 2/3] Added ability to add configuration macros to version.h file --- CMakeLists.txt | 33 ++++++++++++++++++++++++++------- srtcore/srt.h | 14 ++++++++++++++ srtcore/version.h.in | 2 ++ 3 files changed, 42 insertions(+), 7 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index db26d3cd9..49b0c1a74 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -88,7 +88,8 @@ set (SRT_FIXED_DEFINES ENABLE_AEAD_API_PREVIEW ENABLE_MAXREXMITBW) -set (PKGCONFIG_ADD_DEFINES "") +set (SRT_CONFIG_ADD_DEFINES SRT_CONFIG_PROVIDED) +set (SRT_CONFIG_DEFINES "") macro (CheckFixedDefines defname) # We only support boolean enabler flags @@ -97,7 +98,7 @@ macro (CheckFixedDefines defname) # macro name as a regex expression string(REGEX MATCH ${defname} CheckFixedDefines_DEFNAME ${SRT_FIXED_DEFINES}) if (${defname} STREQUAL ${CheckFixedDefines_DEFNAME}) - string(APPEND PKGCONFIG_ADD_DEFINES " -D${defname}=1") + list(APPEND SRT_CONFIG_ADD_DEFINES ${defname}) endif() endmacro () @@ -153,14 +154,17 @@ elseif (POSIX) test_requires_clock_gettime(ENABLE_MONOTONIC_CLOCK_DEFAULT MONOTONIC_CLOCK_LINKLIB) endif() +set (ENABLE_CXX11_DEFAULT ON) +if (CMAKE_CXX_COMPILER_ID MATCHES "^GNU$" AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.7) + set (ENABLE_CXX11_DEFAULT OFF) +endif() + + # options option(CYGWIN_USE_POSIX "Should the POSIX API be used for cygwin. Ignored if the system isn't cygwin." OFF) -if (CMAKE_CXX_COMPILER_ID MATCHES "^GNU$" AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.7) - option(ENABLE_CXX11 "Should the c++11 parts (srt-live-transmit) be enabled" OFF) -else() - option(ENABLE_CXX11 "Should the c++11 parts (srt-live-transmit) be enabled" ON) -endif() +option(ENABLE_CXX11 "Should the c++11 parts (srt-live-transmit) be enabled" ${ENABLE_CXX11_DEFAULT}) +option(ENABLE_CONFIG_HEADER "Should the build configuration macros be placed in the version.h file" OFF) option(ENABLE_APPS "Should the Support Applications be Built?" ON) option(ENABLE_BONDING "Should the bonding functionality be enabled?" OFF) option(ENABLE_TESTING "Should the Developer Test Applications be Built?" OFF) @@ -201,6 +205,10 @@ endif() set(TARGET_srt "srt" CACHE STRING "The name for the SRT library") +# Declare that the config is known when compiling SRT itself and +# also all libraries. +add_definitions(-DSRT_CONFIG_PROVIDED) + # Use application-defined group reader # (currently the only one implemented) add_definitions(-DSRT_ENABLE_APP_READER) @@ -1031,6 +1039,14 @@ if(DEFINED ENV{TEAMCITY_VERSION}) message(STATUS "TeamCity build environment detected: Adding build counter to version header") endif() +if (ENABLE_CONFIG_HEADER) + set (SRT_CONFIG_DEFINES "") + foreach (def ${SRT_CONFIG_ADD_DEFINES}) + string(APPEND SRT_CONFIG_DEFINES "#define ${def} 1 +") + endforeach() +endif() + configure_file("srtcore/version.h.in" "version.h" @ONLY) list(INSERT HEADERS_srt 0 "${CMAKE_CURRENT_BINARY_DIR}/version.h") @@ -1266,6 +1282,9 @@ endif() join_arguments(SRT_LIBS_PRIVATE ${SRT_LIBS_PRIVATE}) if (DEFINED CMAKE_INSTALL_LIBDIR) + foreach(def ${SRT_CONFIG_ADD_DEFINES}) + string(APPEND PKGCONFIG_ADD_DEFINES " -D${def}=1") + endforeach() # haisrt.pc left temporarily for backward compatibility. To be removed in future! configure_file(scripts/srt.pc.in haisrt.pc @ONLY) install(FILES ${CMAKE_CURRENT_BINARY_DIR}/haisrt.pc DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig) diff --git a/srtcore/srt.h b/srtcore/srt.h index 53b6fd274..af67dad36 100644 --- a/srtcore/srt.h +++ b/srtcore/srt.h @@ -25,6 +25,20 @@ written by #include "logging_api.h" +#ifndef SRT_CONFIG_PROVIDED + +// If you see this error, it means that your compile command was compiling a file +// that does #include , but the usage is incorrect. You need to do either +// of two things: +// - Use ENABLE_CONFIG_HEADER option (-DENABLE_CONFIG_HEADER=ON in cmake), in which case +// the macros used for compiling will be provided in the generated version.h file +// - The compile command must contain flags obtained by `pkg-config --cflags srt` that +// will contain appropriate macro defines that are used according to the configuration +// of the SRT library. +#error "Build configuration unknown. Use 'pkg-config --cflags srt' to obtain the required compile flags or use ENABLE_CONFIG_HEADER build option" + +#endif + //////////////////////////////////////////////////////////////////////////////// //if compiling on VC6.0 or pre-WindowsXP systems diff --git a/srtcore/version.h.in b/srtcore/version.h.in index c32ac1226..1fcbe6220 100644 --- a/srtcore/version.h.in +++ b/srtcore/version.h.in @@ -31,4 +31,6 @@ written by SRT_MAKE_VERSION_VALUE( \ SRT_VERSION_MAJOR, SRT_VERSION_MINOR, SRT_VERSION_PATCH ) +@SRT_CONFIG_DEFINES@ + #endif // INC_SRT_VERSION_H From ee27aa9a71c0765b0ff4c470983c2706e558415e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miko=C5=82aj=20Ma=C5=82ecki?= Date: Wed, 4 Oct 2023 19:27:08 +0200 Subject: [PATCH 3/3] Added forcefully placement of the macros in version.h for systems that do not use pkg-config --- CMakeLists.txt | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 49b0c1a74..9c05f8426 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -44,6 +44,7 @@ set_if(SUNOS "${SYSNAME_LC}" MATCHES "sunos") set_if(POSIX LINUX OR DARWIN OR BSD OR SUNOS OR ANDROID OR (CYGWIN AND CYGWIN_USE_POSIX)) set_if(SYMLINKABLE LINUX OR DARWIN OR BSD OR SUNOS OR CYGWIN OR GNU) set_if(NEED_DESTINATION ${CMAKE_VERSION} VERSION_LESS "3.14.0") +set_if(PKG_CONFIG_CAPABLE LINUX OR GNU OR SUNOS OR BSD) include(GNUInstallDirs) @@ -160,7 +161,6 @@ if (CMAKE_CXX_COMPILER_ID MATCHES "^GNU$" AND CMAKE_CXX_COMPILER_VERSION VERSION endif() - # options option(CYGWIN_USE_POSIX "Should the POSIX API be used for cygwin. Ignored if the system isn't cygwin." OFF) option(ENABLE_CXX11 "Should the c++11 parts (srt-live-transmit) be enabled" ${ENABLE_CXX11_DEFAULT}) @@ -203,6 +203,16 @@ if (ATOMIC_USE_SRT_SYNC_MUTEX) add_definitions(-DATOMIC_USE_SRT_SYNC_MUTEX=1) endif() +# Postfix: ENABLE_CONFIG_HEADER must be forcefully turned on on build systems +# that do not utilize pkg-config. + +if (NOT PKG_CONFIG_CAPABLE) + if (NOT ENABLE_CONFIG_HEADER) + message(INFO "Configuration forcefully placed in version.h file as this platform doesn't feature pkg-config.") + endif() + set (ENABLE_CONFIG_HEADER ON) +endif() + set(TARGET_srt "srt" CACHE STRING "The name for the SRT library") # Declare that the config is known when compiling SRT itself and