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 * These macros 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 # define MOZ_GCC_VERSION_AT_MOST(major, minor, patchlevel) \
27 ((__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__) <= \
28 ((major)*10000 + (minor)*100 + (patchlevel)))
29 # if !MOZ_GCC_VERSION_AT_LEAST(6, 1, 0)
30 # error "mfbt (and Gecko) require at least gcc 6.1 to build."
33 #elif defined(_MSC_VER)
36 # define MOZ_IS_MSVC 1
41 * The situation with standard libraries is a lot worse than with compilers,
42 * particularly as clang and gcc could end up using one of three or so standard
43 * libraries, and they may not be up-to-snuff with newer C++11 versions. To
44 * detect the library, we're going to include cstddef (which is a small header
45 * which will be transitively included by everybody else at some point) to grab
46 * the version macros and deduce macros from there.
50 # ifdef _STLPORT_MAJOR
51 # define MOZ_USING_STLPORT 1
52 # define MOZ_STLPORT_VERSION_AT_LEAST(major, minor, patch) \
53 (_STLPORT_VERSION >= ((major) << 8 | (minor) << 4 | (patch)))
54 # elif defined(_LIBCPP_VERSION)
56 * libc++, unfortunately, doesn't appear to have useful versioning macros.
57 * Hopefully, the recommendations of N3694 with respect to standard libraries
58 * will get applied instead and we won't need to worry about version numbers
61 # define MOZ_USING_LIBCXX 1
62 # elif defined(__GLIBCXX__)
63 # define MOZ_USING_LIBSTDCXX 1
65 * libstdc++ is also annoying and doesn't give us useful versioning macros
66 * for the library. If we're using gcc, then assume that libstdc++ matches
67 * the compiler version. If we're using clang, we're going to have to fake
68 * major/minor combinations by looking for newly-defined config macros.
71 # define MOZ_LIBSTDCXX_VERSION_AT_LEAST(major, minor, patch) \
72 MOZ_GCC_VERSION_AT_LEAST(major, minor, patch)
73 # elif defined(_GLIBCXX_THROW_OR_ABORT)
74 # define MOZ_LIBSTDCXX_VERSION_AT_LEAST(major, minor, patch) \
75 ((major) < 4 || ((major) == 4 && (minor) <= 8))
76 # elif defined(_GLIBCXX_NOEXCEPT)
77 # define MOZ_LIBSTDCXX_VERSION_AT_LEAST(major, minor, patch) \
78 ((major) < 4 || ((major) == 4 && (minor) <= 7))
79 # elif defined(_GLIBCXX_USE_DEPRECATED)
80 # define MOZ_LIBSTDCXX_VERSION_AT_LEAST(major, minor, patch) \
81 ((major) < 4 || ((major) == 4 && (minor) <= 6))
82 # elif defined(_GLIBCXX_PSEUDO_VISIBILITY)
83 # define MOZ_LIBSTDCXX_VERSION_AT_LEAST(major, minor, patch) \
84 ((major) < 4 || ((major) == 4 && (minor) <= 5))
85 # elif defined(_GLIBCXX_BEGIN_EXTERN_C)
86 # define MOZ_LIBSTDCXX_VERSION_AT_LEAST(major, minor, patch) \
87 ((major) < 4 || ((major) == 4 && (minor) <= 4))
88 # elif defined(_GLIBCXX_VISIBILITY_ATTR)
89 # define MOZ_LIBSTDCXX_VERSION_AT_LEAST(major, minor, patch) \
90 ((major) < 4 || ((major) == 4 && (minor) <= 3))
91 # elif defined(_GLIBCXX_VISIBILITY)
92 # define MOZ_LIBSTDCXX_VERSION_AT_LEAST(major, minor, patch) \
93 ((major) < 4 || ((major) == 4 && (minor) <= 2))
95 # error "Your version of libstdc++ is unknown to us and is likely too old."
99 // Flesh out the defines for everyone else
100 # ifndef MOZ_USING_STLPORT
101 # define MOZ_USING_STLPORT 0
102 # define MOZ_STLPORT_VERSION_AT_LEAST(major, minor, patch) 0
104 # ifndef MOZ_USING_LIBCXX
105 # define MOZ_USING_LIBCXX 0
107 # ifndef MOZ_USING_LIBSTDCXX
108 # define MOZ_USING_LIBSTDCXX 0
109 # define MOZ_LIBSTDCXX_VERSION_AT_LEAST(major, minor, patch) 0
111 #endif /* __cplusplus */
113 #endif /* mozilla_Compiler_h */