[libcxx] r174623 - Michael van der Westhuizen: The attached patch add support for building against libc++abi and libcxxrt to CMake builds of libc++.

Howard Hinnant hhinnant at apple.com
Thu Feb 7 07:27:39 PST 2013


Author: hhinnant
Date: Thu Feb  7 09:27:39 2013
New Revision: 174623

URL: http://llvm.org/viewvc/llvm-project?rev=174623&view=rev
Log:
Michael van der Westhuizen: The attached patch add support for building against libc++abi and libcxxrt to CMake builds of libc++.

Usage (with the appropriate CC and CXX environment variables) is:
$ cmake -DLIBCXX_CXX_ABI=libcxxabi '-DLIBCXX_LIBCXXABI_INCLUDE_PATHS=/home/michael/libcxxabi/include' ../libcxx
and:
$ cmake -DLIBCXX_CXX_ABI=libcxxrt '-DLIBCXX_LIBCXXRT_INCLUDE_PATHS=/home/michael/libcxxrt/src' ../libcxx

Modified:
    libcxx/trunk/CMakeLists.txt
    libcxx/trunk/include/__split_buffer
    libcxx/trunk/include/functional
    libcxx/trunk/include/string
    libcxx/trunk/include/vector

Modified: libcxx/trunk/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/CMakeLists.txt?rev=174623&r1=174622&r2=174623&view=diff
==============================================================================
--- libcxx/trunk/CMakeLists.txt (original)
+++ libcxx/trunk/CMakeLists.txt Thu Feb  7 09:27:39 2013
@@ -114,6 +114,89 @@ if ("${LIBCXX_CXX_ABI}" STREQUAL "libsup
     FILES_MATCHING
     PATTERN "*"
     )
+elseif ("${LIBCXX_CXX_ABI}" STREQUAL "libcxxabi")
+  set(LIBCXX_LIBCXXABI_INCLUDE_PATHS "${LIBCXX_LIBCXXABI_INCLUDE_PATHS}"
+      CACHE STRINGS
+      "Paths to libc++abi include directories separate by ';'.")
+  set(LIBCXX_CXX_ABI_LIBRARIES c++abi)
+  set(LIBCXX_LIBCXXABI_FILES
+      cxxabi.h
+      cxa_demangle.h
+      )
+  file(MAKE_DIRECTORY "${CMAKE_BINARY_DIR}/include")
+  set(LIBCXX_LIBCXXABI_FILE_PATHS)
+  foreach(path ${LIBCXX_LIBCXXABI_FILES})
+    set(found FALSE)
+    foreach(incpath ${LIBCXX_LIBCXXABI_INCLUDE_PATHS})
+      if (EXISTS "${incpath}/${path}")
+        set(found TRUE)
+        get_filename_component(file ${path} NAME)
+        add_custom_command(
+          OUTPUT "${CMAKE_BINARY_DIR}/include/${file}"
+          COMMAND ${CMAKE_COMMAND} -E copy_if_different
+                    "${incpath}/${path}"
+                    "${CMAKE_BINARY_DIR}/include"
+          MAIN_DEPENDENCY "${incpath}/${path}"
+          )
+        list(APPEND LIBCXX_CXX_ABI_DEPS
+                    "${CMAKE_BINARY_DIR}/include/${file}")
+      endif()
+    endforeach()
+    if (NOT found)
+      message(FATAL_ERROR "Failed to find ${path}")
+    endif()
+  endforeach()
+  add_custom_target(cxxabi_headers DEPENDS ${LIBCXX_CXX_ABI_DEPS})
+  set(LIBCXX_CXX_ABI_DEPS cxxabi_headers)
+  include_directories("${CMAKE_BINARY_DIR}/include")
+  install(DIRECTORY "${CMAKE_BINARY_DIR}/include/"
+    DESTINATION include/c++/v1
+    FILES_MATCHING
+    PATTERN "*"
+    )
+elseif ("${LIBCXX_CXX_ABI}" STREQUAL "libcxxrt")
+  set(LIBCXX_LIBCXXRT_INCLUDE_PATHS "${LIBCXX_LIBCXXRT_INCLUDE_PATHS}"
+      CACHE STRINGS
+      "Paths to libcxxrt include directories separate by ';'.")
+  set(LIBCXX_CXX_ABI_LIBRARIES cxxrt)
+  set(LIBCXX_LIBCXXRT_FILES
+      cxxabi.h
+      unwind.h
+      unwind-arm.h
+      unwind-itanium.h
+      )
+  file(MAKE_DIRECTORY "${CMAKE_BINARY_DIR}/include")
+  set(LIBCXX_LIBCXXRT_FILE_PATHS)
+  foreach(path ${LIBCXX_LIBCXXRT_FILES})
+    set(found FALSE)
+    foreach(incpath ${LIBCXX_LIBCXXRT_INCLUDE_PATHS})
+      if (EXISTS "${incpath}/${path}")
+        set(found TRUE)
+        get_filename_component(file ${path} NAME)
+        add_custom_command(
+          OUTPUT "${CMAKE_BINARY_DIR}/include/${file}"
+          COMMAND ${CMAKE_COMMAND} -E copy_if_different
+                    "${incpath}/${path}"
+                    "${CMAKE_BINARY_DIR}/include"
+          MAIN_DEPENDENCY "${incpath}/${path}"
+          )
+        list(APPEND LIBCXX_CXX_ABI_DEPS
+                    "${CMAKE_BINARY_DIR}/include/${file}")
+      endif()
+    endforeach()
+    if (NOT found)
+      message(FATAL_ERROR "Failed to find ${path}")
+    endif()
+  endforeach()
+  add_custom_target(cxxrt_headers DEPENDS ${LIBCXX_CXX_ABI_DEPS})
+  set(LIBCXX_CXX_ABI_DEPS cxxrt_headers)
+  include_directories("${CMAKE_BINARY_DIR}/include")
+  install(DIRECTORY "${CMAKE_BINARY_DIR}/include/"
+    DESTINATION include/c++/v1
+    FILES_MATCHING
+    PATTERN "*"
+    )
+  list(APPEND LIBCXX_CXX_FEATURE_FLAGS -DLIBCXXRT)
 elseif (NOT "${LIBCXX_CXX_ABI}" STREQUAL "none")
   message(FATAL_ERROR
           "Currently only none and libsupc++ are supported for c++ abi.")

