diff --git a/CMakeLists.txt b/CMakeLists.txt --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -118,13 +118,16 @@ if(CMAKE_COMPILER_IS_GNUCXX OR ${CMAKE_CXX_COMPILER_ID} MATCHES Clang) add_definitions(-Wall -Werror=return-type -Werror=unused-result -Werror=reorder) endif() -include(CheckCXXSymbolExists) -check_cxx_symbol_exists(_LIBCPP_VERSION cstdlib HAVE_LIBCPP) -if(HAVE_LIBCPP) - set(LIBS_PRIVATE "-lc++") -else() - set(LIBS_PRIVATE "-lstdc++") -endif() +set(LIBS_PRIVATE "") +foreach(lib IN LISTS CMAKE_CXX_IMPLICIT_LINK_LIBRARIES) + if(lib IN_LIST CMAKE_C_IMPLICIT_LINK_LIBRARIES) + continue() + elseif(EXISTS "${lib}") + string(APPEND LIBS_PRIVATE " ${CMAKE_LINK_LIBRARY_FILE_FLAG}${lib}") + else() + string(APPEND LIBS_PRIVATE " ${CMAKE_LINK_LIBRARY_FLAG}${lib}") + endif() +endforeach() option(BUILD_SHARED_LIBS "Build shared library" ON)