Pyrogenesis HEAD
Pyrogenesis, a RTS Engine
compiler.h
Go to the documentation of this file.
1/* Copyright (c) 2022 Wildfire Games.
2 *
3 * Permission is hereby granted, free of charge, to any person obtaining
4 * a copy of this software and associated documentation files (the
5 * "Software"), to deal in the Software without restriction, including
6 * without limitation the rights to use, copy, modify, merge, publish,
7 * distribute, sublicense, and/or sell copies of the Software, and to
8 * permit persons to whom the Software is furnished to do so, subject to
9 * the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included
12 * in all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
18 * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
19 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
20 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21 */
22
23/*
24 * compiler-specific macros and fixes
25 */
26
27#ifndef INCLUDED_COMPILER
28#define INCLUDED_COMPILER
29
30// detect compiler and its version (0 if not present, otherwise
31// major*100 + minor). note that more than one *_VERSION may be
32// non-zero due to interoperability (e.g. ICC with MSC).
33// .. VC
34#ifdef _MSC_VER
35# define MSC_VERSION _MSC_VER
36#else
37# define MSC_VERSION 0
38#endif
39// .. ICC (VC-compatible, GCC-compatible)
40#if defined(__INTEL_COMPILER)
41# define ICC_VERSION __INTEL_COMPILER
42#else
43# define ICC_VERSION 0
44#endif
45// .. LCC (Win32) and MCST LCC (E2K) compilers define same identifier (__LCC__)
46#if defined(__LCC__) && !defined(__MCST__)
47# define LCC_VERSION __LCC__
48#else
49# define LCC_VERSION 0
50#endif
51// .. MCST LCC (eLbrus Compiler Collection)
52#if defined(__LCC__) && defined(__MCST__)
53# define MCST_LCC_VERSION (__LCC__*100 + __LCC_MINOR__)
54#else
55# define MCST_LCC_VERSION 0
56#endif
57// .. GCC
58#ifdef __GNUC__
59# define GCC_VERSION (__GNUC__*100 + __GNUC_MINOR__)
60#else
61# define GCC_VERSION 0
62#endif
63// .. Clang/LLVM (GCC-compatible)
64// use Clang's feature checking macros to check for availability of features
65// http://clang.llvm.org/docs/LanguageExtensions.html#feature-checking-macros
66#ifdef __clang__
67# define CLANG_VERSION (__clang_major__*100 + __clang_minor__)
68#else
69# define CLANG_VERSION 0
70#endif
71
72// Clang/LLVM feature check macro compatibility
73#ifndef __has_feature
74# define __has_feature(x) 0
75#endif
76
77#ifndef __has_cpp_attribute
78# define __has_cpp_attribute(x) 0
79#endif
80
81// check if compiling in pure C mode (not C++) with support for C99.
82// (this is more convenient than testing __STDC_VERSION__ directly)
83//
84// note: C99 provides several useful but disjunct bits of functionality.
85// unfortunately, most C++ compilers do not offer a complete implementation.
86// however, many of these features are likely to be added to C++, and/or are
87// already available as extensions. what we'll do is add a HAVE_ macro for
88// each feature and test those instead. they are set if HAVE_C99, or also if
89// the compiler happens to support something compatible.
90//
91// rationale: lying about __STDC_VERSION__ via Premake so as to enable support
92// for some C99 functions doesn't work. Mac OS X headers would then use the
93// restrict keyword, which is never supported by g++ (because that might
94// end up breaking valid C++98 programs).
95#define HAVE_C99 0
96#ifdef __STDC_VERSION__
97# if __STDC_VERSION__ >= 199901L
98# undef HAVE_C99
99# define HAVE_C99 1
100# endif
101#endif
102
103// Streaming SIMD Extensions (not supported by all GCC)
104// this only ascertains compiler support; use x86_x64::Cap to
105// check whether the instructions are supported by the CPU.
106#ifndef COMPILER_HAS_SSE
107# if GCC_VERSION && defined(__SSE__)
108# define COMPILER_HAS_SSE 1
109# elif MSC_VERSION // also includes ICC
110# define COMPILER_HAS_SSE 1
111# else
112# define COMPILER_HAS_SSE 0
113# endif
114#endif
115
116#ifndef COMPILER_HAS_SSE2
117# if GCC_VERSION && defined(__SSE2__)
118# define COMPILER_HAS_SSE2 1
119# elif MSC_VERSION // also includes ICC
120# define COMPILER_HAS_SSE2 1
121# else
122# define COMPILER_HAS_SSE2 0
123# endif
124#endif
125
126#endif // #ifndef INCLUDED_COMPILER