1 | //************************************ bs::framework - Copyright 2018 Marko Pintera **************************************// |
2 | //*********** Licensed under the MIT license. See LICENSE.md for full terms. This notice is not to be removed. ***********// |
3 | #pragma once |
4 | |
5 | // Initial platform/compiler-related stuff to set. |
6 | #define BS_PLATFORM_WIN32 1 |
7 | #define BS_PLATFORM_LINUX 2 |
8 | #define BS_PLATFORM_OSX 3 |
9 | #define BS_PLATFORM_IOS 4 |
10 | #define BS_PLATFORM_ANDROID 5 |
11 | |
12 | #define BS_COMPILER_MSVC 1 |
13 | #define BS_COMPILER_GNUC 2 |
14 | #define BS_COMPILER_INTEL 3 |
15 | #define BS_COMPILER_CLANG 4 |
16 | |
17 | #define BS_ARCHITECTURE_x86_32 1 |
18 | #define BS_ARCHITECTURE_x86_64 2 |
19 | |
20 | #define BS_ENDIAN_LITTLE 1 |
21 | #define BS_ENDIAN_BIG 2 |
22 | #define BS_ENDIAN BS_ENDIAN_LITTLE |
23 | |
24 | // Finds the compiler type and version. |
25 | #if defined(__clang__) |
26 | # define BS_COMPILER BS_COMPILER_CLANG |
27 | # define BS_COMP_VER __clang_version__ |
28 | # define BS_THREADLOCAL __thread |
29 | # define BS_STDCALL __attribute__((stdcall)) |
30 | # define BS_CDECL __attribute__((cdecl)) |
31 | # define BS_FALLTHROUGH [[clang::fallthrough]]; |
32 | #elif defined(__GNUC__) // Check after Clang, as Clang defines this too |
33 | # define BS_COMPILER BS_COMPILER_GNUC |
34 | # define BS_COMP_VER (((__GNUC__)*100) + \ |
35 | (__GNUC_MINOR__*10) + \ |
36 | __GNUC_PATCHLEVEL__) |
37 | # define BS_THREADLOCAL __thread |
38 | # define BS_STDCALL __attribute__((stdcall)) |
39 | # define BS_CDECL __attribute__((cdecl)) |
40 | # define BS_FALLTHROUGH __attribute__((fallthrough)); |
41 | #elif defined (__INTEL_COMPILER) |
42 | # define BS_COMPILER BS_COMPILER_INTEL |
43 | # define BS_COMP_VER __INTEL_COMPILER |
44 | # define BS_STDCALL __stdcall |
45 | # define BS_CDECL __cdecl |
46 | # define BS_FALLTHROUGH |
47 | // BS_THREADLOCAL define is down below because Intel compiler defines it differently based on platform |
48 | #elif defined(_MSC_VER) // Check after Clang and Intel, since we could be building with either within VS |
49 | # define BS_COMPILER BS_COMPILER_MSVC |
50 | # define BS_COMP_VER _MSC_VER |
51 | # define BS_THREADLOCAL __declspec(thread) |
52 | # define BS_STDCALL __stdcall |
53 | # define BS_CDECL __cdecl |
54 | # define BS_FALLTHROUGH |
55 | # undef __PRETTY_FUNCTION__ |
56 | # define __PRETTY_FUNCTION__ __FUNCSIG__ |
57 | #else |
58 | # pragma error "No known compiler. " |
59 | #endif |
60 | |
61 | // Finds the current platform |
62 | #if defined( __WIN32__ ) || defined( _WIN32 ) |
63 | # define BS_PLATFORM BS_PLATFORM_WIN32 |
64 | #elif defined( __APPLE_CC__) |
65 | # define BS_PLATFORM BS_PLATFORM_OSX |
66 | #else |
67 | # define BS_PLATFORM BS_PLATFORM_LINUX |
68 | #endif |
69 | |
70 | // Find the architecture type |
71 | #if defined(__x86_64__) || defined(_M_X64) |
72 | # define BS_ARCH_TYPE BS_ARCHITECTURE_x86_64 |
73 | #else |
74 | # define BS_ARCH_TYPE BS_ARCHITECTURE_x86_32 |
75 | #endif |
76 | |
77 | // DLL export |
78 | #if BS_PLATFORM == BS_PLATFORM_WIN32 // Windows |
79 | # if BS_COMPILER == BS_COMPILER_MSVC |
80 | # if defined(BS_STATIC_LIB) |
81 | # define BS_UTILITY_EXPORT |
82 | # else |
83 | # if defined(BS_UTILITY_EXPORTS) |
84 | # define BS_UTILITY_EXPORT __declspec(dllexport) |
85 | # else |
86 | # define BS_UTILITY_EXPORT __declspec(dllimport) |
87 | # endif |
88 | # endif |
89 | # else |
90 | # if defined(BS_STATIC_LIB) |
91 | # define BS_UTILITY_EXPORT |
92 | # else |
93 | # if defined(BS_UTILITY_EXPORTS) |
94 | # define BS_UTILITY_EXPORT __attribute__ ((dllexport)) |
95 | # else |
96 | # define BS_UTILITY_EXPORT __attribute__ ((dllimport)) |
97 | # endif |
98 | # endif |
99 | # endif |
100 | #define BS_UTILITY_HIDDEN |
101 | #else // Linux/Mac settings |
102 | # define BS_UTILITY_EXPORT __attribute__ ((visibility ("default"))) |
103 | # define BS_UTILITY_HIDDEN __attribute__ ((visibility ("hidden"))) |
104 | #endif |
105 | |
106 | // DLL export for plugins |
107 | #if BS_PLATFORM == BS_PLATFORM_WIN32 // Windows |
108 | # if BS_COMPILER == BS_COMPILER_MSVC |
109 | # define BS_PLUGIN_EXPORT __declspec(dllexport) |
110 | # else |
111 | # define BS_PLUGIN_EXPORT __attribute__ ((dllexport)) |
112 | # endif |
113 | # define BS_UTILITY_HIDDEN |
114 | #else // Linux/Mac settings |
115 | # define BS_PLUGIN_EXPORT __attribute__ ((visibility ("default"))) |
116 | #endif |
117 | |
118 | // Windows Settings |
119 | #if BS_PLATFORM == BS_PLATFORM_WIN32 |
120 | // Win32 compilers use _DEBUG for specifying debug builds. |
121 | // for MinGW, we set DEBUG |
122 | # if defined(_DEBUG) || defined(DEBUG) |
123 | # define BS_DEBUG_MODE 1 |
124 | # else |
125 | # define BS_DEBUG_MODE 0 |
126 | # endif |
127 | |
128 | # if BS_COMPILER == BS_COMPILER_INTEL |
129 | # define BS_THREADLOCAL __declspec(thread) |
130 | # endif |
131 | #endif |
132 | |
133 | // Linux/Mac Settings |
134 | #if BS_PLATFORM == BS_PLATFORM_LINUX || BS_PLATFORM == BS_PLATFORM_OSX |
135 | # ifdef DEBUG |
136 | # define BS_DEBUG_MODE 1 |
137 | # else |
138 | # define BS_DEBUG_MODE 0 |
139 | # endif |
140 | |
141 | # if BS_COMPILER == BS_COMPILER_INTEL |
142 | # define BS_THREADLOCAL __thread |
143 | # endif |
144 | #endif |