GTLRDefines.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. /* Copyright (c) 2011 Google Inc.
  2. *
  3. * Licensed under the Apache License, Version 2.0 (the "License");
  4. * you may not use this file except in compliance with the License.
  5. * You may obtain a copy of the License at
  6. *
  7. * http://www.apache.org/licenses/LICENSE-2.0
  8. *
  9. * Unless required by applicable law or agreed to in writing, software
  10. * distributed under the License is distributed on an "AS IS" BASIS,
  11. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. * See the License for the specific language governing permissions and
  13. * limitations under the License.
  14. */
  15. //
  16. // GTLRDefines.h
  17. //
  18. // Ensure Apple's conditionals we depend on are defined.
  19. #import <TargetConditionals.h>
  20. #import <AvailabilityMacros.h>
  21. // These can be redefined via a prefix if you are prefixing symbols to prefix
  22. // the names used in strings. Something like:
  23. // #define _HELPER(x) "MyPrefix" #x
  24. // #define GTLR_CLASSNAME_STR(x) @_HELPER(x)
  25. // #define GTLR_CLASSNAME_CSTR(x) _HELPER(x)
  26. #ifndef GTLR_CLASSNAME_STR
  27. #define _GTLR_CLASSNAME_HELPER(x) #x
  28. #define GTLR_CLASSNAME_STR(x) @_GTLR_CLASSNAME_HELPER(x)
  29. #define GTLR_CLASSNAME_CSTR(x) _GTLR_CLASSNAME_HELPER(x)
  30. #endif
  31. // Provide a common definition for externing constants/functions
  32. #if defined(__cplusplus)
  33. #define GTLR_EXTERN extern "C"
  34. #else
  35. #define GTLR_EXTERN extern
  36. #endif
  37. //
  38. // GTLR_ASSERT defaults to bridging to NSAssert. This macro exists just in case
  39. // it needs to be remapped.
  40. // GTLR_DEBUG_ASSERT is similar, but compiles in only for debug builds
  41. //
  42. #ifndef GTLR_ASSERT
  43. // NSCAssert to avoid capturing self if used in a block.
  44. #define GTLR_ASSERT(condition, ...) NSCAssert(condition, __VA_ARGS__)
  45. #endif // GTLR_ASSERT
  46. #ifndef GTLR_DEBUG_ASSERT
  47. #if DEBUG && !defined(NS_BLOCK_ASSERTIONS)
  48. #define GTLR_DEBUG_ASSERT(condition, ...) GTLR_ASSERT(condition, __VA_ARGS__)
  49. #elif DEBUG
  50. // In DEBUG builds with assertions blocked, log to avoid unused variable warnings.
  51. #define GTLR_DEBUG_ASSERT(condition, ...) if (!(condition)) { NSLog(__VA_ARGS__); }
  52. #else
  53. #define GTLR_DEBUG_ASSERT(condition, ...) do { } while (0)
  54. #endif
  55. #endif
  56. #ifndef GTLR_DEBUG_LOG
  57. #if DEBUG
  58. #define GTLR_DEBUG_LOG(...) NSLog(__VA_ARGS__)
  59. #else
  60. #define GTLR_DEBUG_LOG(...) do { } while (0)
  61. #endif
  62. #endif
  63. #ifndef GTLR_DEBUG_ASSERT_CURRENT_QUEUE
  64. #define GTLR_ASSERT_CURRENT_QUEUE_DEBUG(targetQueue) \
  65. GTLR_DEBUG_ASSERT(0 == strcmp(GTLR_QUEUE_NAME(targetQueue), \
  66. GTLR_QUEUE_NAME(DISPATCH_CURRENT_QUEUE_LABEL)), \
  67. @"Current queue is %s (expected %s)", \
  68. GTLR_QUEUE_NAME(DISPATCH_CURRENT_QUEUE_LABEL), \
  69. GTLR_QUEUE_NAME(targetQueue))
  70. #define GTLR_QUEUE_NAME(queue) \
  71. (strlen(dispatch_queue_get_label(queue)) > 0 ? dispatch_queue_get_label(queue) : "unnamed")
  72. #endif // GTLR_ASSERT_CURRENT_QUEUE_DEBUG
  73. // Sanity check the min versions.
  74. #if (defined(TARGET_OS_TV) && TARGET_OS_TV) || (defined(TARGET_OS_WATCH) && TARGET_OS_WATCH)
  75. // No min checks for these two.
  76. #elif TARGET_OS_IPHONE
  77. #if !defined(__IPHONE_9_0) || (__IPHONE_OS_VERSION_MAX_ALLOWED < __IPHONE_9_0)
  78. #error "This project expects to be compiled with the iOS 9.0 SDK (or later)."
  79. #endif
  80. #if __IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_7_0
  81. #error "The minimum supported iOS version is 7.0."
  82. #endif
  83. #elif TARGET_OS_MAC
  84. #if !defined(MAC_OS_X_VERSION_10_10) || (MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_10)
  85. #error "This project expects to be compiled with the OS X 10.10 SDK (or later)."
  86. #endif
  87. #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_9
  88. #error "The minimum supported OS X version is 10.9."
  89. #endif
  90. #else
  91. #error "Unknown target platform."
  92. #endif
  93. // Version marker used to validate the generated sources against the library
  94. // version. The will be changed any time the library makes a change that means
  95. // past sources need to be regenerated.
  96. #define GTLR_RUNTIME_VERSION 3000