MezzanineEngine 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
crossplatformexport.h
Go to the documentation of this file.
1 // © Copyright 2010 - 2014 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 and from a shared/dynamic library.
46  @details Currently this file uses __declspec(dllexport) and __declspec(dllimport) on the windows platform to control what
47  is imported from or exported to the Mezzanine DLL. If WINDOWS if defined then MEZZ_LIB will be set to either "__declspec(dllexport)"
48  or "__declspec(dllimport)". Every Class, template, function variable, and other item intended to be in Mezzanine is tagged with
49  MEZZ_LIB. \n \n
50 
51  During compilation of the Mezzanine engine __declspec(dllexport) tells the compiler that a given item (a function, class, template,
52  etc...), should be included in the dll and made available for use in games (or whatever kind of applicaitons use Mezzanine). This
53  header sets MEZZ_LIB to __declspec(dllexport) if EXPORTINGPHYSGAMEDLL is set. If Mezzanine is compiled using the cmake build
54  provided then this is handle automatically. If the cmake build is not used, then this file will attempt to detect if the platform
55  it is running on is windows or not. It is preferable that you configure your build environment to define WINDOWS and EXPORTINGMEZZANINEDLL
56  if you are compiling this on windows without the provided cmake build. \n \n
57 
58  Compilation of applications using Mezzanine __declspec(dllimport), tells the compiler what to expect from the dll and may make
59  optimizations available with some compilers. This is automatically set if you use the cmake build, if you aren't this file will
60  attempt to determine if you are running windows. It is best to set the build envirnoment of your game or applciation to define
61  WINDOWS, if possible copy of our cmake builds for Catch! or the EngineDemo. \n \n
62 
63  The Macro MEZZ_LIB is declared as empty if WINDOWS is not defined, as should be the case if LINUX or MACOSX is defined. \n \n
64 
65 
66 */
67 /// @file
68 /// @brief Sets up some compiler variables that allow the Mezzanine to know what platform it is on.
69 
70 
71  // Check for other nonwindows OS
72  #ifdef LINUX
73  #define NONWINDOWS
74  #endif
75 
76  #ifdef MACOSX
77  #define NONWINDOWS
78  #endif
79 
80  // ©heck for windows, but not in a way that overides what is passed on the command prompt
81  #ifndef NONWINDOWS
82  #ifndef WINDOWS
83  #ifdef __WIN32__
84  #define WINDOWS
85  #endif
86 
87  #ifdef _WIN32
88  #define WINDOWS
89  #endif
90 
91  #ifdef __CYGWIN32__
92  #define WINDOWS
93  #endif
94 
95  #ifdef _MSC_VER
96  #define WINDOWS
97  #endif
98  #endif // WINDOWS
99  #endif // \NONWINDOWS
100 
101  /// @def MEZZ_LIB
102  /// @brief Some platforms require special decorations to denote what is exported/imported in a share library. This is that decoration if when it is needed.
103  #ifdef WINDOWS
104  /// @def _MEZZ_THREAD_WIN32_
105  /// @brief Defined if this is running on windows.
106  #define _MEZZ_THREAD_WIN32_
107 
108  #ifdef _MSC_VER
109  #pragma warning( disable : 4251) // Disable the dll import/export warnings on items that are set correctly.
110  #pragma warning( disable : 4244) // Disable the double to float conversions, they are in their by design to minimize floating point rounding during intermediate calculations.
111  #pragma warning( disable : 4127) // Disable conditional expression is constant
112  #pragma warning( disable : 4800) // pugi xml unspecified bool type coercion has performance cost, used only in unit tests
113  #pragma warning( disable : 4221) // interfaces don't generate linkable symbols, well of course they don't
114  #pragma warning( disable : 4512) // Could not generate assignment operator for class that doesn't need one
115  #endif
116 
117  /// @details if this is not defined, then most likely _MEZZ_THREAD_POSIX_ is.
118  #ifdef EXPORTINGMEZZANINEDLL
119  #define MEZZ_LIB __declspec(dllexport)
120  #else
121  #define MEZZ_LIB __declspec(dllimport)
122  #endif // \EXPORTINGMEZZANINEDLL
123  #else
124  #define MEZZ_LIB
125  /// @def _MEZZ_THREAD_POSIX_
126  /// @brief Defined if this is running on Linux, Mac OS X, Android, or any other sane platform.
127  /// @details if this is not defined, then most likely _MEZZ_THREAD_WIN32_ is.
128  #define _MEZZ_THREAD_POSIX_
129  #if defined(__APPLE__) || defined(__MACH__) || defined(__OSX__)
130  /// @def _MEZZ_THREAD_APPLE_
131  /// @brief Sometimes specific workarounds are required for Mac OS this is how we detect it.
132  #define _MEZZ_THREAD_APPLE_
133  #endif
134  #endif // \WINDOWS
135 
136  #define _MEZZ_PLATFORM_DEFINED_
137 
138  /// @def MEZZ_DEPRECATED
139  /// @brief Used to mark old functionality that should not be used as such. In supported compilers using such functionality should produce warnings.
140  #ifndef MEZZ_DEPRECATED
141  #if defined(__GNUC__)
142  #define MEZZ_DEPRECATED __attribute__((deprecated))
143  #elif defined(_MSC_VER) && _MSC_VER >= 1300
144  #define MEZZ_DEPRECATED __declspec(deprecated)
145  #else
146  #define MEZZ_DEPRECATED
147  #endif
148  #endif
149 
150 
151  /// @def MEZZ_USEBARRIERSEACHFRAME
152  /// @brief This is used to configure whether to re-create threads each frame of or synchronize.
153  /// @details Any synchronization will be done with atomic @ref Mezzanine::Threading::Barrier "Barrier". This is
154  /// controlled by the CMake (or other build system) option Mezz_MinimizeThreadsEachFrame.
155  #ifndef MEZZ_USEBARRIERSEACHFRAME
156  #define MEZZ_USEBARRIERSEACHFRAME
157  #endif
158  #ifndef _MEZZ_MINTHREADS_
159  #undef MEZZ_USEBARRIERSEACHFRAME
160  #endif
161 
162  /// @def MEZZ_USEATOMICSTODECACHECOMPLETEWORK
163  /// @brief This is used to configure whether to atomically store a shortcut to skip checking all workunits.
164  /// @details When this is enabled @ref Mezzanine::Threading::AtomicCompareAndSwap32 "Atomic CAS" operations are used to maintain
165  /// a count of the number of complete workunits at the beginning of the work unit listings. Normally these
166  /// listings are read-only during frame execution, and the work units store whether or not they are
167  /// complete. The default algorithm forces iteration over a large number of work units to simply check for
168  /// completion in some situations. If memory bandwidth is slow or limited this can be a large source of
169  /// of contention. Enable this option when there are many work units trades atomic operations for memory
170  /// bandwidth. This must be tested on a per system basis to determine full preformance ramifications. This
171  /// is controlled by the CMake (or other build system) option Mezz_DecacheWorkUnits.
172  #ifndef MEZZ_USEATOMICSTODECACHECOMPLETEWORK
173  #define MEZZ_USEATOMICSTODECACHECOMPLETEWORK
174  #endif
175  #ifndef _MEZZ_DECACHEWORKUNIT_
176  #undef MEZZ_USEATOMICSTODECACHECOMPLETEWORK
177  #endif
178 
179  /// @def MEZZ_FRAMESTOTRACK
180  /// @brief Used to control how long frames track length and other similar values. This is
181  /// controlled by the CMake (or other build system) option Mezz_FramesToTrack.
182  #ifndef MEZZ_FRAMESTOTRACK
183  #define MEZZ_FRAMESTOTRACK 10
184  #endif
185  #ifdef _MEZZ_FRAMESTOTRACK_
186  #undef MEZZ_FRAMESTOTRACK
187  #define MEZZ_FRAMESTOTRACK _MEZZ_FRAMESTOTRACK_
188  #endif
189 
190  /// @def WINAPI
191  /// @brief Calling some win32 api functions require special calling conventions, this is their configuration.
192  #ifdef WINDOWS
193  #define WINAPI __stdcall
194  #else
195  #define WINAPI ErrorThisOnlyGoesInwin32Code
196  #endif
197 #endif