OpenVDB  8.1.1
Platform.h
Go to the documentation of this file.
1 // Copyright Contributors to the OpenVDB Project
2 // SPDX-License-Identifier: MPL-2.0
5 
6 #ifndef OPENVDB_PLATFORM_HAS_BEEN_INCLUDED
7 #define OPENVDB_PLATFORM_HAS_BEEN_INCLUDED
8 
9 #define PRAGMA(x) _Pragma(#x)
10 
14 #define OPENVDB_PREPROC_STRINGIFY_(x) #x
15 #define OPENVDB_PREPROC_STRINGIFY(x) OPENVDB_PREPROC_STRINGIFY_(x)
20 
22 #define OPENVDB_PREPROC_CONCAT_(x, y) x ## y
23 #define OPENVDB_PREPROC_CONCAT(x, y) OPENVDB_PREPROC_CONCAT_(x, y)
28 
31 #if defined(__GNUC__)
32  #define OPENVDB_CHECK_GCC(MAJOR, MINOR) \
33  (__GNUC__ > MAJOR || (__GNUC__ == MAJOR && __GNUC_MINOR__ >= MINOR))
34 #else
35  #define OPENVDB_CHECK_GCC(MAJOR, MINOR) 0
36 #endif
37 
39 #define OPENVDB_HAS_CXX11 1
40 
41 
43 #if defined(OPENVDB_USE_SSE42) || defined(OPENVDB_USE_AVX)
44  #if defined(_WIN32)
45  #include <intrin.h>
46  #elif defined(__GNUC__)
47  #if defined(__x86_64__) || defined(__i386__)
48  #include <x86intrin.h>
49  #elif defined(__ARM_NEON__)
50  #include <arm_neon.h>
51  #endif
52  #endif
53 #endif
54 
56 #ifdef _WIN32
57  // Math constants are not included in <cmath> unless _USE_MATH_DEFINES is
58  // defined on MSVC
59  // https://docs.microsoft.com/en-us/cpp/c-runtime-library/math-constants
60  #ifndef _USE_MATH_DEFINES
61  #define _USE_MATH_DEFINES
62  #endif
63  #ifndef NOMINMAX
65  #define NOMINMAX
66  #endif
67 
68  // By default, assume we're building OpenVDB as a DLL if we're dynamically
69  // linking in the CRT, unless OPENVDB_STATICLIB is defined.
70  #if defined(_DLL) && !defined(OPENVDB_STATICLIB) && !defined(OPENVDB_DLL)
71  #define OPENVDB_DLL
72  #endif
73 
74  // By default, assume that we're dynamically linking OpenEXR, unless
75  // OPENVDB_OPENEXR_STATICLIB is defined.
76  #if !defined(OPENVDB_OPENEXR_STATICLIB) && !defined(OPENEXR_DLL)
77  #define OPENEXR_DLL
78  #endif
79 #endif
80 
96 #if defined(__INTEL_COMPILER)
97  // Disable ICC remarks 111 ("statement is unreachable"), 128 ("loop is not reachable"),
98  // 185 ("dynamic initialization in unreachable code"), and 280 ("selector expression
99  // is constant").
100  #define OPENVDB_NO_UNREACHABLE_CODE_WARNING_BEGIN \
101  _Pragma("warning (push)") \
102  _Pragma("warning (disable:111)") \
103  _Pragma("warning (disable:128)") \
104  _Pragma("warning (disable:185)") \
105  _Pragma("warning (disable:280)")
106  #define OPENVDB_NO_UNREACHABLE_CODE_WARNING_END \
107  _Pragma("warning (pop)")
108 #elif defined(__clang__)
109  #define OPENVDB_NO_UNREACHABLE_CODE_WARNING_BEGIN \
110  PRAGMA(clang diagnostic push) \
111  PRAGMA(clang diagnostic ignored "-Wunreachable-code")
112  #define OPENVDB_NO_UNREACHABLE_CODE_WARNING_END \
113  PRAGMA(clang diagnostic pop)
114 #else
115  #define OPENVDB_NO_UNREACHABLE_CODE_WARNING_BEGIN
116  #define OPENVDB_NO_UNREACHABLE_CODE_WARNING_END
117 #endif
118 
121 #ifndef OPENVDB_NO_DEPRECATION_WARNINGS
122 #define OPENVDB_DEPRECATED [[deprecated]]
123 #define OPENVDB_DEPRECATED_MESSAGE(msg) [[deprecated(msg)]]
124 #else
125 #define OPENVDB_DEPRECATED
126 #define OPENVDB_DEPRECATED_MESSAGE(msg)
127 #endif
128 
142 #if defined __INTEL_COMPILER
143  #define OPENVDB_NO_DEPRECATION_WARNING_BEGIN \
144  _Pragma("warning (push)") \
145  _Pragma("warning (disable:1478)") \
146  PRAGMA(message("NOTE: ignoring deprecation warning at " __FILE__ \
147  ":" OPENVDB_PREPROC_STRINGIFY(__LINE__)))
148  #define OPENVDB_NO_DEPRECATION_WARNING_END \
149  _Pragma("warning (pop)")
150 #elif defined __clang__
151  #define OPENVDB_NO_DEPRECATION_WARNING_BEGIN \
152  _Pragma("clang diagnostic push") \
153  _Pragma("clang diagnostic ignored \"-Wdeprecated-declarations\"")
154  // note: no #pragma message, since Clang treats them as warnings
155  #define OPENVDB_NO_DEPRECATION_WARNING_END \
156  _Pragma("clang diagnostic pop")
157 #elif defined __GNUC__
158  #define OPENVDB_NO_DEPRECATION_WARNING_BEGIN \
159  _Pragma("GCC diagnostic push") \
160  _Pragma("GCC diagnostic ignored \"-Wdeprecated-declarations\"") \
161  _Pragma("message(\"NOTE: ignoring deprecation warning\")")
162  #define OPENVDB_NO_DEPRECATION_WARNING_END \
163  _Pragma("GCC diagnostic pop")
164 #elif defined _MSC_VER
165  #define OPENVDB_NO_DEPRECATION_WARNING_BEGIN \
166  __pragma(warning(push)) \
167  __pragma(warning(disable : 4996)) \
168  __pragma(message("NOTE: ignoring deprecation warning at " __FILE__ \
169  ":" OPENVDB_PREPROC_STRINGIFY(__LINE__)))
170  #define OPENVDB_NO_DEPRECATION_WARNING_END \
171  __pragma(warning(pop))
172 #else
173  #define OPENVDB_NO_DEPRECATION_WARNING_BEGIN
174  #define OPENVDB_NO_DEPRECATION_WARNING_END
175 #endif
176 
177 
188 #if defined __INTEL_COMPILER
189  #define OPENVDB_NO_TYPE_CONVERSION_WARNING_BEGIN
190  #define OPENVDB_NO_TYPE_CONVERSION_WARNING_END
191 #elif defined __GNUC__
192  // -Wfloat-conversion was only introduced in GCC 4.9
193  #if OPENVDB_CHECK_GCC(4, 9)
194  #define OPENVDB_NO_TYPE_CONVERSION_WARNING_BEGIN \
195  _Pragma("GCC diagnostic push") \
196  _Pragma("GCC diagnostic ignored \"-Wconversion\"") \
197  _Pragma("GCC diagnostic ignored \"-Wfloat-conversion\"")
198  #else
199  #define OPENVDB_NO_TYPE_CONVERSION_WARNING_BEGIN \
200  _Pragma("GCC diagnostic push") \
201  _Pragma("GCC diagnostic ignored \"-Wconversion\"")
202  #endif
203  #define OPENVDB_NO_TYPE_CONVERSION_WARNING_END \
204  _Pragma("GCC diagnostic pop")
205 #else
206  #define OPENVDB_NO_TYPE_CONVERSION_WARNING_BEGIN
207  #define OPENVDB_NO_TYPE_CONVERSION_WARNING_END
208 #endif
209 
211 #ifdef OPENVDB_EXPORT
212 #undef OPENVDB_EXPORT
213 #endif
214 #ifdef OPENVDB_IMPORT
215 #undef OPENVDB_IMPORT
216 #endif
217 #ifdef __GNUC__
218  #define OPENVDB_EXPORT __attribute__((visibility("default")))
219  #define OPENVDB_IMPORT __attribute__((visibility("default")))
220 #endif
221 #ifdef _WIN32
222  #ifdef OPENVDB_DLL
223  #define OPENVDB_EXPORT __declspec(dllexport)
224  #define OPENVDB_IMPORT __declspec(dllimport)
225  #else
226  #define OPENVDB_EXPORT
227  #define OPENVDB_IMPORT
228  #endif
229 #endif
230 
234 #ifdef OPENVDB_API
235 #undef OPENVDB_API
236 #endif
237 #ifdef OPENVDB_PRIVATE
238  #define OPENVDB_API OPENVDB_EXPORT
239 #else
240  #define OPENVDB_API OPENVDB_IMPORT
241 #endif
242 #ifdef OPENVDB_HOUDINI_API
243 #undef OPENVDB_HOUDINI_API
244 #endif
245 #ifdef OPENVDB_HOUDINI_PRIVATE
246  #define OPENVDB_HOUDINI_API OPENVDB_EXPORT
247 #else
248  #define OPENVDB_HOUDINI_API OPENVDB_IMPORT
249 #endif
250 
251 #if defined(__ICC)
252 
253 // Use these defines to bracket a region of code that has safe static accesses.
254 // Keep the region as small as possible.
255 #define OPENVDB_START_THREADSAFE_STATIC_REFERENCE __pragma(warning(disable:1710))
256 #define OPENVDB_FINISH_THREADSAFE_STATIC_REFERENCE __pragma(warning(default:1710))
257 #define OPENVDB_START_THREADSAFE_STATIC_WRITE __pragma(warning(disable:1711))
258 #define OPENVDB_FINISH_THREADSAFE_STATIC_WRITE __pragma(warning(default:1711))
259 #define OPENVDB_START_THREADSAFE_STATIC_ADDRESS __pragma(warning(disable:1712))
260 #define OPENVDB_FINISH_THREADSAFE_STATIC_ADDRESS __pragma(warning(default:1712))
261 
262 // Use these defines to bracket a region of code that has unsafe static accesses.
263 // Keep the region as small as possible.
264 #define OPENVDB_START_NON_THREADSAFE_STATIC_REFERENCE __pragma(warning(disable:1710))
265 #define OPENVDB_FINISH_NON_THREADSAFE_STATIC_REFERENCE __pragma(warning(default:1710))
266 #define OPENVDB_START_NON_THREADSAFE_STATIC_WRITE __pragma(warning(disable:1711))
267 #define OPENVDB_FINISH_NON_THREADSAFE_STATIC_WRITE __pragma(warning(default:1711))
268 #define OPENVDB_START_NON_THREADSAFE_STATIC_ADDRESS __pragma(warning(disable:1712))
269 #define OPENVDB_FINISH_NON_THREADSAFE_STATIC_ADDRESS __pragma(warning(default:1712))
270 
271 // Simpler version for one-line cases
272 #define OPENVDB_THREADSAFE_STATIC_REFERENCE(CODE) \
273  __pragma(warning(disable:1710)); CODE; __pragma(warning(default:1710))
274 #define OPENVDB_THREADSAFE_STATIC_WRITE(CODE) \
275  __pragma(warning(disable:1711)); CODE; __pragma(warning(default:1711))
276 #define OPENVDB_THREADSAFE_STATIC_ADDRESS(CODE) \
277  __pragma(warning(disable:1712)); CODE; __pragma(warning(default:1712))
278 
279 #else // GCC does not support these compiler warnings
280 
281 #define OPENVDB_START_THREADSAFE_STATIC_REFERENCE
282 #define OPENVDB_FINISH_THREADSAFE_STATIC_REFERENCE
283 #define OPENVDB_START_THREADSAFE_STATIC_WRITE
284 #define OPENVDB_FINISH_THREADSAFE_STATIC_WRITE
285 #define OPENVDB_START_THREADSAFE_STATIC_ADDRESS
286 #define OPENVDB_FINISH_THREADSAFE_STATIC_ADDRESS
287 
288 #define OPENVDB_START_NON_THREADSAFE_STATIC_REFERENCE
289 #define OPENVDB_FINISH_NON_THREADSAFE_STATIC_REFERENCE
290 #define OPENVDB_START_NON_THREADSAFE_STATIC_WRITE
291 #define OPENVDB_FINISH_NON_THREADSAFE_STATIC_WRITE
292 #define OPENVDB_START_NON_THREADSAFE_STATIC_ADDRESS
293 #define OPENVDB_FINISH_NON_THREADSAFE_STATIC_ADDRESS
294 
295 #define OPENVDB_THREADSAFE_STATIC_REFERENCE(CODE) CODE
296 #define OPENVDB_THREADSAFE_STATIC_WRITE(CODE) CODE
297 #define OPENVDB_THREADSAFE_STATIC_ADDRESS(CODE) CODE
298 
299 #endif // defined(__ICC)
300 
301 #endif // OPENVDB_PLATFORM_HAS_BEEN_INCLUDED