OpenVDB 9.1.0
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 // 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 ///Disable the non-portable Windows definitions of min() and max() macros
64 #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
81/// Bracket code with OPENVDB_NO_UNREACHABLE_CODE_WARNING_BEGIN/_END,
82/// as in the following example, to inhibit ICC remarks about unreachable code:
83/// @code
84/// template<typename NodeType>
85/// void processNode(NodeType& node)
86/// {
87/// OPENVDB_NO_UNREACHABLE_CODE_WARNING_BEGIN
88/// if (NodeType::LEVEL == 0) return; // ignore leaf nodes
89/// int i = 0;
90/// ...
91/// OPENVDB_NO_UNREACHABLE_CODE_WARNING_END
92/// }
93/// @endcode
94/// In the above, <tt>NodeType::LEVEL == 0</tt> is a compile-time constant expression,
95/// so for some template instantiations, the line below it is unreachable.
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
119/// Deprecation macros. Define OPENVDB_NO_DEPRECATION_WARNINGS to disable all
120/// deprecation warnings in OpenVDB.
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
129/// @brief Bracket code with OPENVDB_NO_DEPRECATION_WARNING_BEGIN/_END,
130/// to inhibit warnings about deprecated code.
131/// @note Only intended to be used internally whilst parent code is being
132/// deprecated
133/// @details Example:
134/// @code
135/// OPENVDB_DEPRECATED void myDeprecatedFunction() {}
136///
137/// {
138/// OPENVDB_NO_DEPRECATION_WARNING_BEGIN
139/// myDeprecatedFunction();
140/// OPENVDB_NO_DEPRECATION_WARNING_END
141/// }
142/// @endcode
143#if defined __INTEL_COMPILER
144 #define OPENVDB_NO_DEPRECATION_WARNING_BEGIN \
145 _Pragma("warning (push)") \
146 _Pragma("warning (disable:1478)")
147 #define OPENVDB_NO_DEPRECATION_WARNING_END \
148 _Pragma("warning (pop)")
149#elif defined __clang__
150 #define OPENVDB_NO_DEPRECATION_WARNING_BEGIN \
151 _Pragma("clang diagnostic push") \
152 _Pragma("clang diagnostic ignored \"-Wdeprecated-declarations\"")
153 // note: no #pragma message, since Clang treats them as warnings
154 #define OPENVDB_NO_DEPRECATION_WARNING_END \
155 _Pragma("clang diagnostic pop")
156#elif defined __GNUC__
157 #define OPENVDB_NO_DEPRECATION_WARNING_BEGIN \
158 _Pragma("GCC diagnostic push") \
159 _Pragma("GCC diagnostic ignored \"-Wdeprecated-declarations\"")
160 #define OPENVDB_NO_DEPRECATION_WARNING_END \
161 _Pragma("GCC diagnostic pop")
162#elif defined _MSC_VER
163 #define OPENVDB_NO_DEPRECATION_WARNING_BEGIN \
164 __pragma(warning(push)) \
165 __pragma(warning(disable : 4996))
166 #define OPENVDB_NO_DEPRECATION_WARNING_END \
167 __pragma(warning(pop))
168#else
169 #define OPENVDB_NO_DEPRECATION_WARNING_BEGIN
170 #define OPENVDB_NO_DEPRECATION_WARNING_END
171#endif
172
173
174/// @brief Bracket code with OPENVDB_NO_TYPE_CONVERSION_WARNING_BEGIN/_END,
175/// to inhibit warnings about type conversion.
176/// @note Use this sparingly. Use static casts and explicit type conversion if at all possible.
177/// @details Example:
178/// @code
179/// float value = 0.1f;
180/// OPENVDB_NO_TYPE_CONVERSION_WARNING_BEGIN
181/// int valueAsInt = value;
182/// OPENVDB_NO_TYPE_CONVERSION_WARNING_END
183/// @endcode
184#if defined __INTEL_COMPILER
185 #define OPENVDB_NO_TYPE_CONVERSION_WARNING_BEGIN
186 #define OPENVDB_NO_TYPE_CONVERSION_WARNING_END
187#elif defined __GNUC__
188 // -Wfloat-conversion was only introduced in GCC 4.9
189 #if OPENVDB_CHECK_GCC(4, 9)
190 #define OPENVDB_NO_TYPE_CONVERSION_WARNING_BEGIN \
191 _Pragma("GCC diagnostic push") \
192 _Pragma("GCC diagnostic ignored \"-Wconversion\"") \
193 _Pragma("GCC diagnostic ignored \"-Wfloat-conversion\"")
194 #else
195 #define OPENVDB_NO_TYPE_CONVERSION_WARNING_BEGIN \
196 _Pragma("GCC diagnostic push") \
197 _Pragma("GCC diagnostic ignored \"-Wconversion\"")
198 #endif
199 #define OPENVDB_NO_TYPE_CONVERSION_WARNING_END \
200 _Pragma("GCC diagnostic pop")
201#else
202 #define OPENVDB_NO_TYPE_CONVERSION_WARNING_BEGIN
203 #define OPENVDB_NO_TYPE_CONVERSION_WARNING_END
204#endif
205
206/// Helper macros for defining library symbol visibility
207#ifdef OPENVDB_EXPORT
208#undef OPENVDB_EXPORT
209#endif
210#ifdef OPENVDB_IMPORT
211#undef OPENVDB_IMPORT
212#endif
213#ifdef _WIN32
214 #ifdef OPENVDB_DLL
215 #define OPENVDB_EXPORT __declspec(dllexport)
216 #define OPENVDB_IMPORT __declspec(dllimport)
217 #else
218 #define OPENVDB_EXPORT
219 #define OPENVDB_IMPORT
220 #endif
221#elif defined(__GNUC__)
222 #define OPENVDB_EXPORT __attribute__((visibility("default")))
223 #define OPENVDB_IMPORT __attribute__((visibility("default")))
224#endif
225
226/// Helper macros for explicit template instantiation
227#if defined(_WIN32) && defined(OPENVDB_DLL)
228 #ifdef OPENVDB_PRIVATE
229 #define OPENVDB_TEMPLATE_EXPORT OPENVDB_EXPORT
230 #define OPENVDB_TEMPLATE_IMPORT
231 #else
232 #define OPENVDB_TEMPLATE_EXPORT
233 #define OPENVDB_TEMPLATE_IMPORT OPENVDB_IMPORT
234 #endif
235#else
236 #define OPENVDB_TEMPLATE_IMPORT
237 #define OPENVDB_TEMPLATE_EXPORT
238#endif
239
240/// All classes and public free standing functions must be explicitly marked
241/// as <lib>_API to be exported. The <lib>_PRIVATE macros are defined when
242/// building that particular library.
243#ifdef OPENVDB_API
244#undef OPENVDB_API
245#endif
246#ifdef OPENVDB_PRIVATE
247 #define OPENVDB_API OPENVDB_EXPORT
248#else
249 #define OPENVDB_API OPENVDB_IMPORT
250#endif
251#ifdef OPENVDB_HOUDINI_API
252#undef OPENVDB_HOUDINI_API
253#endif
254#ifdef OPENVDB_HOUDINI_PRIVATE
255 #define OPENVDB_HOUDINI_API OPENVDB_EXPORT
256#else
257 #define OPENVDB_HOUDINI_API OPENVDB_IMPORT
258#endif
259
260#ifdef OPENVDB_AX_DLL
261#ifdef OPENVDB_AX_API
262#undef OPENVDB_AX_API
263#endif
264#ifdef OPENVDB_AX_PRIVATE
265 #define OPENVDB_AX_API OPENVDB_EXPORT
266#else
267 #define OPENVDB_AX_API OPENVDB_IMPORT
268#endif
269#else
270#define OPENVDB_AX_API
271#endif // OPENVDB_AX_DLL
272
273#if defined(__ICC)
274
275// Use these defines to bracket a region of code that has safe static accesses.
276// Keep the region as small as possible.
277#define OPENVDB_START_THREADSAFE_STATIC_REFERENCE __pragma(warning(disable:1710))
278#define OPENVDB_FINISH_THREADSAFE_STATIC_REFERENCE __pragma(warning(default:1710))
279#define OPENVDB_START_THREADSAFE_STATIC_WRITE __pragma(warning(disable:1711))
280#define OPENVDB_FINISH_THREADSAFE_STATIC_WRITE __pragma(warning(default:1711))
281#define OPENVDB_START_THREADSAFE_STATIC_ADDRESS __pragma(warning(disable:1712))
282#define OPENVDB_FINISH_THREADSAFE_STATIC_ADDRESS __pragma(warning(default:1712))
283
284// Use these defines to bracket a region of code that has unsafe static accesses.
285// Keep the region as small as possible.
286#define OPENVDB_START_NON_THREADSAFE_STATIC_REFERENCE __pragma(warning(disable:1710))
287#define OPENVDB_FINISH_NON_THREADSAFE_STATIC_REFERENCE __pragma(warning(default:1710))
288#define OPENVDB_START_NON_THREADSAFE_STATIC_WRITE __pragma(warning(disable:1711))
289#define OPENVDB_FINISH_NON_THREADSAFE_STATIC_WRITE __pragma(warning(default:1711))
290#define OPENVDB_START_NON_THREADSAFE_STATIC_ADDRESS __pragma(warning(disable:1712))
291#define OPENVDB_FINISH_NON_THREADSAFE_STATIC_ADDRESS __pragma(warning(default:1712))
292
293// Simpler version for one-line cases
294#define OPENVDB_THREADSAFE_STATIC_REFERENCE(CODE) \
295 __pragma(warning(disable:1710)); CODE; __pragma(warning(default:1710))
296#define OPENVDB_THREADSAFE_STATIC_WRITE(CODE) \
297 __pragma(warning(disable:1711)); CODE; __pragma(warning(default:1711))
298#define OPENVDB_THREADSAFE_STATIC_ADDRESS(CODE) \
299 __pragma(warning(disable:1712)); CODE; __pragma(warning(default:1712))
300
301#else // GCC does not support these compiler warnings
302
303#define OPENVDB_START_THREADSAFE_STATIC_REFERENCE
304#define OPENVDB_FINISH_THREADSAFE_STATIC_REFERENCE
305#define OPENVDB_START_THREADSAFE_STATIC_WRITE
306#define OPENVDB_FINISH_THREADSAFE_STATIC_WRITE
307#define OPENVDB_START_THREADSAFE_STATIC_ADDRESS
308#define OPENVDB_FINISH_THREADSAFE_STATIC_ADDRESS
309
310#define OPENVDB_START_NON_THREADSAFE_STATIC_REFERENCE
311#define OPENVDB_FINISH_NON_THREADSAFE_STATIC_REFERENCE
312#define OPENVDB_START_NON_THREADSAFE_STATIC_WRITE
313#define OPENVDB_FINISH_NON_THREADSAFE_STATIC_WRITE
314#define OPENVDB_START_NON_THREADSAFE_STATIC_ADDRESS
315#define OPENVDB_FINISH_NON_THREADSAFE_STATIC_ADDRESS
316
317#define OPENVDB_THREADSAFE_STATIC_REFERENCE(CODE) CODE
318#define OPENVDB_THREADSAFE_STATIC_WRITE(CODE) CODE
319#define OPENVDB_THREADSAFE_STATIC_ADDRESS(CODE) CODE
320
321#endif // defined(__ICC)
322
323#endif // OPENVDB_PLATFORM_HAS_BEEN_INCLUDED