From 61e01510c25488a5fabf30d9899c2555b4f87a6d Mon Sep 17 00:00:00 2001 From: Jose Santiago Date: Wed, 24 Oct 2018 16:30:42 -0500 Subject: [PATCH] Fix SRT Private libraries allow for the applications to be linked against the correct C++ runtime library used by the toolchain. For instance OSX, Linux, *BSD, and others can use the LIBC++ runtime library instead of the GNUSTDC++ library. The latest OSX uses releases use LIBC++ and require it for C++11 and later support. --- CMakeLists.txt | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index b1b0a86c5..933895de0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -85,7 +85,7 @@ option(ENABLE_STATIC "Should libsrt be built as a static library" ON) option(ENABLE_SUFLIP "Should suflip tool be built" OFF) option(ENABLE_GETNAMEINFO "In-logs sockaddr-to-string should do rev-dns" OFF) option(USE_GNUTLS "Should use gnutls instead of openssl" OFF) -option(ENABLE_C_DEPS "Extra library dependencies in srt.pc for C language" OFF) +option(ENABLE_CXX_DEPS "Extra library dependencies in srt.pc for the CXX libraries useful with C language" ON) option(USE_STATIC_LIBSTDCXX "Should use static rather than shared libstdc++" OFF) set(TARGET_srt "srt" CACHE STRING "The name for the haisrt library") @@ -500,7 +500,7 @@ target_include_directories(haicrypt_virtual PRIVATE ${SSL_INCLUDE_DIRS}) if (MICROSOFT) set (SRT_LIBS_PRIVATE ${SRT_LIBS_PRIVATE} ws2_32.lib) elseif (MINGW) - set (SRT_LIBS_PRIVATE ${SRT_LIBS_PRIVATE} -lwsock32 -lws2_32 -lstdc++) + set (SRT_LIBS_PRIVATE ${SRT_LIBS_PRIVATE} -lwsock32 -lws2_32) endif() # --- @@ -575,19 +575,18 @@ if (NOT DEFINED INSTALLDIR) get_filename_component(INSTALLDIR ${INSTALLDIR} ABSOLUTE) endif() -# XXX -# These two flags are required if compiling a C application -# The problem is that pkg-config cannot return flags that are -# suitable for C or C++ only - just "cflags", and for C by default. +# Required if linking a C application. # This may cause trouble when you want to compile your app with static libstdc++; # if your build requires it, you'd probably remove -lstdc++ from the list # obtained by `pkg-config --libs`. -# -# Some sensible solution for that is desired. Currently turned on only on demand. -if (ENABLE_C_DEPS) -if ( LINUX ) - set (IFNEEDED_SRT_LDFLAGS "-lstdc++ -lm") -endif() +if(ENABLE_CXX_DEPS) + foreach(LIB ${CMAKE_CXX_IMPLICIT_LINK_LIBRARIES}) + if(IS_ABSOLUTE ${LIB} AND EXISTS ${LIB}) + set(SRT_LIBS_PRIVATE ${SRT_LIBS_PRIVATE} ${LIB}) + else() + set(SRT_LIBS_PRIVATE ${SRT_LIBS_PRIVATE} "-l${LIB}") + endif() + endforeach() endif() join_arguments(SRT_LIBS_PRIVATE ${SRT_LIBS_PRIVATE})