1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 /* Various compiler checks. */
9 #ifndef mozilla_Compiler_h
10 #define mozilla_Compiler_h
15 #if !defined(__clang__) && defined(__GNUC__)
20 * This macro should simplify gcc version checking. For example, to check
21 * for gcc 4.7.1 or later, check `#if MOZ_GCC_VERSION_AT_LEAST(4, 7, 1)`.
23 # define MOZ_GCC_VERSION_AT_LEAST(major, minor, patchlevel) \
24 ((__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__) \
25 >= ((major) * 10000 + (minor) * 100 + (patchlevel)))
26 # if !MOZ_GCC_VERSION_AT_LEAST(4, 7, 0)
27 # error "mfbt (and Gecko) require at least gcc 4.7 to build."
30 #elif defined(_MSC_VER)
33 # define MOZ_IS_MSVC 1
38 * The situation with standard libraries is a lot worse than with compilers,
39 * particularly as clang and gcc could end up using one of three or so standard
40 * libraries, and they may not be up-to-snuff with newer C++11 versions. To
41 * detect the library, we're going to include cstddef (which is a small header
42 * which will be transitively included by everybody else at some point) to grab
43 * the version macros and deduce macros from there.
47 # ifdef _STLPORT_MAJOR
48 # define MOZ_USING_STLPORT 1
49 # define MOZ_STLPORT_VERSION_AT_LEAST(major, minor, patch) \
50 (_STLPORT_VERSION >= ((major) << 8 | (minor) << 4 | (patch)))
51 # elif defined(_LIBCPP_VERSION)
53 * libc++, unfortunately, doesn't appear to have useful versioning macros.
54 * Hopefully, the recommendations of N3694 with respect to standard libraries
55 * will get applied instead and we won't need to worry about version numbers
58 # define MOZ_USING_LIBCXX 1
59 # elif defined(__GLIBCXX__)
60 # define MOZ_USING_LIBSTDCXX 1
62 * libstdc++ is also annoying and doesn't give us useful versioning macros
63 * for the library. If we're using gcc, then assume that libstdc++ matches
64 * the compiler version. If we're using clang, we're going to have to fake
65 * major/minor combinations by looking for newly-defined config macros.
68 # define MOZ_LIBSTDCXX_VERSION_AT_LEAST(major, minor, patch) \
69 MOZ_GCC_VERSION_AT_LEAST(major, minor, patch)
70 # elif defined(_GLIBCXX_THROW_OR_ABORT)
71 # define MOZ_LIBSTDCXX_VERSION_AT_LEAST(major, minor, patch) \
72 ((major) < 4 || ((major) == 4 && (minor) <= 8))
73 # elif defined(_GLIBCXX_NOEXCEPT)
74 # define MOZ_LIBSTDCXX_VERSION_AT_LEAST(major, minor, patch) \
75 ((major) < 4 || ((major) == 4 && (minor) <= 7))
76 # elif defined(_GLIBCXX_USE_DEPRECATED)
77 # define MOZ_LIBSTDCXX_VERSION_AT_LEAST(major, minor, patch) \
78 ((major) < 4 || ((major) == 4 && (minor) <= 6))
79 # elif defined(_GLIBCXX_PSEUDO_VISIBILITY)
80 # define MOZ_LIBSTDCXX_VERSION_AT_LEAST(major, minor, patch) \
81 ((major) < 4 || ((major) == 4 && (minor) <= 5))
82 # elif defined(_GLIBCXX_BEGIN_EXTERN_C)
83 # define MOZ_LIBSTDCXX_VERSION_AT_LEAST(major, minor, patch) \
84 ((major) < 4 || ((major) == 4 && (minor) <= 4))
85 # elif defined(_GLIBCXX_VISIBILITY_ATTR)
86 # define MOZ_LIBSTDCXX_VERSION_AT_LEAST(major, minor, patch) \
87 ((major) < 4 || ((major) == 4 && (minor) <= 3))
88 # elif defined(_GLIBCXX_VISIBILITY)
89 # define MOZ_LIBSTDCXX_VERSION_AT_LEAST(major, minor, patch) \
90 ((major) < 4 || ((major) == 4 && (minor) <= 2))
92 # error "Your version of libstdc++ is unknown to us and is likely too old."
96 // Flesh out the defines for everyone else
97 # ifndef MOZ_USING_STLPORT
98 # define MOZ_USING_STLPORT 0
99 # define MOZ_STLPORT_VERSION_AT_LEAST(major, minor, patch) 0
101 # ifndef MOZ_USING_LIBCXX
102 # define MOZ_USING_LIBCXX 0
104 # ifndef MOZ_USING_LIBSTDCXX
105 # define MOZ_USING_LIBSTDCXX 0
106 # define MOZ_LIBSTDCXX_VERSION_AT_LEAST(major, minor, patch) 0
108 #endif /* __cplusplus */
110 #endif /* mozilla_Compiler_h */