@@ -469,7 +469,7 @@ if ("${USE_CXX_STD_LIB}" EQUAL 98)
469469 # but on Windows we don't support non-C++11 compiling anymore.
470470 add_definitions (-DHVU_EXT_INCLUDE_SYNC= "../srtcore/srt_sync_cxx98.h" )
471471else ()
472- string (APPEND FEATURE_REPORT "LOGGER_SYNC=std " )
472+ string (APPEND FEATURE_REPORT "LOGGER_SYNC=c++ std " )
473473endif ()
474474
475475# add extra warning flags for gccish compilers
@@ -494,6 +494,7 @@ message(STATUS "WARNING OPTIONS: ${SRT_GCC_WARN}")
494494# --------------------------------------------
495495# Post-option variable synchronization
496496# and option-to-preprocessor-macro transition
497+ # (Optional features)
497498# --------------------------------------------
498499
499500# Global independet settings
@@ -525,34 +526,6 @@ if (NOT DEFINED SRT_LOG_SLOWDOWN_FREQ_MS)
525526endif ()
526527list (APPEND SRT_EXTRA_CFLAGS "-DSRT_LOG_SLOWDOWN_FREQ_MS=${SRT_LOG_SLOWDOWN_FREQ_MS} " )
527528
528- if (NOT ENABLE_STDCXX_SYNC)
529- if (ENABLE_MONOTONIC_CLOCK)
530- # Require monotonic clock, unless it's explicitly set OFF
531- list (PREPEND CMAKE_REQUIRED_LIBRARIES "${CMAKE_THREAD_LIBS_INIT} " )
532-
533- # Note: pthread_condattr_setclock doesn't exist on some systems, at least
534- # old versions of Android (__ANDROID_API__ < 21) are known to not provide it
535- check_symbol_exists (pthread_condattr_setclock "pthread.h" HAVE_PTHREAD_CONDATTR_SETCLOCK )
536- test_requires_clock_gettime (HAVE_MONOTONIC_CLOCK_GETTIME MONOTONIC_CLOCK_LINKLIB )
537- if (NOT HAVE_MONOTONIC_CLOCK_GETTIME OR NOT HAVE_PTHREAD_CONDATTR_SETCLOCK)
538- message (FATAL_ERROR "Your platform does not support CLOCK_MONOTONIC. Build with -DENABLE_MONOTONIC_CLOCK=OFF." )
539- endif ()
540- if (NOT MONOTONIC_CLOCK_LINKLIB STREQUAL "" )
541- set (WITH_EXTRALIBS "${WITH_EXTRALIBS} ${MONOTONIC_CLOCK_LINKLIB} " )
542- endif ()
543- add_definitions (-DSRT_ENABLE_MONOTONIC_CLOCK=1 )
544- string (APPEND FEATURE_REPORT "SYNC=POSIX CLOCK=MONOTONIC " )
545- message (STATUS "SYNC LIBRARY: POSIX, MONOTONIC CLOCK: ON" )
546- else ()
547- string (APPEND FEATURE_REPORT "SYNC=POSIX CLOCK=SYSTEM " )
548- message (WARNING
549- "ENABLE_MONOTONIC_CLOCK is OFF. This is dangerous.
550- SRT may malfunction, if the system time is changed during transmission." )
551- endif ()
552- else ()
553- string (APPEND FEATURE_REPORT "SYNC=C++std " )
554- endif ()
555-
556529if (USE_GNUSTL)
557530 pkg_check_modules (GNUSTL REQUIRED gnustl )
558531 link_directories (${GNUSTL_LIBRARY_DIRS} )
@@ -673,6 +646,7 @@ endif()
673646if (LINUX )
674647# This is an option supported only on Linux
675648 add_definitions (-DSRT_ENABLE_BINDTODEVICE )
649+ string (APPEND FEATURE_REPORT "BINDTODEVICE=ON " )
676650endif ()
677651
678652if (USE_STATIC_LIBSTDCXX)
@@ -698,20 +672,71 @@ else ()
698672 message (STATUS "Threads: cmake-default: ${PTHREAD_LIBRARY} " )
699673endif ()
700674
701- # To avoid the need for other judgments when ENABLE_STDCXX_SYNC is OFF in the future, this is a separate conditional statement.
702- if (NOT ENABLE_STDCXX_SYNC AND ENABLE_MONOTONIC_CLOCK)
675+ # Check the feature of PTHREAD providing pthread_atfork function.
676+ # Regardless of the current thread support library, this is a function
677+ # called as a callback at fork() call. This is required so that SRT
678+ # library can be used with applications that do fork().
679+
680+ if (NOT MICROSOFT AND NOT MINGW)
681+ # Do not enforce pthread library in case of MICROSOFT
682+ # because it dosn't need fork() support (even if someone
683+ # might want to try to compile for Windows with pthreads).
684+
703685 list (PREPEND CMAKE_REQUIRED_LIBRARIES "${PTHREAD_LIBRARY} " )
704686 unset (CMAKE_REQUIRED_QUIET)
705- check_symbol_exists (pthread_condattr_setclock "pthread.h" HAVE_PTHREAD_CONDATTR_SETCLOCK )
706- message (STATUS "Checking pthread_condattr_setclock: '${HAVE_PTHREAD_CONDATTR_SETCLOCK} '" )
707- if ("${HAVE_PTHREAD_CONDATTR_SETCLOCK} " STREQUAL "1" )
708- string (APPEND FEATURE_REPORT "PTHREAD_COND_CLOCK=monotonic " )
709- add_definitions (-DHAVE_PTHREAD_CONDATTR_SETCLOCK=1 )
710- else ()
711- string (APPEND FEATURE_REPORT "PTHREAD_COND_CLOCK=system " )
712- message (WARNING "NOT FOUND pthread_cond_timedwait. pthread_cond_timedwait will use system clock. Recommended -DENABLE_STDCXX_SYNC=ON" )
687+
688+ check_symbol_exists (pthread_atfork "pthread.h" HAVE_PTHREAD_ATFORK )
689+ if ("${HAVE_PTHREAD_ATFORK} " STREQUAL "1" )
690+ add_definitions (-DHAVE_PTHREAD_ATFORK=1 )
691+ string (APPEND FEATURE_REPORT "ATFORK=ON " )
713692 endif ()
714- endif ()
693+ endif ()
694+
695+ if (NOT ENABLE_STDCXX_SYNC)
696+ if (ENABLE_MONOTONIC_CLOCK)
697+ # Require monotonic clock, unless it's explicitly set OFF
698+ list (PREPEND CMAKE_REQUIRED_LIBRARIES "${CMAKE_THREAD_LIBS_INIT} " )
699+
700+ # Note: pthread_condattr_setclock doesn't exist on some systems, at least
701+ # old versions of Android (__ANDROID_API__ < 21) are known to not provide it
702+ check_symbol_exists (pthread_condattr_setclock "pthread.h" HAVE_PTHREAD_CONDATTR_SETCLOCK )
703+ test_requires_clock_gettime (HAVE_MONOTONIC_CLOCK_GETTIME MONOTONIC_CLOCK_LINKLIB )
704+ if (NOT HAVE_MONOTONIC_CLOCK_GETTIME OR NOT HAVE_PTHREAD_CONDATTR_SETCLOCK)
705+ message (FATAL_ERROR "Your platform does not support CLOCK_MONOTONIC. Build with -DENABLE_MONOTONIC_CLOCK=OFF." )
706+ endif ()
707+ if (NOT MONOTONIC_CLOCK_LINKLIB STREQUAL "" )
708+ set (WITH_EXTRALIBS "${WITH_EXTRALIBS} ${MONOTONIC_CLOCK_LINKLIB} " )
709+ endif ()
710+ add_definitions (-DSRT_ENABLE_MONOTONIC_CLOCK=1 )
711+ string (APPEND FEATURE_REPORT "SYNC=POSIX CLOCK=monotonic " )
712+ message (STATUS "SYNC LIBRARY: POSIX, MONOTONIC CLOCK: ON" )
713+
714+ # Add-unique not supported in cmake, use unload version
715+ list (FIND CMAKE_REQUIRED_QUIET "${PTHREAD_LIBRARY} " HAVE_ALREADY)
716+ if (NOT HAVE_ALREADY)
717+ list (PREPEND CMAKE_REQUIRED_LIBRARIES "${PTHREAD_LIBRARY} " )
718+ endif ()
719+ unset (CMAKE_REQUIRED_QUIET)
720+ check_symbol_exists (pthread_condattr_setclock "pthread.h" HAVE_PTHREAD_CONDATTR_SETCLOCK )
721+ message (STATUS "Checking pthread_condattr_setclock: '${HAVE_PTHREAD_CONDATTR_SETCLOCK} '" )
722+ if ("${HAVE_PTHREAD_CONDATTR_SETCLOCK} " STREQUAL "1" )
723+ string (APPEND FEATURE_REPORT "PTHREAD_COND_CLOCK=monotonic " )
724+ add_definitions (-DHAVE_PTHREAD_CONDATTR_SETCLOCK=1 )
725+ else ()
726+ string (APPEND FEATURE_REPORT "PTHREAD_COND_CLOCK=system " )
727+ message (WARNING "NOT FOUND pthread_cond_timedwait. pthread_cond_timedwait will use system clock. Recommended -DENABLE_STDCXX_SYNC=ON" )
728+ endif ()
729+
730+ else ()
731+ string (APPEND FEATURE_REPORT "SYNC=POSIX CLOCK=SYSTEM PTHREAD_COND_CLOCK=system " )
732+ message (WARNING
733+ "ENABLE_MONOTONIC_CLOCK is OFF. This is dangerous.
734+ SRT may malfunction, if the system time is changed during transmission." )
735+ endif ()
736+ else ()
737+ string (APPEND FEATURE_REPORT "SYNC=C++std " )
738+ endif ()
739+
715740
716741# When you use crosscompiling, you have to take care that PKG_CONFIG_PATH
717742# and CMAKE_PREFIX_PATH are set properly.
0 commit comments