mfbt/Compiler.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/mfbt/Compiler.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,105 @@
     1.4 +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     1.5 +/* vim: set ts=8 sts=2 et sw=2 tw=80: */
     1.6 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.7 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.8 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.9 +
    1.10 +/* Various compiler checks. */
    1.11 +
    1.12 +#ifndef mozilla_Compiler_h
    1.13 +#define mozilla_Compiler_h
    1.14 +
    1.15 +#if !defined(__clang__) && defined(__GNUC__)
    1.16 +
    1.17 +#  define MOZ_IS_GCC 1
    1.18 +   /*
    1.19 +    * This macro should simplify gcc version checking. For example, to check
    1.20 +    * for gcc 4.5.1 or later, check `#if MOZ_GCC_VERSION_AT_LEAST(4, 5, 1)`.
    1.21 +    */
    1.22 +#  define MOZ_GCC_VERSION_AT_LEAST(major, minor, patchlevel)          \
    1.23 +     ((__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__) \
    1.24 +      >= ((major) * 10000 + (minor) * 100 + (patchlevel)))
    1.25 +#  if !MOZ_GCC_VERSION_AT_LEAST(4, 4, 0)
    1.26 +#    error "mfbt (and Gecko) require at least gcc 4.4 to build."
    1.27 +#  endif
    1.28 +
    1.29 +#else
    1.30 +
    1.31 +#  define MOZ_IS_GCC 0
    1.32 +
    1.33 +#endif
    1.34 +
    1.35 +/*
    1.36 + * The situation with standard libraries is a lot worse than with compilers,
    1.37 + * particularly as clang and gcc could end up using one of three or so standard
    1.38 + * libraries, and they may not be up-to-snuff with newer C++11 versions. To
    1.39 + * detect the library, we're going to include cstddef (which is a small header
    1.40 + * which will be transitively included by everybody else at some point) to grab
    1.41 + * the version macros and deduce macros from there.
    1.42 + */
    1.43 +#ifdef __cplusplus
    1.44 +#  include <cstddef>
    1.45 +#  ifdef _STLPORT_MAJOR
    1.46 +#    define MOZ_USING_STLPORT 1
    1.47 +#    define MOZ_STLPORT_VERSION_AT_LEAST(major, minor, patch) \
    1.48 +       (_STLPORT_VERSION >= ((major) << 8 | (minor) << 4 | (patch)))
    1.49 +#  elif defined(_LIBCPP_VERSION)
    1.50 +   /*
    1.51 +    * libc++, unfortunately, doesn't appear to have useful versioning macros.
    1.52 +    * Hopefully, the recommendations of N3694 with respect to standard libraries
    1.53 +    * will get applied instead and we won't need to worry about version numbers
    1.54 +    * here.
    1.55 +    */
    1.56 +#    define MOZ_USING_LIBCXX 1
    1.57 +#  elif defined(__GLIBCXX__)
    1.58 +#    define MOZ_USING_LIBSTDCXX 1
    1.59 +   /*
    1.60 +    * libstdc++ is also annoying and doesn't give us useful versioning macros
    1.61 +    * for the library. If we're using gcc, then assume that libstdc++ matches
    1.62 +    * the compiler version. If we're using clang, we're going to have to fake
    1.63 +    * major/minor combinations by looking for newly-defined config macros.
    1.64 +    */
    1.65 +#    if MOZ_IS_GCC
    1.66 +#      define MOZ_LIBSTDCXX_VERSION_AT_LEAST(major, minor, patch) \
    1.67 +          MOZ_GCC_VERSION_AT_LEAST(major, minor, patch)
    1.68 +#    elif defined(_GLIBCXX_THROW_OR_ABORT)
    1.69 +#      define MOZ_LIBSTDCXX_VERSION_AT_LEAST(major, minor, patch) \
    1.70 +          ((major) < 4 || ((major) == 4 && (minor) <= 8))
    1.71 +#    elif defined(_GLIBCXX_NOEXCEPT)
    1.72 +#      define MOZ_LIBSTDCXX_VERSION_AT_LEAST(major, minor, patch) \
    1.73 +          ((major) < 4 || ((major) == 4 && (minor) <= 7))
    1.74 +#    elif defined(_GLIBCXX_USE_DEPRECATED)
    1.75 +#      define MOZ_LIBSTDCXX_VERSION_AT_LEAST(major, minor, patch) \
    1.76 +          ((major) < 4 || ((major) == 4 && (minor) <= 6))
    1.77 +#    elif defined(_GLIBCXX_PSEUDO_VISIBILITY)
    1.78 +#      define MOZ_LIBSTDCXX_VERSION_AT_LEAST(major, minor, patch) \
    1.79 +          ((major) < 4 || ((major) == 4 && (minor) <= 5))
    1.80 +#    elif defined(_GLIBCXX_BEGIN_EXTERN_C)
    1.81 +#      define MOZ_LIBSTDCXX_VERSION_AT_LEAST(major, minor, patch) \
    1.82 +          ((major) < 4 || ((major) == 4 && (minor) <= 4))
    1.83 +#    elif defined(_GLIBCXX_VISIBILITY_ATTR)
    1.84 +#      define MOZ_LIBSTDCXX_VERSION_AT_LEAST(major, minor, patch) \
    1.85 +          ((major) < 4 || ((major) == 4 && (minor) <= 3))
    1.86 +#    elif defined(_GLIBCXX_VISIBILITY)
    1.87 +#      define MOZ_LIBSTDCXX_VERSION_AT_LEAST(major, minor, patch) \
    1.88 +          ((major) < 4 || ((major) == 4 && (minor) <= 2))
    1.89 +#    else
    1.90 +#      error "Your version of libstdc++ is unknown to us and is likely too old."
    1.91 +#    endif
    1.92 +#  endif
    1.93 +
    1.94 +   // Flesh out the defines for everyone else
    1.95 +#  ifndef MOZ_USING_STLPORT
    1.96 +#    define MOZ_USING_STLPORT 0
    1.97 +#    define MOZ_STLPORT_VERSION_AT_LEAST(major, minor, patch) 0
    1.98 +#  endif
    1.99 +#  ifndef MOZ_USING_LIBCXX
   1.100 +#    define MOZ_USING_LIBCXX 0
   1.101 +#  endif
   1.102 +#  ifndef MOZ_USING_LIBSTDCXX
   1.103 +#    define MOZ_USING_LIBSTDCXX 0
   1.104 +#    define MOZ_LIBSTDCXX_VERSION_AT_LEAST(major, minor, patch) 0
   1.105 +#  endif
   1.106 +#endif /* __cplusplus */
   1.107 +
   1.108 +#endif /* mozilla_Compiler_h */

mercurial