[cfe-dev] Best way to detect libc++ at compile time?
Howard Hinnant
hhinnant at apple.com
Thu Jul 19 19:50:32 PDT 2012
On Jul 19, 2012, at 10:19 PM, Rich E <reakinator at gmail.com> wrote:
> Hi all,
>
> I am enabling libc++ in a library that was depending on boost for things such as mutex, thread, shared_ptr, etc., and I have not yet found a way to detect that we are compiling with the libc++ library unless I first include a header from it. I can do this:
>
> // framework config.h:
>
> #include <vector>
>
> #if defined( _LIBCPP_VERSION )
> #define USING_LIBCPP
> #endif
>
> but now every file that wanted to know if we are using libc++ has vector in it. This include is used to determine which standard library we should use, and many things depend on it. Is there a better solution, other than a -D flag to clang?
My solution is very similar to yours except I use <ciso646>. The C++ specification specifically says that #include <ciso646> has no effect. So it is very cheap to include.
The libc++ implementation of <ciso646> is:
#ifndef _LIBCPP_CISO646
#define _LIBCPP_CISO646
#include <__config>
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
#pragma GCC system_header
#endif
#endif // _LIBCPP_CISO646
And <__config> will #define _LIBCPP_VERSION. All libc++ headers include <__config> as the first thing. Other implementations of <ciso646> will not (I hope) #define _LIBCPP_VERSION.
Howard
More information about the cfe-dev
mailing list