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.5.1 or later, check `#if MOZ_GCC_VERSION_AT_LEAST(4, 5, 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, 4, 0)
27 # error "mfbt (and Gecko) require at least gcc 4.4 to build."
30 #elif defined(_MSC_VER)
33 # define MOZ_IS_MSVC 1
35 * This macro should simplify MSVC version checking. For example, to check
36 * for VC10 or later, check `#ifdef MOZ_MSVC_VERSION_AT_LEAST(10)`.
38 # define MOZ_MSVC_VERSION_AT_LEAST(version) \
39 (version == 10 ? _MSC_VER >= 1600 : \
40 (version == 11 ? _MSC_VER >= 1700 : \
41 (version == 12 ? _MSC_VER >= 1800 : \
42 (version == 13 ? _MSC_VER >= 1900 : \
44 # if !MOZ_MSVC_VERSION_AT_LEAST(10)
45 # error "mfbt (and Gecko) require at least MSVC 2010 RTM to build."
51 * The situation with standard libraries is a lot worse than with compilers,
52 * particularly as clang and gcc could end up using one of three or so standard
53 * libraries, and they may not be up-to-snuff with newer C++11 versions. To
54 * detect the library, we're going to include cstddef (which is a small header
55 * which will be transitively included by everybody else at some point) to grab
56 * the version macros and deduce macros from there.
60 # ifdef _STLPORT_MAJOR
61 # define MOZ_USING_STLPORT 1
62 # define MOZ_STLPORT_VERSION_AT_LEAST(major, minor, patch) \
63 (_STLPORT_VERSION >= ((major) << 8 | (minor) << 4 | (patch)))
64 # elif defined(_LIBCPP_VERSION)
66 * libc++, unfortunately, doesn't appear to have useful versioning macros.
67 * Hopefully, the recommendations of N3694 with respect to standard libraries
68 * will get applied instead and we won't need to worry about version numbers
71 # define MOZ_USING_LIBCXX 1
72 # elif defined(__GLIBCXX__)
73 # define MOZ_USING_LIBSTDCXX 1
75 * libstdc++ is also annoying and doesn't give us useful versioning macros
76 * for the library. If we're using gcc, then assume that libstdc++ matches
77 * the compiler version. If we're using clang, we're going to have to fake
78 * major/minor combinations by looking for newly-defined config macros.
81 # define MOZ_LIBSTDCXX_VERSION_AT_LEAST(major, minor, patch) \
82 MOZ_GCC_VERSION_AT_LEAST(major, minor, patch)
83 # elif defined(_GLIBCXX_THROW_OR_ABORT)
84 # define MOZ_LIBSTDCXX_VERSION_AT_LEAST(major, minor, patch) \
85 ((major) < 4 || ((major) == 4 && (minor) <= 8))
86 # elif defined(_GLIBCXX_NOEXCEPT)
87 # define MOZ_LIBSTDCXX_VERSION_AT_LEAST(major, minor, patch) \
88 ((major) < 4 || ((major) == 4 && (minor) <= 7))
89 # elif defined(_GLIBCXX_USE_DEPRECATED)
90 # define MOZ_LIBSTDCXX_VERSION_AT_LEAST(major, minor, patch) \
91 ((major) < 4 || ((major) == 4 && (minor) <= 6))
92 # elif defined(_GLIBCXX_PSEUDO_VISIBILITY)
93 # define MOZ_LIBSTDCXX_VERSION_AT_LEAST(major, minor, patch) \
94 ((major) < 4 || ((major) == 4 && (minor) <= 5))
95 # elif defined(_GLIBCXX_BEGIN_EXTERN_C)
96 # define MOZ_LIBSTDCXX_VERSION_AT_LEAST(major, minor, patch) \
97 ((major) < 4 || ((major) == 4 && (minor) <= 4))
98 # elif defined(_GLIBCXX_VISIBILITY_ATTR)
99 # define MOZ_LIBSTDCXX_VERSION_AT_LEAST(major, minor, patch) \
100 ((major) < 4 || ((major) == 4 && (minor) <= 3))
101 # elif defined(_GLIBCXX_VISIBILITY)
102 # define MOZ_LIBSTDCXX_VERSION_AT_LEAST(major, minor, patch) \
103 ((major) < 4 || ((major) == 4 && (minor) <= 2))
105 # error "Your version of libstdc++ is unknown to us and is likely too old."
109 // Flesh out the defines for everyone else
110 # ifndef MOZ_USING_STLPORT
111 # define MOZ_USING_STLPORT 0
112 # define MOZ_STLPORT_VERSION_AT_LEAST(major, minor, patch) 0
114 # ifndef MOZ_USING_LIBCXX
115 # define MOZ_USING_LIBCXX 0
117 # ifndef MOZ_USING_LIBSTDCXX
118 # define MOZ_USING_LIBSTDCXX 0
119 # define MOZ_LIBSTDCXX_VERSION_AT_LEAST(major, minor, patch) 0
121 #endif /* __cplusplus */
123 #endif /* mozilla_Compiler_h */