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 Use this sparingly. Remove references to deprecated code if at all possible. 132 /// @details Example: 133 /// @code 134 /// OPENVDB_DEPRECATED void myDeprecatedFunction() {} 135 /// 136 /// { 137 /// OPENVDB_NO_DEPRECATION_WARNING_BEGIN 138 /// myDeprecatedFunction(); 139 /// OPENVDB_NO_DEPRECATION_WARNING_END 140 /// } 141 /// @endcode 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 178 /// @brief Bracket code with OPENVDB_NO_TYPE_CONVERSION_WARNING_BEGIN/_END, 179 /// to inhibit warnings about type conversion. 180 /// @note Use this sparingly. Use static casts and explicit type conversion if at all possible. 181 /// @details Example: 182 /// @code 183 /// float value = 0.1f; 184 /// OPENVDB_NO_TYPE_CONVERSION_WARNING_BEGIN 185 /// int valueAsInt = value; 186 /// OPENVDB_NO_TYPE_CONVERSION_WARNING_END 187 /// @endcode 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 210 /// Helper macros for defining library symbol visibility 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 231 /// Helper macros for explicit template instantiation 232 #if defined(_WIN32) && defined(OPENVDB_DLL) 233 #ifdef OPENVDB_PRIVATE 234 #define OPENVDB_TEMPLATE_EXPORT OPENVDB_EXPORT 235 #define OPENVDB_TEMPLATE_IMPORT 236 #else 237 #define OPENVDB_TEMPLATE_EXPORT 238 #define OPENVDB_TEMPLATE_IMPORT OPENVDB_IMPORT 239 #endif 240 #else 241 #define OPENVDB_TEMPLATE_IMPORT 242 #define OPENVDB_TEMPLATE_EXPORT 243 #endif 244 245 /// All classes and public free standing functions must be explicitly marked 246 /// as \<lib\>_API to be exported. The \<lib\>_PRIVATE macros are defined when 247 /// building that particular library. 248 #ifdef OPENVDB_API 249 #undef OPENVDB_API 250 #endif 251 #ifdef OPENVDB_PRIVATE 252 #define OPENVDB_API OPENVDB_EXPORT 253 #else 254 #define OPENVDB_API OPENVDB_IMPORT 255 #endif 256 #ifdef OPENVDB_HOUDINI_API 257 #undef OPENVDB_HOUDINI_API 258 #endif 259 #ifdef OPENVDB_HOUDINI_PRIVATE 260 #define OPENVDB_HOUDINI_API OPENVDB_EXPORT 261 #else 262 #define OPENVDB_HOUDINI_API OPENVDB_IMPORT 263 #endif 264 265 #if defined(__ICC) 266 267 // Use these defines to bracket a region of code that has safe static accesses. 268 // Keep the region as small as possible. 269 #define OPENVDB_START_THREADSAFE_STATIC_REFERENCE __pragma(warning(disable:1710)) 270 #define OPENVDB_FINISH_THREADSAFE_STATIC_REFERENCE __pragma(warning(default:1710)) 271 #define OPENVDB_START_THREADSAFE_STATIC_WRITE __pragma(warning(disable:1711)) 272 #define OPENVDB_FINISH_THREADSAFE_STATIC_WRITE __pragma(warning(default:1711)) 273 #define OPENVDB_START_THREADSAFE_STATIC_ADDRESS __pragma(warning(disable:1712)) 274 #define OPENVDB_FINISH_THREADSAFE_STATIC_ADDRESS __pragma(warning(default:1712)) 275 276 // Use these defines to bracket a region of code that has unsafe static accesses. 277 // Keep the region as small as possible. 278 #define OPENVDB_START_NON_THREADSAFE_STATIC_REFERENCE __pragma(warning(disable:1710)) 279 #define OPENVDB_FINISH_NON_THREADSAFE_STATIC_REFERENCE __pragma(warning(default:1710)) 280 #define OPENVDB_START_NON_THREADSAFE_STATIC_WRITE __pragma(warning(disable:1711)) 281 #define OPENVDB_FINISH_NON_THREADSAFE_STATIC_WRITE __pragma(warning(default:1711)) 282 #define OPENVDB_START_NON_THREADSAFE_STATIC_ADDRESS __pragma(warning(disable:1712)) 283 #define OPENVDB_FINISH_NON_THREADSAFE_STATIC_ADDRESS __pragma(warning(default:1712)) 284 285 // Simpler version for one-line cases 286 #define OPENVDB_THREADSAFE_STATIC_REFERENCE(CODE) \ 287 __pragma(warning(disable:1710)); CODE; __pragma(warning(default:1710)) 288 #define OPENVDB_THREADSAFE_STATIC_WRITE(CODE) \ 289 __pragma(warning(disable:1711)); CODE; __pragma(warning(default:1711)) 290 #define OPENVDB_THREADSAFE_STATIC_ADDRESS(CODE) \ 291 __pragma(warning(disable:1712)); CODE; __pragma(warning(default:1712)) 292 293 #else // GCC does not support these compiler warnings 294 295 #define OPENVDB_START_THREADSAFE_STATIC_REFERENCE 296 #define OPENVDB_FINISH_THREADSAFE_STATIC_REFERENCE 297 #define OPENVDB_START_THREADSAFE_STATIC_WRITE 298 #define OPENVDB_FINISH_THREADSAFE_STATIC_WRITE 299 #define OPENVDB_START_THREADSAFE_STATIC_ADDRESS 300 #define OPENVDB_FINISH_THREADSAFE_STATIC_ADDRESS 301 302 #define OPENVDB_START_NON_THREADSAFE_STATIC_REFERENCE 303 #define OPENVDB_FINISH_NON_THREADSAFE_STATIC_REFERENCE 304 #define OPENVDB_START_NON_THREADSAFE_STATIC_WRITE 305 #define OPENVDB_FINISH_NON_THREADSAFE_STATIC_WRITE 306 #define OPENVDB_START_NON_THREADSAFE_STATIC_ADDRESS 307 #define OPENVDB_FINISH_NON_THREADSAFE_STATIC_ADDRESS 308 309 #define OPENVDB_THREADSAFE_STATIC_REFERENCE(CODE) CODE 310 #define OPENVDB_THREADSAFE_STATIC_WRITE(CODE) CODE 311 #define OPENVDB_THREADSAFE_STATIC_ADDRESS(CODE) CODE 312 313 #endif // defined(__ICC) 314 315 #endif // OPENVDB_PLATFORM_HAS_BEEN_INCLUDED 316