OpenVDB 10.0.1
Loading...
Searching...
No Matches
Platform.h
Go to the documentation of this file.
1// Copyright Contributors to the OpenVDB Project
2// SPDX-License-Identifier: MPL-2.0
3///
4/// @file Platform.h
5
6#ifndef OPENVDB_PLATFORM_HAS_BEEN_INCLUDED
7#define OPENVDB_PLATFORM_HAS_BEEN_INCLUDED
8
9#define PRAGMA(x) _Pragma(#x)
10
11/// @name Utilities
12/// @{
13/// @cond OPENVDB_DOCS_INTERNAL
14#define OPENVDB_PREPROC_STRINGIFY_(x) #x
15/// @endcond
16/// @brief Return @a x as a string literal. If @a x is a macro,
17/// return its value as a string literal.
18/// @hideinitializer
19#define OPENVDB_PREPROC_STRINGIFY(x) OPENVDB_PREPROC_STRINGIFY_(x)
20
21/// @cond OPENVDB_DOCS_INTERNAL
22#define OPENVDB_PREPROC_CONCAT_(x, y) x ## y
23/// @endcond
24/// @brief Form a new token by concatenating two existing tokens.
25/// If either token is a macro, concatenate its value.
26/// @hideinitializer
27#define OPENVDB_PREPROC_CONCAT(x, y) OPENVDB_PREPROC_CONCAT_(x, y)
28/// @}
29
30/// Macro for determining if GCC version is >= than X.Y
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
38/// OpenVDB now requires C++11
39#define OPENVDB_HAS_CXX11 1
40
41
42/// SIMD Intrinsic Headers
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
55/// Windows defines
56#ifdef _WIN32
57 ///Disable the non-portable Windows definitions of min() and max() macros
58 #ifndef NOMINMAX
59 #define NOMINMAX
60 #endif
61
62 // By default, assume we're building OpenVDB as a DLL if we're dynamically
63 // linking in the CRT, unless OPENVDB_STATICLIB is defined.
64 #if defined(_DLL) && !defined(OPENVDB_STATICLIB) && !defined(OPENVDB_DLL)
65 #define OPENVDB_DLL
66 #endif
67
68 // By default, assume that we're dynamically linking OpenEXR, unless
69 // OPENVDB_OPENEXR_STATICLIB is defined.
70 #if !defined(OPENVDB_OPENEXR_STATICLIB) && !defined(OPENEXR_DLL)
71 #define OPENEXR_DLL
72 #endif
73#endif
74
75/// Macros to suppress undefined behaviour sanitizer warnings. Should be used
76/// sparingly, primarily to suppress issues in upstream dependencies.
77#if defined(__clang__)
78#define OPENVDB_UBSAN_SUPPRESS(X) __attribute__((no_sanitize(X)))
79#else
80#define OPENVDB_UBSAN_SUPPRESS(X)
81#endif
82
83/// Bracket code with OPENVDB_NO_UNREACHABLE_CODE_WARNING_BEGIN/_END,
84/// as in the following example, to inhibit ICC remarks about unreachable code:
85/// @code
86/// template<typename NodeType>
87/// void processNode(NodeType& node)
88/// {
89/// OPENVDB_NO_UNREACHABLE_CODE_WARNING_BEGIN
90/// if (NodeType::LEVEL == 0) return; // ignore leaf nodes
91/// int i = 0;
92/// ...
93/// OPENVDB_NO_UNREACHABLE_CODE_WARNING_END
94/// }
95/// @endcode
96/// In the above, <tt>NodeType::LEVEL == 0</tt> is a compile-time constant expression,
97/// so for some template instantiations, the line below it is unreachable.
98#if defined(__INTEL_COMPILER)
99 // Disable ICC remarks 111 ("statement is unreachable"), 128 ("loop is not reachable"),
100 // 185 ("dynamic initialization in unreachable code"), and 280 ("selector expression
101 // is constant").
102 #define OPENVDB_NO_UNREACHABLE_CODE_WARNING_BEGIN \
103 _Pragma("warning (push)") \
104 _Pragma("warning (disable:111)") \
105 _Pragma("warning (disable:128)") \
106 _Pragma("warning (disable:185)") \
107 _Pragma("warning (disable:280)")
108 #define OPENVDB_NO_UNREACHABLE_CODE_WARNING_END \
109 _Pragma("warning (pop)")
110#elif defined(__clang__)
111 #define OPENVDB_NO_UNREACHABLE_CODE_WARNING_BEGIN \
112 PRAGMA(clang diagnostic push) \
113 PRAGMA(clang diagnostic ignored "-Wunreachable-code")
114 #define OPENVDB_NO_UNREACHABLE_CODE_WARNING_END \
115 PRAGMA(clang diagnostic pop)
116#else
117 #define OPENVDB_NO_UNREACHABLE_CODE_WARNING_BEGIN
118 #define OPENVDB_NO_UNREACHABLE_CODE_WARNING_END
119#endif
120
121/// Deprecation macros. Define OPENVDB_NO_DEPRECATION_WARNINGS to disable all
122/// deprecation warnings in OpenVDB.
123#ifndef OPENVDB_NO_DEPRECATION_WARNINGS
124#define OPENVDB_DEPRECATED [[deprecated]]
125#define OPENVDB_DEPRECATED_MESSAGE(msg) [[deprecated(msg)]]
126#else
127#define OPENVDB_DEPRECATED
128#define OPENVDB_DEPRECATED_MESSAGE(msg)
129#endif
130
131/// @brief Bracket code with OPENVDB_NO_DEPRECATION_WARNING_BEGIN/_END,
132/// to inhibit warnings about deprecated code.
133/// @note Only intended to be used internally whilst parent code is being
134/// deprecated
135/// @details Example:
136/// @code
137/// OPENVDB_DEPRECATED void myDeprecatedFunction() {}
138///
139/// {
140/// OPENVDB_NO_DEPRECATION_WARNING_BEGIN
141/// myDeprecatedFunction();
142/// OPENVDB_NO_DEPRECATION_WARNING_END
143/// }
144/// @endcode
145#if defined __INTEL_COMPILER
146 #define OPENVDB_NO_DEPRECATION_WARNING_BEGIN \
147 _Pragma("warning (push)") \
148 _Pragma("warning (disable:1478)")
149 #define OPENVDB_NO_DEPRECATION_WARNING_END \
150 _Pragma("warning (pop)")
151#elif defined __clang__
152 #define OPENVDB_NO_DEPRECATION_WARNING_BEGIN \
153 _Pragma("clang diagnostic push") \
154 _Pragma("clang diagnostic ignored \"-Wdeprecated-declarations\"")
155 // note: no #pragma message, since Clang treats them as warnings
156 #define OPENVDB_NO_DEPRECATION_WARNING_END \
157 _Pragma("clang diagnostic pop")
158#elif defined __GNUC__
159 #define OPENVDB_NO_DEPRECATION_WARNING_BEGIN \
160 _Pragma("GCC diagnostic push") \
161 _Pragma("GCC diagnostic ignored \"-Wdeprecated-declarations\"")
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 #define OPENVDB_NO_DEPRECATION_WARNING_END \
169 __pragma(warning(pop))
170#else
171 #define OPENVDB_NO_DEPRECATION_WARNING_BEGIN
172 #define OPENVDB_NO_DEPRECATION_WARNING_END
173#endif
174
175
176/// @brief Bracket code with OPENVDB_NO_TYPE_CONVERSION_WARNING_BEGIN/_END,
177/// to inhibit warnings about type conversion.
178/// @note Use this sparingly. Use static casts and explicit type conversion if at all possible.
179/// @details Example:
180/// @code
181/// float value = 0.1f;
182/// OPENVDB_NO_TYPE_CONVERSION_WARNING_BEGIN
183/// int valueAsInt = value;
184/// OPENVDB_NO_TYPE_CONVERSION_WARNING_END
185/// @endcode
186#if defined __INTEL_COMPILER
187 #define OPENVDB_NO_TYPE_CONVERSION_WARNING_BEGIN
188 #define OPENVDB_NO_TYPE_CONVERSION_WARNING_END
189#elif defined __GNUC__
190 // -Wfloat-conversion was only introduced in GCC 4.9
191 #if OPENVDB_CHECK_GCC(4, 9)
192 #define OPENVDB_NO_TYPE_CONVERSION_WARNING_BEGIN \
193 _Pragma("GCC diagnostic push") \
194 _Pragma("GCC diagnostic ignored \"-Wconversion\"") \
195 _Pragma("GCC diagnostic ignored \"-Wfloat-conversion\"")
196 #else
197 #define OPENVDB_NO_TYPE_CONVERSION_WARNING_BEGIN \
198 _Pragma("GCC diagnostic push") \
199 _Pragma("GCC diagnostic ignored \"-Wconversion\"")
200 #endif
201 #define OPENVDB_NO_TYPE_CONVERSION_WARNING_END \
202 _Pragma("GCC diagnostic pop")
203#else
204 #define OPENVDB_NO_TYPE_CONVERSION_WARNING_BEGIN
205 #define OPENVDB_NO_TYPE_CONVERSION_WARNING_END
206#endif
207
208/// Helper macros for defining library symbol visibility
209#ifdef OPENVDB_EXPORT
210#undef OPENVDB_EXPORT
211#endif
212#ifdef OPENVDB_IMPORT
213#undef OPENVDB_IMPORT
214#endif
215#ifdef _WIN32
216 #ifdef OPENVDB_DLL
217 #define OPENVDB_EXPORT __declspec(dllexport)
218 #define OPENVDB_IMPORT __declspec(dllimport)
219 #else
220 #define OPENVDB_EXPORT
221 #define OPENVDB_IMPORT
222 #endif
223#elif defined(__GNUC__)
224 #define OPENVDB_EXPORT __attribute__((visibility("default")))
225 #define OPENVDB_IMPORT __attribute__((visibility("default")))
226#endif
227
228/// Helper macros for explicit template instantiation
229#if defined(_WIN32) && defined(OPENVDB_DLL)
230 #ifdef OPENVDB_PRIVATE
231 #define OPENVDB_TEMPLATE_EXPORT OPENVDB_EXPORT
232 #define OPENVDB_TEMPLATE_IMPORT
233 #else
234 #define OPENVDB_TEMPLATE_EXPORT
235 #define OPENVDB_TEMPLATE_IMPORT OPENVDB_IMPORT
236 #endif
237#else
238 #define OPENVDB_TEMPLATE_IMPORT
239 #define OPENVDB_TEMPLATE_EXPORT
240#endif
241
242/// All classes and public free standing functions must be explicitly marked
243/// as <lib>_API to be exported. The <lib>_PRIVATE macros are defined when
244/// building that particular library.
245#ifdef OPENVDB_API
246#undef OPENVDB_API
247#endif
248#ifdef OPENVDB_PRIVATE
249 #define OPENVDB_API OPENVDB_EXPORT
250#else
251 #define OPENVDB_API OPENVDB_IMPORT
252#endif
253#ifdef OPENVDB_HOUDINI_API
254#undef OPENVDB_HOUDINI_API
255#endif
256#ifdef OPENVDB_HOUDINI_PRIVATE
257 #define OPENVDB_HOUDINI_API OPENVDB_EXPORT
258#else
259 #define OPENVDB_HOUDINI_API OPENVDB_IMPORT
260#endif
261
262#ifdef OPENVDB_AX_DLL
263#ifdef OPENVDB_AX_API
264#undef OPENVDB_AX_API
265#endif
266#ifdef OPENVDB_AX_PRIVATE
267 #define OPENVDB_AX_API OPENVDB_EXPORT
268#else
269 #define OPENVDB_AX_API OPENVDB_IMPORT
270#endif
271#else
272#define OPENVDB_AX_API
273#endif // OPENVDB_AX_DLL
274
275#if defined(__ICC)
276
277// Use these defines to bracket a region of code that has safe static accesses.
278// Keep the region as small as possible.
279#define OPENVDB_START_THREADSAFE_STATIC_REFERENCE __pragma(warning(disable:1710))
280#define OPENVDB_FINISH_THREADSAFE_STATIC_REFERENCE __pragma(warning(default:1710))
281#define OPENVDB_START_THREADSAFE_STATIC_WRITE __pragma(warning(disable:1711))
282#define OPENVDB_FINISH_THREADSAFE_STATIC_WRITE __pragma(warning(default:1711))
283#define OPENVDB_START_THREADSAFE_STATIC_ADDRESS __pragma(warning(disable:1712))
284#define OPENVDB_FINISH_THREADSAFE_STATIC_ADDRESS __pragma(warning(default:1712))
285
286// Use these defines to bracket a region of code that has unsafe static accesses.
287// Keep the region as small as possible.
288#define OPENVDB_START_NON_THREADSAFE_STATIC_REFERENCE __pragma(warning(disable:1710))
289#define OPENVDB_FINISH_NON_THREADSAFE_STATIC_REFERENCE __pragma(warning(default:1710))
290#define OPENVDB_START_NON_THREADSAFE_STATIC_WRITE __pragma(warning(disable:1711))
291#define OPENVDB_FINISH_NON_THREADSAFE_STATIC_WRITE __pragma(warning(default:1711))
292#define OPENVDB_START_NON_THREADSAFE_STATIC_ADDRESS __pragma(warning(disable:1712))
293#define OPENVDB_FINISH_NON_THREADSAFE_STATIC_ADDRESS __pragma(warning(default:1712))
294
295// Simpler version for one-line cases
296#define OPENVDB_THREADSAFE_STATIC_REFERENCE(CODE) \
297 __pragma(warning(disable:1710)); CODE; __pragma(warning(default:1710))
298#define OPENVDB_THREADSAFE_STATIC_WRITE(CODE) \
299 __pragma(warning(disable:1711)); CODE; __pragma(warning(default:1711))
300#define OPENVDB_THREADSAFE_STATIC_ADDRESS(CODE) \
301 __pragma(warning(disable:1712)); CODE; __pragma(warning(default:1712))
302
303#else // GCC does not support these compiler warnings
304
305#define OPENVDB_START_THREADSAFE_STATIC_REFERENCE
306#define OPENVDB_FINISH_THREADSAFE_STATIC_REFERENCE
307#define OPENVDB_START_THREADSAFE_STATIC_WRITE
308#define OPENVDB_FINISH_THREADSAFE_STATIC_WRITE
309#define OPENVDB_START_THREADSAFE_STATIC_ADDRESS
310#define OPENVDB_FINISH_THREADSAFE_STATIC_ADDRESS
311
312#define OPENVDB_START_NON_THREADSAFE_STATIC_REFERENCE
313#define OPENVDB_FINISH_NON_THREADSAFE_STATIC_REFERENCE
314#define OPENVDB_START_NON_THREADSAFE_STATIC_WRITE
315#define OPENVDB_FINISH_NON_THREADSAFE_STATIC_WRITE
316#define OPENVDB_START_NON_THREADSAFE_STATIC_ADDRESS
317#define OPENVDB_FINISH_NON_THREADSAFE_STATIC_ADDRESS
318
319#define OPENVDB_THREADSAFE_STATIC_REFERENCE(CODE) CODE
320#define OPENVDB_THREADSAFE_STATIC_WRITE(CODE) CODE
321#define OPENVDB_THREADSAFE_STATIC_ADDRESS(CODE) CODE
322
323#endif // defined(__ICC)
324
325#endif // OPENVDB_PLATFORM_HAS_BEEN_INCLUDED