HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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 #include "PlatformConfig.h"
10 
11 #define PRAGMA(x) _Pragma(#x)
12 
13 /// @name Utilities
14 /// @{
15 /// @cond OPENVDB_VERSION_INTERNAL
16 #define OPENVDB_PREPROC_STRINGIFY_(x) #x
17 /// @endcond
18 /// @brief Return @a x as a string literal. If @a x is a macro,
19 /// return its value as a string literal.
20 /// @hideinitializer
21 #define OPENVDB_PREPROC_STRINGIFY(x) OPENVDB_PREPROC_STRINGIFY_(x)
22 
23 /// @cond OPENVDB_VERSION_INTERNAL
24 #define OPENVDB_PREPROC_CONCAT_(x, y) x ## y
25 /// @endcond
26 /// @brief Form a new token by concatenating two existing tokens.
27 /// If either token is a macro, concatenate its value.
28 /// @hideinitializer
29 #define OPENVDB_PREPROC_CONCAT(x, y) OPENVDB_PREPROC_CONCAT_(x, y)
30 /// @}
31 
32 
33 /// Use OPENVDB_DEPRECATED to mark functions as deprecated.
34 /// It should be placed right before the signature of the function,
35 /// e.g., "OPENVDB_DEPRECATED void functionName();".
36 #ifdef OPENVDB_DEPRECATED
37 #undef OPENVDB_DEPRECATED
38 #endif
39 #ifdef _MSC_VER
40  #define OPENVDB_DEPRECATED __declspec(deprecated)
41 #else
42  #define OPENVDB_DEPRECATED __attribute__ ((deprecated))
43 #endif
44 
45 /// Macro for determining if GCC version is >= than X.Y
46 #if defined(__GNUC__)
47  #define OPENVDB_CHECK_GCC(MAJOR, MINOR) \
48  (__GNUC__ > MAJOR || (__GNUC__ == MAJOR && __GNUC_MINOR__ >= MINOR))
49 #else
50  #define OPENVDB_CHECK_GCC(MAJOR, MINOR) 0
51 #endif
52 
53 /// OpenVDB now requires C++11
54 #define OPENVDB_HAS_CXX11 1
55 
56 /// For compilers that need templated function specializations to have
57 /// storage qualifiers, we need to declare the specializations as static inline.
58 /// Otherwise, we'll get linker errors about multiply defined symbols.
59 #if defined(__GNUC__) && OPENVDB_CHECK_GCC(4, 4)
60  #define OPENVDB_STATIC_SPECIALIZATION
61 #else
62  #define OPENVDB_STATIC_SPECIALIZATION static
63 #endif
64 
65 
66 /// SIMD Intrinsic Headers
67 #if defined(OPENVDB_USE_SSE42) || defined(OPENVDB_USE_AVX)
68  #if defined(_WIN32)
69  #include <intrin.h>
70  #elif defined(__GNUC__)
71  #if defined(__x86_64__) || defined(__i386__)
72  #include <x86intrin.h>
73  #elif defined(__ARM_NEON__)
74  #include <arm_neon.h>
75  #endif
76  #endif
77 #endif
78 
79 
80 /// Bracket code with OPENVDB_NO_UNREACHABLE_CODE_WARNING_BEGIN/_END,
81 /// as in the following example, to inhibit ICC remarks about unreachable code:
82 /// @code
83 /// template<typename NodeType>
84 /// void processNode(NodeType& node)
85 /// {
86 /// OPENVDB_NO_UNREACHABLE_CODE_WARNING_BEGIN
87 /// if (NodeType::LEVEL == 0) return; // ignore leaf nodes
88 /// int i = 0;
89 /// ...
90 /// OPENVDB_NO_UNREACHABLE_CODE_WARNING_END
91 /// }
92 /// @endcode
93 /// In the above, <tt>NodeType::LEVEL == 0</tt> is a compile-time constant expression,
94 /// so for some template instantiations, the line below it is unreachable.
95 #if defined(__INTEL_COMPILER)
96  // Disable ICC remarks 111 ("statement is unreachable"), 128 ("loop is not reachable"),
97  // 185 ("dynamic initialization in unreachable code"), and 280 ("selector expression
98  // is constant").
99  #define OPENVDB_NO_UNREACHABLE_CODE_WARNING_BEGIN \
100  _Pragma("warning (push)") \
101  _Pragma("warning (disable:111)") \
102  _Pragma("warning (disable:128)") \
103  _Pragma("warning (disable:185)") \
104  _Pragma("warning (disable:280)")
105  #define OPENVDB_NO_UNREACHABLE_CODE_WARNING_END \
106  _Pragma("warning (pop)")
107 #elif defined(__clang__)
108  #define OPENVDB_NO_UNREACHABLE_CODE_WARNING_BEGIN \
109  PRAGMA(clang diagnostic push) \
110  PRAGMA(clang diagnostic ignored "-Wunreachable-code")
111  #define OPENVDB_NO_UNREACHABLE_CODE_WARNING_END \
112  PRAGMA(clang diagnostic pop)
113 #else
114  #define OPENVDB_NO_UNREACHABLE_CODE_WARNING_BEGIN
115  #define OPENVDB_NO_UNREACHABLE_CODE_WARNING_END
116 #endif
117 
118 
119 /// @brief Bracket code with OPENVDB_NO_DEPRECATION_WARNING_BEGIN/_END,
120 /// to inhibit warnings about deprecated code.
121 /// @note Use this sparingly. Remove references to deprecated code if at all possible.
122 /// @details Example:
123 /// @code
124 /// OPENVDB_DEPRECATED void myDeprecatedFunction() {}
125 ///
126 /// {
127 /// OPENVDB_NO_DEPRECATION_WARNING_BEGIN
128 /// myDeprecatedFunction();
129 /// OPENVDB_NO_DEPRECATION_WARNING_END
130 /// }
131 /// @endcode
132 #if defined __INTEL_COMPILER
133  #define OPENVDB_NO_DEPRECATION_WARNING_BEGIN \
134  _Pragma("warning (push)") \
135  _Pragma("warning (disable:1478)") \
136  PRAGMA(message("NOTE: ignoring deprecation warning at " __FILE__ \
137  ":" OPENVDB_PREPROC_STRINGIFY(__LINE__)))
138  #define OPENVDB_NO_DEPRECATION_WARNING_END \
139  _Pragma("warning (pop)")
140 #elif defined __clang__
141  #define OPENVDB_NO_DEPRECATION_WARNING_BEGIN \
142  _Pragma("clang diagnostic push") \
143  _Pragma("clang diagnostic ignored \"-Wdeprecated-declarations\"")
144  // note: no #pragma message, since Clang treats them as warnings
145  #define OPENVDB_NO_DEPRECATION_WARNING_END \
146  _Pragma("clang diagnostic pop")
147 #elif defined __GNUC__
148  #define OPENVDB_NO_DEPRECATION_WARNING_BEGIN \
149  _Pragma("GCC diagnostic push") \
150  _Pragma("GCC diagnostic ignored \"-Wdeprecated-declarations\"") \
151  _Pragma("message(\"NOTE: ignoring deprecation warning\")")
152  #define OPENVDB_NO_DEPRECATION_WARNING_END \
153  _Pragma("GCC diagnostic pop")
154 #elif defined _MSC_VER
155  #define OPENVDB_NO_DEPRECATION_WARNING_BEGIN \
156  __pragma(warning(push)) \
157  __pragma(warning(disable : 4996)) \
158  __pragma(message("NOTE: ignoring deprecation warning at " __FILE__ \
159  ":" OPENVDB_PREPROC_STRINGIFY(__LINE__)))
160  #define OPENVDB_NO_DEPRECATION_WARNING_END \
161  __pragma(warning(pop))
162 #else
163  #define OPENVDB_NO_DEPRECATION_WARNING_BEGIN
164  #define OPENVDB_NO_DEPRECATION_WARNING_END
165 #endif
166 
167 
168 /// @brief Bracket code with OPENVDB_NO_TYPE_CONVERSION_WARNING_BEGIN/_END,
169 /// to inhibit warnings about type conversion.
170 /// @note Use this sparingly. Use static casts and explicit type conversion if at all possible.
171 /// @details Example:
172 /// @code
173 /// float value = 0.1f;
174 /// OPENVDB_NO_TYPE_CONVERSION_WARNING_BEGIN
175 /// int valueAsInt = value;
176 /// OPENVDB_NO_TYPE_CONVERSION_WARNING_END
177 /// @endcode
178 #if defined __INTEL_COMPILER
179  #define OPENVDB_NO_TYPE_CONVERSION_WARNING_BEGIN
180  #define OPENVDB_NO_TYPE_CONVERSION_WARNING_END
181 #elif defined __GNUC__
182  // -Wfloat-conversion was only introduced in GCC 4.9
183  #if OPENVDB_CHECK_GCC(4, 9)
184  #define OPENVDB_NO_TYPE_CONVERSION_WARNING_BEGIN \
185  _Pragma("GCC diagnostic push") \
186  _Pragma("GCC diagnostic ignored \"-Wconversion\"") \
187  _Pragma("GCC diagnostic ignored \"-Wfloat-conversion\"")
188  #else
189  #define OPENVDB_NO_TYPE_CONVERSION_WARNING_BEGIN \
190  _Pragma("GCC diagnostic push") \
191  _Pragma("GCC diagnostic ignored \"-Wconversion\"")
192  #endif
193  #define OPENVDB_NO_TYPE_CONVERSION_WARNING_END \
194  _Pragma("GCC diagnostic pop")
195 #else
196  #define OPENVDB_NO_TYPE_CONVERSION_WARNING_BEGIN
197  #define OPENVDB_NO_TYPE_CONVERSION_WARNING_END
198 #endif
199 
200 /// Helper macros for defining library symbol visibility
201 #ifdef OPENVDB_EXPORT
202 #undef OPENVDB_EXPORT
203 #endif
204 #ifdef OPENVDB_IMPORT
205 #undef OPENVDB_IMPORT
206 #endif
207 #ifdef __GNUC__
208  #define OPENVDB_EXPORT __attribute__((visibility("default")))
209  #define OPENVDB_IMPORT __attribute__((visibility("default")))
210 #endif
211 #ifdef _WIN32
212  #ifdef OPENVDB_DLL
213  #define OPENVDB_EXPORT __declspec(dllexport)
214  #define OPENVDB_IMPORT __declspec(dllimport)
215  #else
216  #define OPENVDB_EXPORT
217  #define OPENVDB_IMPORT
218  #endif
219 #endif
220 
221 /// All classes and public free standing functions must be explicitly marked
222 /// as <lib>_API to be exported. The <lib>_PRIVATE macros are defined when
223 /// building that particular library.
224 #ifdef OPENVDB_API
225 #undef OPENVDB_API
226 #endif
227 #ifdef OPENVDB_PRIVATE
228  #define OPENVDB_API OPENVDB_EXPORT
229 #else
230  #define OPENVDB_API OPENVDB_IMPORT
231 #endif
232 #ifdef OPENVDB_HOUDINI_API
233 #undef OPENVDB_HOUDINI_API
234 #endif
235 #ifdef OPENVDB_HOUDINI_PRIVATE
236  #define OPENVDB_HOUDINI_API OPENVDB_EXPORT
237 #else
238  #define OPENVDB_HOUDINI_API OPENVDB_IMPORT
239 #endif
240 
241 #endif // OPENVDB_PLATFORM_HAS_BEEN_INCLUDED