[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:05:23 PDT 2016
mgorny created this revision.
mgorny added a reviewer: EricWF.
mgorny added a subscriber: cfe-commits.
Herald added subscribers: modocache, beanz.
Use the -print-libgcc-file-name compiler option to obtain the path to
libgcc or an equivalent compiler runtime library, rather than hardcoding
-lgcc_s. This aims to make it possible to avoid linking with -lgcc_s
when -rtlib=compiler-rt is used along with libunwind.
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_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}}")
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D25568.74535.patch
Type: text/x-patch
Size: 1768 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20161013/5b048a72/attachment.bin>
More information about the cfe-commits
mailing list