Spinning Topp Logo BlackTopp Studios
inc
crossplatformexport.h
Go to the documentation of this file.
1 // © Copyright 2010 - 2016 BlackTopp Studios Inc.
2 /* This file is part of The Mezzanine Engine.
3 
4  The Mezzanine Engine is free software: you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation, either version 3 of the License, or
7  (at your option) any later version.
8 
9  The Mezzanine Engine is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License
15  along with The Mezzanine Engine. If not, see <http://www.gnu.org/licenses/>.
16 */
17 /* The original authors have included a copy of the license specified above in the
18  'Docs' folder. See 'gpl.txt'
19 */
20 /* We welcome the use of the Mezzanine engine to anyone, including companies who wish to
21  Build professional software and charge for their product.
22 
23  However there are some practical restrictions, so if your project involves
24  any of the following you should contact us and we will try to work something
25  out:
26  - DRM or Copy Protection of any kind(except Copyrights)
27  - Software Patents You Do Not Wish to Freely License
28  - Any Kind of Linking to Non-GPL licensed Works
29  - Are Currently In Violation of Another Copyright Holder's GPL License
30  - If You want to change our code and not add a few hundred MB of stuff to
31  your distribution
32 
33  These and other limitations could cause serious legal problems if you ignore
34  them, so it is best to simply contact us or the Free Software Foundation, if
35  you have any questions.
36 
37  Joseph Toppi - toppij@gmail.com
38  John Blackwood - makoenergy02@gmail.com
39 */
40 #ifndef _crossplatformexports_h
41 #define _crossplatformexports_h
42 
43 /**
44  @file crossplatformexport.h
45  @brief This file is used on some platforms to determine what data should be read and written to
46  and from a shared/dynamic library.
47  @details Currently this file uses __declspec(dllexport) and __declspec(dllimport) on the windows
48  platform to control what is imported from or exported to the Mezzanine DLL. If MEZZ_WINDOWS if
49  defined then MEZZ_LIB will be set to either "__declspec(dllexport)" or "__declspec(dllimport)".
50  Every Class, function variable, and other item intended to be in Mezzanine is tagged with
51  MEZZ_LIB.
52 
53  @n @n
54  During compilation of the Mezzanine engine __declspec(dllexport) tells the compiler that a given
55  item (a function, class, etc...), should be included in the dll and made available for use in
56  games (or whatever kind of applicaitons use Mezzanine). This header sets MEZZ_LIB to
57  __declspec(dllexport) if EXPORTINGMEZZANINEDLL is set. If Mezzanine is compiled using the cmake
58  build provided then this is handle automatically. If the cmake build is not used, then this file
59  will attempt to detect if the platform t is running on is windows or not. It is preferable that
60  you configure your build environment to define MEZZ_WINDOWS and EXPORTINGMEZZANINEDLL if you are
61  compiling this on windows without the provided cmake build. \n \n
62 
63  Compilation of applications using Mezzanine __declspec(dllimport), tells the compiler what to
64  expect from the dll and may make optimizations available with some compilers. This is
65  automatically set if you use the cmake build, if you aren't this file will attempt to determine
66  if you are running windows. It is best to set the build envirnoment of your game or applciation
67  to define MEZZ_WINDOWS, if possible copy of our cmake builds for Catch! or the EngineDemo.
68 
69  @n @n
70  The Macro MEZZ_LIB is declared as empty if MEZZ_WINDOWS is not defined, as should be the case if
71  MEZZ_LINUX or MEZZ_MACOSX is defined. \n \n
72 
73 
74 */
75 /// @file
76 /// @brief Sets up some compiler variables that allow the Mezzanine to know what platform it is on.
77 
78 
79  // Check for other nonwindows OS
80  #ifdef MEZZ_LINUX
81  #define NONWINDOWS
82  #endif
83 
84  #ifdef MEZZ_MACOSX
85  #define NONWINDOWS
86  #endif
87 
88  // Check for windows, but not in a way that overides what is passed on the command prompt
89  #ifndef NONWINDOWS
90  #ifndef MEZZ_WINDOWS
91  #ifdef __WIN32__
92  #define MEZZ_WINDOWS
93  #endif
94 
95  #ifdef _WIN32
96  #define MEZZ_WINDOWS
97  #endif
98 
99  #ifdef __CYGWIN32__
100  #define MEZZ_WINDOWS
101  #endif
102 
103  #ifdef _MSC_VER
104  #define MEZZ_WINDOWS
105  #endif
106  #endif // MEZZ_WINDOWS
107  #endif // \NONWINDOWS
108 
109  /// @def MEZZ_LIB
110  /// @brief Some platforms require special decorations to denote what is exported/imported in a
111  /// share library. This is that decoration if when it is needed.
112  #ifdef MEZZ_WINDOWS
113  /// @def _MEZZ_THREAD_WIN32_
114  /// @brief Defined if this is running on windows.
115  #define _MEZZ_THREAD_WIN32_
116 
117  #ifdef _MSC_VER
118  #pragma warning( disable : 4251) // Disable the dll import/export warnings on items that
119  // are set correctly.
120  #pragma warning( disable : 4244) // Disable the double to float conversions, they are in
121  // their by design to minimize floating point rounding
122  // during intermediate calculations.
123  #pragma warning( disable : 4127) // Disable conditional expression is constant
124  #pragma warning( disable : 4800) // pugi xml unspecified bool type coercion has
125  // performance cost, used only in unit tests
126  #pragma warning( disable : 4221) // interfaces don't generate linkable symbols, well of
127  // course they don't
128  #pragma warning( disable : 4512) // Could not generate assignment operator for class
129  // that doesn't need one
130  #endif
131 
132  /// @details if this is not defined, then most likely _MEZZ_THREAD_POSIX_ is.
133  #ifdef EXPORTINGMEZZANINEDLL
134  #define MEZZ_LIB __declspec(dllexport)
135  #else
136  #define MEZZ_LIB __declspec(dllimport)
137  #endif // \EXPORTINGMEZZANINEDLL
138  #else
139  #define MEZZ_LIB
140  /// @def _MEZZ_THREAD_POSIX_
141  /// @brief Defined if this is running on Linux, Mac OS X, Android, or any other sane
142  /// platform.
143  /// @details if this is not defined, then most likely _MEZZ_THREAD_WIN32_ is.
144  #define _MEZZ_THREAD_POSIX_
145  #if defined(__APPLE__) || defined(__MACH__) || defined(__OSX__)
146  /// @def _MEZZ_THREAD_APPLE_
147  /// @brief Sometimes specific workarounds are required for Mac OS this is how we detect
148  /// it.
149  #define _MEZZ_THREAD_APPLE_
150  #endif
151  #endif // \WINDOWS
152 
153  #define _MEZZ_PLATFORM_DEFINED_
154 
155  /// @def MEZZ_DEPRECATED
156  /// @brief Used to mark old functionality that should not be used as such. In supported
157  /// compilers using such functionality should produce warnings.
158  #ifndef MEZZ_DEPRECATED
159  #if defined(__GNUC__)
160  #define MEZZ_DEPRECATED __attribute__((deprecated))
161  #elif defined(_MSC_VER) && _MSC_VER >= 1300
162  #define MEZZ_DEPRECATED __declspec(deprecated)
163  #else
164  #define MEZZ_DEPRECATED
165  #endif
166  #endif
167 
168  /// @def MEZZ_USEATOMICSTODECACHECOMPLETEWORK
169  /// @brief This is used to configure whether to atomically store a shortcut to skip checking all
170  /// workunits.
171  /// @details When this is enabled @ref Mezzanine::Threading::AtomicCompareAndSwap32 "Atomic CAS"
172  /// operations are used to maintain a count of the number of complete workunits at the beginning
173  /// of the work unit listings. Normally these listings are read-only during frame execution, and
174  /// the work units store whether or not they are complete. The default algorithm forces
175  /// iteration over a large number of work units to simply check for completion in some
176  /// situations. If memory bandwidth is slow or limited this can be a large source of of
177  /// contention. Enable this option when there are many work units trades atomic operations for
178  /// memory bandwidth. This must be tested on a per system basis to determine full preformance
179  /// ramifications. This is controlled by the CMake (or other build system) option
180  /// Mezz_DecacheWorkUnits.
181  #ifndef MEZZ_USEATOMICSTODECACHECOMPLETEWORK
182  #define MEZZ_USEATOMICSTODECACHECOMPLETEWORK
183  #endif
184  #ifndef _MEZZ_DECACHEWORKUNIT_
185  #undef MEZZ_USEATOMICSTODECACHECOMPLETEWORK
186  #endif
187 
188  /// @def MEZZ_FRAMESTOTRACK
189  /// @brief Used to control how long frames track length and other similar values. This is
190  /// controlled by the CMake (or other build system) option Mezz_FramesToTrack.
191  #ifndef MEZZ_FRAMESTOTRACK
192  #define MEZZ_FRAMESTOTRACK 10
193  #endif
194  #ifdef _MEZZ_FRAMESTOTRACK_
195  #undef MEZZ_FRAMESTOTRACK
196  #define MEZZ_FRAMESTOTRACK _MEZZ_FRAMESTOTRACK_
197  #endif
198 
199  /// @def WINAPI
200  /// @brief Calling some win32 api functions require special calling conventions, this is their
201  /// configuration.
202  #ifdef MEZZ_WINDOWS
203  #define WINAPI __stdcall
204  #else
205  #define WINAPI ErrorThisOnlyGoesInwin32Code
206  #endif
207 
208 
209  /// @def SAVE_WARNING_STATE
210  /// @brief Saves thes State in the compiler which detemines what warnings will be captured. Must
211  /// be used with @ref RESTORE_WARNING_STATE to prevent compilation issues.
212  /// @sa RESTORE_WARNING_STATE
213 
214  /// @def SUPPRESS_VC_WARNING
215  /// @brief If in visual studio this resolves to a pragma that supresses a warning, if not it
216  /// resolves to nothing.
217 
218  /// @def SUPPRESS_GCC_WARNING
219  /// @brief If in or a compatible compiler this resolves to a pragma that supresses a warning, if
220  /// not it resolves to nothing.
221 
222  /// @def RESTORE_WARNING_STATE
223  /// @brief Restores the last warning state saved with @ref SAVE_WARNING_STATE. This cleans up after
224  /// @ref SAVE_WARNING_STATE
225  /// @note Part of the C++ API only.
226  /// @sa SAVE_WARNING_STATE
227 
228  #ifndef SWIG
229  #ifdef _MSC_VER // The intel compiler might act up here
230  #define SAVE_WARNING_STATE PRAGMA(warning(push))
231  #define SUPPRESS_VC_WARNING(suppress) PRAGMA(warning(disable: ## suppress ## ))
232  #define SUPPRESS_GCC_WARNING(suppress)
233  #define RESTORE_WARNING_STATE PRAGMA(warning(pop))
234  #define PRAGMA(x) __pragma(x)
235  #else
236  #define SAVE_WARNING_STATE PRAGMA(GCC diagnostic push)
237  #define SUPPRESS_VC_WARNING(X)
238  #define SUPPRESS_GCC_WARNING(X) PRAGMA(GCC diagnostic ignored X)
239  #define RESTORE_WARNING_STATE PRAGMA(GCC diagnostic pop)
240  #define PRAGMA(x) _Pragma(#x)
241  #endif
242  #endif
243 
244 
245 #endif