Modified: libcxx/trunk/include/__split_buffer
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/__split_buffer?rev=174623&r1=174622&r2=174623&view=diff
==============================================================================
--- libcxx/trunk/include/__split_buffer (original)
+++ libcxx/trunk/include/__split_buffer Thu Feb  7 09:27:39 2013
@@ -290,7 +290,7 @@ void
 __split_buffer<_Tp, _Allocator>::__destruct_at_begin(pointer __new_begin, false_type)
 {
     while (__begin_ != __new_begin)
-        __alloc_traits::destroy(__alloc(), __begin_++);
+        __alloc_traits::destroy(__alloc(), _VSTD::__to_raw_pointer(__begin_++));
 }
 
 template <class _Tp, class _Allocator>
@@ -307,7 +307,7 @@ void
 __split_buffer<_Tp, _Allocator>::__destruct_at_end(pointer __new_last, false_type) _NOEXCEPT
 {
     while (__new_last != __end_)
-        __alloc_traits::destroy(__alloc(), --__end_);
+        __alloc_traits::destroy(__alloc(), _VSTD::__to_raw_pointer(--__end_));
 }
 
 template <class _Tp, class _Allocator>

Modified: libcxx/trunk/include/functional
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/functional?rev=174623&r1=174622&r2=174623&view=diff
==============================================================================
--- libcxx/trunk/include/functional (original)
+++ libcxx/trunk/include/functional Thu Feb  7 09:27:39 2013
@@ -465,6 +465,10 @@ POLICY:  For non-variadic implementation
 #include <memory>
 #include <tuple>
 
+#if __OBJC__
+#  include <Foundation/NSObject.h>
+#endif
+
 #include <__functional_base>
 
 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
@@ -2020,6 +2024,26 @@ struct _LIBCPP_VISIBLE hash<long double>
     }
 };
 
