Detect libc++ in configure.ac.
authorPeter Griess <pgriess@fb.com>
Tue, 8 Oct 2013 23:57:39 +0000 (16:57 -0700)
committerSara Golemon <sgolemon@fb.com>
Thu, 24 Oct 2013 21:53:41 +0000 (14:53 -0700)
Summary:
- Explicitly detect use of libc++ in configure.ac and reflect this in
folly-config.h. Do this rather than looking for to pop up organically
_LIBCPP_VERSION since this only exists if we've included some libc++
header files prior to refernce. This isn't always the case, e.g. in
Portability.h.

Test Plan:
- fbconfig -r folly && fbmake runtests
- ./configure && make check on Ubuntu/FC/Mac

Reviewed By: simpkins@fb.com

FB internal diff: D1002958

folly/Portability.h
folly/configure.ac
folly/test/ScopeGuardTest.cpp

index 608c1d9b873d4d1aaab712c94d4722c289cf2011..d017400e3a4d020f72e23c77817666330248bae9 100644 (file)
@@ -121,7 +121,7 @@ struct MaxAlign { char c; } __attribute__((aligned));
 // It turns out that GNU libstdc++ and LLVM libc++ differ on how they implement
 // the 'std' namespace; the latter uses inline namepsaces. Wrap this decision
 // up in a macro to make forward-declarations easier.
-#ifdef _LIBCPP_VERSION
+#if FOLLY_USE_LIBCPP
 #define FOLLY_NAMESPACE_STD_BEGIN     _LIBCPP_BEGIN_NAMESPACE_STD
 #define FOLLY_NAMESPACE_STD_END       _LIBCPP_END_NAMESPACE_STD
 #else
index 2dc854aaaa9232debf6317ccbd123cf09b7a68f9..29ae18fd3f5a83dbacba3c70e2978e47e28102d1 100644 (file)
@@ -78,6 +78,15 @@ AC_COMPILE_IFELSE(
    AC_DEFINE([OVERRIDE], [],
              [Define to "override" if the compiler supports C++11 "override"])]
 )
+AC_COMPILE_IFELSE(
+  [AC_LANG_SOURCE[
+    #include <type_traits>
+    #if !_LIBCPP_VERSION
+    #error No libc++
+    #endif
+    void func() {}]
+  ],
+  [AC_DEFINE([USE_LIBCPP], [1], [Define to 1 if we're using libc++.])])
 
 # Check for clock_gettime(2). This is not in an AC_CHECK_FUNCS() because we
 # want to link with librt if necessary.
index 6e6b65a8acea0aa24962065e209f164d56371c4a..b741e37503536cfbc7977e316b1f4e607b82cd16 100644 (file)
@@ -15,6 +15,7 @@
  */
 
 #include "folly/ScopeGuard.h"
+#include "folly/Portability.h"
 
 #include <gflags/gflags.h>
 #include <gtest/gtest.h>
@@ -126,7 +127,7 @@ TEST(ScopeGuard, GuardException) {
       throw std::runtime_error("destructors should never throw!");
     });
   },
-#ifdef _LIBCPP_VERSION
+#if FOLLY_USE_LIBCPP
   "terminate called throwing an exception"
 #else
   "destructors should never throw"