[PATCH] D25568: [libcxx] [cmake] Use -print-libgcc-file-name option to find compiler runtime

Michał Górny via cfe-commits cfe-commits at lists.llvm.org
Thu Oct 13 10:10:21 PDT 2016


mgorny updated this revision to Diff 74538.
mgorny added a comment.

Fixed indentation.


https://reviews.llvm.org/D25568

Files:
  cmake/Modules/HandleLibcxxFlags.cmake
  lib/CMakeLists.txt


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.
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_CXX_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}}")


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D25568.74538.patch
Type: text/x-patch
Size: 1760 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20161013/b1309236/attachment.bin>


More information about the cfe-commits mailing list