+#if __OBJC__
+
+template <>
+struct _LIBCPP_VISIBLE hash<id>
+    : public unary_function<id, size_t>
+{
+    _LIBCPP_INLINE_VISIBILITY
+    size_t operator()(id __v) const _NOEXCEPT {return [__v hash];}
+};
+
+template <>
+struct _LIBCPP_VISIBLE equal_to<id>
+    : public binary_function<id, id, bool>
+{
+    _LIBCPP_INLINE_VISIBILITY bool operator()(id __x, id __y) const
+        {return __x == __y || [__x isEqual: __y];}
+};
+
+#endif  //  __OBJC__
+
 // struct hash<T*> in <memory>
 
 _LIBCPP_END_NAMESPACE_STD

Modified: libcxx/trunk/include/string
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/string?rev=174623&r1=174622&r2=174623&view=diff
==============================================================================
--- libcxx/trunk/include/string (original)
+++ libcxx/trunk/include/string Thu Feb  7 09:27:39 2013
@@ -2067,10 +2067,13 @@ basic_string<_CharT, _Traits, _Allocator
     pointer __p = __alloc_traits::allocate(__alloc(), __cap+1);
     __invalidate_all_iterators();
     if (__n_copy != 0)
-        traits_type::copy(__p, __old_p, __n_copy);
+        traits_type::copy(_VSTD::__to_raw_pointer(__p),
+                          _VSTD::__to_raw_pointer(__old_p), __n_copy);
     size_type __sec_cp_sz = __old_sz - __n_del - __n_copy;
     if (__sec_cp_sz != 0)
-        traits_type::copy(__p + __n_copy + __n_add, __old_p + __n_copy + __n_del, __sec_cp_sz);
+        traits_type::copy(_VSTD::__to_raw_pointer(__p + __n_copy + __n_add),
+                          _VSTD::__to_raw_pointer(__old_p + __n_copy + __n_del),
+                          __sec_cp_sz);
     if (__old_cap+1 != __min_cap)
         __alloc_traits::deallocate(__alloc(), __old_p, __old_cap+1);
     __set_long_pointer(__p);
@@ -2303,7 +2306,7 @@ basic_string<_CharT, _Traits, _Allocator
         if (__cap - __sz < __n)
             __grow_by(__cap, __sz + __n - __cap, __sz, __sz, 0);
         pointer __p = __get_pointer();
-        traits_type::assign(__p + __sz, __n, __c);
+        traits_type::assign(_VSTD::__to_raw_pointer(__p + __sz), __n, __c);
         __sz += __n;
         __set_size(__sz);
         traits_type::assign(__p[__sz], value_type());

Modified: libcxx/trunk/include/vector
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/vector?rev=174623&r1=174622&r2=174623&view=diff
==============================================================================
--- libcxx/trunk/include/vector (original)
+++ libcxx/trunk/include/vector Thu Feb  7 09:27:39 2013
@@ -440,7 +440,7 @@ void
 __vector_base<_Tp, _Allocator>::__destruct_at_end(const_pointer __new_last, false_type) _NOEXCEPT
 {
     while (__new_last != __end_)
-        __alloc_traits::destroy(__alloc(), const_cast<pointer>(--__end_));
+        __alloc_traits::destroy(__alloc(), _VSTD::__to_raw_pointer(--__end_));
 }
 
 template <class _Tp, class _Allocator>
@@ -448,7 +448,7 @@ _LIBCPP_INLINE_VISIBILITY inline
 void
 __vector_base<_Tp, _Allocator>::__destruct_at_end(const_pointer __new_last, true_type) _NOEXCEPT
 {
-    __end_ = const_cast<pointer>(__new_last);
+    __end_ = static_cast<pointer>(__new_last);
 }
 
 template <class _Tp, class _Allocator>
@@ -1550,7 +1550,7 @@ vector<_Tp, _Allocator>::erase(const_ite
         "vector::erase(iterator) called with an iterator not"
         " referring to this vector");
 #endif
-    pointer __p = const_cast<pointer>(&*__position);
+    pointer __p = this->__begin_ + (__position - cbegin());
     iterator __r = __make_iter(__p);
     this->__destruct_at_end(_VSTD::move(__p + 1, this->__end_, __p));
     return __r;





More information about the cfe-commits mailing list