Index: cmake/Modules/HandleLibcxxFlags.cmake =================================================================== --- cmake/Modules/HandleLibcxxFlags.cmake +++ cmake/Modules/HandleLibcxxFlags.cmake @@ -196,6 +196,29 @@ endforeach() endmacro() +# Attempt to detect the correct compiler runtime library and add it +# to 'LIBCXX_LIBRARIES'. Fall back to gcc_s if available. +macro(add_libgcc_library) + # split space-separated vars into a list + set(libgcc_cmd ${CMAKE_C_COMPILER} + ${CMAKE_SHARED_LIBRARY_CXX_FLAGS} + ${CMAKE_CXX_FLAGS} + ${CMAKE_SHARED_LINKER_FLAGS} + -print-libgcc-file-name) + + execute_process( + COMMAND "${libgcc_cmd}" + RESULT_VARIABLE libgcc_check_ret + OUTPUT_VARIABLE libgcc_path + OUTPUT_STRIP_TRAILING_WHITESPACE) + + if (${libgcc_check_ret} EQUAL 0) + add_library_flags("${libgcc_path}") + else() + add_library_flags_if(LIBCXX_HAS_GCC_S_LIB gcc_s) + endif() +endmacro() + # Turn a comma separated CMake list into a space separated string. macro(split_list listname) string(REPLACE ";" " " ${listname} "${${listname}}") Index: lib/CMakeLists.txt =================================================================== --- lib/CMakeLists.txt +++ lib/CMakeLists.txt @@ -83,7 +83,7 @@ add_library_flags_if(LIBCXX_HAS_C_LIB c) add_library_flags_if(LIBCXX_HAS_M_LIB m) add_library_flags_if(LIBCXX_HAS_RT_LIB rt) -add_library_flags_if(LIBCXX_HAS_GCC_S_LIB gcc_s) +add_libgcc_library() add_library_flags_if(LIBCXX_HAVE_CXX_ATOMICS_WITH_LIB atomic) # Add the unwinder library. @@ -95,6 +95,8 @@ else() add_interface_library(unwind) endif() +else() + add_library_flags_if(LIBCXX_HAS_GCC_S_LIB gcc_s) endif() # Setup flags.