[libcxx] Use libtool when merging archives on Apple platforms

ar doesn't produce the correct results when used for linking static
archives on Apple platforms, so instead use libtool -static which is
the official way to build static archives on those platforms.

Differential Revision: https://reviews.llvm.org/D62770

git-svn-id: https://llvm.org/svn/llvm-project/libcxxabi/trunk@362311 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index e4e1fac..77f0098 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -226,6 +226,10 @@
     list(APPEND LIBCXXABI_INSTALL_TARGETS "cxxabi_static")
   endif()
 
+  if (APPLE)
+    set(MERGE_ARCHIVES_LIBTOOL "--use-libtool" "--libtool" "${CMAKE_LIBTOOL}")
+  endif()
+
   # Merge the the libc++abi.a and libunwind.a into one.
   if(LIBCXXABI_USE_LLVM_UNWINDER AND LIBCXXABI_STATICALLY_LINK_UNWINDER_IN_STATIC_LIBRARY)
     add_custom_command(TARGET cxxabi_static POST_BUILD
@@ -233,6 +237,7 @@
       ARGS
         -o "$<TARGET_LINKER_FILE:cxxabi_static>"
         --ar "${CMAKE_AR}"
+        ${MERGE_ARCHIVES_LIBTOOL}
         "$<TARGET_LINKER_FILE:cxxabi_static>"
         "$<TARGET_LINKER_FILE:unwind_static>"
       WORKING_DIRECTORY ${LIBCXXABI_BUILD_DIR}