Mitsuba Renderer  0.5.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
platform.h
Go to the documentation of this file.
1 /*
2  This file is part of Mitsuba, a physically based rendering system.
3 
4  Copyright (c) 2007-2014 by Wenzel Jakob and others.
5 
6  Mitsuba is free software; you can redistribute it and/or modify
7  it under the terms of the GNU General Public License Version 3
8  as published by the Free Software Foundation.
9 
10  Mitsuba is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License
16  along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18 
19 #pragma once
20 #if !defined(__MITSUBA_CORE_PLATFORM_H_)
21 #define __MITSUBA_CORE_PLATFORM_H_
22 
23 /// Disable BOOST's autolinking feature
24 #define BOOST_ALL_NO_LIB 1
25 
26 #if !defined(_OPENMP) && !defined(MTS_NO_OPENMP)
27  #define MTS_NO_OPENMP
28 #endif
29 
30 #if defined(_MSC_VER)
31  #define __MSVC__
32  #define __WINDOWS__
33 
34  // Don't complain about perfectly fine ISO C++
35  #define _CRT_SECURE_NO_WARNINGS
36  #define _CRT_NONSTDC_NO_DEPRECATE
37  #define _CRT_SECURE_NO_DEPRECATE
38 
39  #define _WIN32_WINNT 0x0501 // Windows XP
40  #define NOMINMAX
41  #define WIN32_LEAN_AND_MEAN
42 
43  #pragma warning(disable : 4251) // 'field' : class 'A' needs to have dll-interface to be used by clients of class 'B'
44  #pragma warning(disable : 4800) // 'type' : forcing value to bool 'true' or 'false' (performance warning)
45  #pragma warning(disable : 4996) // Secure SCL warnings
46 
47  #include <stdint.h>
48 
49  #if _MSC_VER >= 1400
50  #include <memory.h>
51  #include <string.h>
52  #include <math.h>
53  #pragma intrinsic(memset, memcmp, memcpy, strlen, strcmp, strcpy, _strset, strcat, fabs, abs)
54  #endif
55 
56  #if _MSC_VER >= 1600
57  #ifdef SINGLE_PRECISION
58  #pragma detect_mismatch( "MTS_FLOAT_PRECISION", "SINGLE")
59  #elif DOUBLE_PRECISION
60  #pragma detect_mismatch( "MTS_FLOAT_PRECISION", "DOUBLE")
61  #endif
62  #define MTS_STRINGIFY(s) #s
63  #define MTS_XSTRINGIFY(s) MTS_STRINGIFY(s)
64  #pragma detect_mismatch("MTS_SPECTRUM_SAMPLES", MTS_XSTRINGIFY(SPECTRUM_SAMPLES))
65  #endif
66 #elif defined(__APPLE__)
67  #define __OSX__
68 #elif defined(__linux)
69  #define __LINUX__
70  #if !defined(_GNU_SOURCE)
71  #define _GNU_SOURCE
72  #endif
73 #else
74  #error Unknown OS
75 #endif
76 
77 #ifdef __MSVC__
78  #define MTS_DONT_EXPORT // not supported on MSVC
79  #define SIZE_T_FMT "%Iu"
80  #define BOOST_FILESYSTEM_NO_LIB
81  #define BOOST_SYSTEM_NO_LIB
82  #define MTS_EXPORT __declspec(dllexport)
83  #define MTS_IMPORT __declspec(dllimport)
84  #define MTS_MAY_ALIAS // not supported on Windows
85 #else
86  #define MTS_EXPORT __attribute__ ((visibility("default")))
87  #define MTS_IMPORT
88  #define MTS_MAY_ALIAS __attribute__ ((__may_alias__))
89 
90  #include <stdint.h>
91 
92  #define SIZE_T_FMT "%zd"
93 #endif
94 
95 #define MTS_MODULE_CORE 1
96 #define MTS_MODULE_RENDER 2
97 #define MTS_MODULE_HW 3
98 #define MTS_MODULE_BIDIR 4
99 #define MTS_MODULE_PYTHON 5
100 
101 #if MTS_BUILD_MODULE == MTS_MODULE_CORE
102  #define MTS_EXPORT_CORE MTS_EXPORT
103 #else
104  #define MTS_EXPORT_CORE MTS_IMPORT
105 #endif
106 #if MTS_BUILD_MODULE == MTS_MODULE_RENDER
107  #define MTS_EXPORT_RENDER MTS_EXPORT
108 #else
109  #define MTS_EXPORT_RENDER MTS_IMPORT
110 #endif
111 #if MTS_BUILD_MODULE == MTS_MODULE_HW
112  #define MTS_EXPORT_HW MTS_EXPORT
113 #else
114  #define MTS_EXPORT_HW MTS_IMPORT
115 #endif
116 #if MTS_BUILD_MODULE == MTS_MODULE_BIDIR
117  #define MTS_EXPORT_BIDIR MTS_EXPORT
118 #else
119  #define MTS_EXPORT_BIDIR MTS_IMPORT
120 #endif
121 #if MTS_BUILD_MODULE == MTS_MODULE_PYTHON
122  #define MTS_EXPORT_PYTHON MTS_EXPORT
123 #else
124  #define MTS_EXPORT_PYTHON MTS_IMPORT
125 #endif
126 
127 #if defined(__x86_64__) || defined(_M_X64) || defined(__LP64__) || defined(_LP64) || defined(WIN64)
128 #define __64BIT__
129 #else
130 #define __32BIT__
131 #endif
132 
133 #if !defined(__LITTLE_ENDIAN__) && !defined(__BIG_ENDIAN__)
134 #define __LITTLE_ENDIAN__ 1 // Little endian by default
135 #endif
136 
137 #define MTS_NAMESPACE_BEGIN namespace mitsuba {
138 #define MTS_NAMESPACE_END }
139 
140 #if defined(__GNUC__)
141 #define FINLINE inline __attribute__((always_inline))
142 #define NOINLINE __attribute__((noinline))
143 #define EXPECT_TAKEN(a) __builtin_expect(!!(a), true)
144 #define EXPECT_NOT_TAKEN(a) __builtin_expect(!!(a), false)
145 #elif defined(__MSVC__)
146 #define FINLINE __forceinline
147 #define NOINLINE __declspec(noinline)
148 #define MM_ALIGN16 __declspec(align(16))
149 #define EXPECT_TAKEN(a) (a)
150 #define EXPECT_NOT_TAKEN(a) (a)
151 #else
152 #error Unsupported compiler!
153 #endif
154 
155 #ifdef MTS_SSE
156 #define SSE_STR "SSE2 enabled"
157 #else
158 #define SSE_STR "SSE2 disabled"
159 #endif
160 
161 /* The default OpenMP implementation on OSX is seriously broken,
162  for instance it segfaults when launching OpenMP threads
163  from context other than the main application thread */
164 #if defined(__OSX__) && !defined(__INTEL_COMPILER) && !defined(MTS_NO_OPENMP)
165 #define MTS_NO_OPENMP
166 #endif
167 
168 #if !defined(MTS_NO_OPENMP)
169 #define MTS_OPENMP
170 #endif
171 
172 /* Compile with Boost::Filesystem v3 */
173 #define BOOST_FILESYSTEM_VERSION 3
174 
175 #include <string>
176 
178 
179 #if defined(DOUBLE_PRECISION)
180 typedef double Float;
181 #elif defined(SINGLE_PRECISION)
182 typedef float Float;
183 #else
184 #error No precision flag was defined!
185 #endif
186 
187 #if defined(__OSX__)
188 extern MTS_EXPORT_CORE void __mts_autorelease_init();
189 extern MTS_EXPORT_CORE void __mts_autorelease_shutdown();
190 extern MTS_EXPORT_CORE void __mts_autorelease_begin();
191 extern MTS_EXPORT_CORE void __mts_autorelease_end();
192 extern MTS_EXPORT_CORE std::string __mts_bundlepath();
193 extern MTS_EXPORT_CORE void __mts_chdir_to_bundlepath();
194 extern MTS_EXPORT_CORE void __mts_init_cocoa();
195 extern MTS_EXPORT_CORE void __mts_set_appdefaults();
196 #define MTS_AUTORELEASE_BEGIN() __mts_autorelease_begin();
197 #define MTS_AUTORELEASE_END() __mts_autorelease_end();
198 #define MTS_AMBIGUOUS_SIZE_T 1
199 #else
200 #define MTS_AUTORELEASE_BEGIN()
201 #define MTS_AUTORELEASE_END()
202 #endif
203 
205 
206 
207 /// \cond
208 // Try to make MSVC++ behave a bit more like C++
209 // with an underlying C99 implementation
210 // (and don't include this in the documentation)
211 #if defined(_MSC_VER)
212 
213 #include <float.h>
214 
215 #define snprintf _snprintf
216 #define vsnprintf _vsnprintf
217 
218 namespace mitsuba {
219 #if defined(__64BIT__)
220 typedef long long ssize_t;
221 #else
222 typedef long ssize_t;
223 #endif
224 };
225 
226 namespace std {
227  inline char tolower(char c) {
228  return ::tolower(c);
229  }
230 
231  inline char toupper(char c) {
232  return ::toupper(c);
233  }
234 
235  inline bool isnan(float f) {
236  return _isnan(f);
237  }
238 
239  inline bool isnan(double f) {
240  return _isnan(f);
241  }
242 
243  inline bool isfinite(float f) {
244  return _finite(f);
245  }
246 
247  inline bool isfinite(double f) {
248  return _finite(f);
249  }
250 
251  inline bool isinf(float f) {
252  return !_finite(f);
253  }
254 
255  inline bool isinf(double f) {
256  return !_finite(f);
257  }
258 };
259 #endif
260 /// \endcond
261 
262 #endif /* __MITSUBA_CORE_PLATFORM_H_ */
#define MTS_NAMESPACE_BEGIN
Definition: platform.h:137
#define MTS_EXPORT_CORE
Definition: platform.h:104
#define MTS_NAMESPACE_END
Definition: platform.h:138