diff --git a/CMakeLists.txt b/CMakeLists.txt index 7e32b69b..bf54bd78 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -143,25 +143,25 @@ if(CMAKE_COMPILER_IS_GNUCXX OR ${CMAKE_CXX_COMPILER_ID} MATCHES Clang) add_definitions(-Wall -Werror=return-type -Werror=unused-result -Werror=reorder) endif() -set(THREADS_PREFER_PTHREAD_FLAG TRUE) find_package(Threads REQUIRED) -include(CheckCXXSymbolExists) -check_cxx_symbol_exists(_LIBCPP_VERSION cstdlib HAVE_LIBCPP) # Build Libs.private contents for libde265.pc. set(_libs_private "") -if(NOT MSVC) - if(HAVE_LIBCPP) - list(APPEND _libs_private "-lc++") +foreach(lib IN LISTS CMAKE_CXX_IMPLICIT_LINK_LIBRARIES) + if(lib IN_LIST CMAKE_C_IMPLICIT_LINK_LIBRARIES) + continue() + elseif(EXISTS "${lib}") + list(APPEND _libs_private "${lib}") else() - list(APPEND _libs_private "-lstdc++") + list(APPEND _libs_private "-l${lib}") endif() -endif() +endforeach() + # Emit '-lpthread' rather than '-pthread' so consumers using # `pkg-config --libs --static` get an unambiguous linker flag (see #453). if(CMAKE_USE_PTHREADS_INIT) - list(APPEND _libs_private "-lpthread") + list(APPEND _libs_private "${CMAKE_THREAD_LIBS_INIT}") endif() if(UNIX) list(APPEND _libs_private "-lm")