Otclient  14/8/2020
compiler.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2010-2020 OTClient <https://github.com/edubart/otclient>
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a copy
5  * of this software and associated documentation files (the "Software"), to deal
6  * in the Software without restriction, including without limitation the rights
7  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8  * copies of the Software, and to permit persons to whom the Software is
9  * furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice shall be included in
12  * all copies or substantial portions of the Software.
13  *
14  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20  * THE SOFTWARE.
21  */
22 
23 #ifndef STDEXT_COMPILER_H
24 #define STDEXT_COMPILER_H
25 
26 #ifdef WIN32
27 #include <winsock2.h>
28 #endif
29 
30 #ifdef __clang__
31  // clang is supported
32  #define BUILD_COMPILER "clang " __VERSION__
33 #elif defined(__GNUC__)
34  #if !(__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6))
35  #error "Sorry, you need gcc 4.6 or greater to compile."
36  #endif
37  #define BUILD_COMPILER "gcc " __VERSION__
38 #elif defined(_MSC_VER)
39  #if _MSC_VER < 1800
40  #error "You need Visual Studio 2013 or greater to compile."
41  #endif
42  #pragma warning(disable:4244) // conversion from 'A' to 'B', possible loss of data
43  #pragma warning(disable:4267) // '?' : conversion from 'A' to 'B', possible loss of data
44  #pragma warning(disable:4305) // 'initializing' : truncation from 'A' to 'B'
45  #pragma warning(disable:4146) // unary minus operator applied to unsigned type, result still unsigned
46  #pragma warning(disable:4800) // 'A' : forcing value to bool 'true' or 'false' (performance warning)
47 
48  #if _MSC_VER == 1912 || _MSC_VER == 1911 || _MSC_VER == 1910
49  #define BUILD_COMPILER "Visual Studio 2017"
50  #elif _MSC_VER == 1900
51  #define BUILD_COMPILER "Visual Studio 2015"
52  #elif _MSC_VER == 1800
53  #define BUILD_COMPILER "Visual Studio 2013"
54  #else
55  #define BUILD_COMPILER "Visual Studio"
56  #endif
57 
58  #define __PRETTY_FUNCTION__ __FUNCDNAME__
59 #else
60  #error "Compiler not supported."
61 #endif
62 
66 #if defined(__clang__) || defined(__GNUC__)
67 #define likely(x) __builtin_expect(!!(x), 1)
68 #define unlikely(x) __builtin_expect(!!(x), 0)
69 #else
70 #define likely(x) (x)
71 #define unlikely(x) (x)
72 #endif
73 
74 #if !defined(_MSC_VER) && !defined(__GXX_EXPERIMENTAL_CXX0X__)
75 #error "C++0x is required to compile this application. Try updating your compiler."
76 #endif
77 
78 #endif