ua_config.h.in 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. #ifndef UA_CONFIG_H_
  2. #define UA_CONFIG_H_
  3. #ifndef _XOPEN_SOURCE
  4. # define _XOPEN_SOURCE 500
  5. # define _DEFAULT_SOURCE
  6. #endif
  7. #define UA_LOGLEVEL ${UA_LOGLEVEL}
  8. #cmakedefine UA_ENABLE_MULTITHREADING
  9. #cmakedefine UA_ENABLE_METHODCALLS
  10. #cmakedefine UA_ENABLE_SUBSCRIPTIONS
  11. #cmakedefine UA_ENABLE_TYPENAMES
  12. #cmakedefine UA_ENABLE_EMBEDDED_LIBC
  13. #cmakedefine UA_ENABLE_GENERATE_NAMESPACE0
  14. #cmakedefine UA_ENABLE_EXTERNAL_NAMESPACES
  15. #cmakedefine UA_ENABLE_NODEMANAGEMENT
  16. #cmakedefine UA_ENABLE_NONSTANDARD_UDP
  17. #cmakedefine UA_ENABLE_NONSTANDARD_STATELESS
  18. /**
  19. * Function Export
  20. * --------------- */
  21. #ifdef _WIN32
  22. # ifdef UA_DYNAMIC_LINKING
  23. # ifdef __GNUC__
  24. # define UA_EXPORT __attribute__ ((dllexport))
  25. # else
  26. # define UA_EXPORT __declspec(dllexport)
  27. # endif
  28. # else
  29. # ifdef __GNUC__
  30. # define UA_EXPORT __attribute__ ((dllexport))
  31. # else
  32. # define UA_EXPORT __declspec(dllimport)
  33. # endif
  34. # endif
  35. #else
  36. # if __GNUC__ || __clang__
  37. # define UA_EXPORT __attribute__ ((visibility ("default")))
  38. # else
  39. # define UA_EXPORT
  40. # endif
  41. #endif
  42. /**
  43. * Inline Functions
  44. * ---------------- */
  45. #ifdef _MSC_VER
  46. # define UA_INLINE __inline
  47. #else
  48. # define UA_INLINE inline
  49. #endif
  50. /**
  51. * Non-aliasing pointers
  52. * -------------------- */
  53. #ifdef _MSC_VER
  54. # define UA_RESTRICT __restrict
  55. #elif defined(__GNUC__)
  56. # define UA_RESTRICT __restrict__
  57. #else
  58. # define UA_RESTRICT restrict
  59. #endif
  60. /**
  61. * Function attributes
  62. * ------------------- */
  63. #ifdef __GNUC__
  64. # define UA_FUNC_ATTR_MALLOC __attribute__((malloc))
  65. # define UA_FUNC_ATTR_PURE __attribute__ ((pure))
  66. # define UA_FUNC_ATTR_CONST __attribute__((const))
  67. # define UA_FUNC_ATTR_WARN_UNUSED_RESULT __attribute__((warn_unused_result))
  68. #else
  69. # define UA_FUNC_ATTR_MALLOC
  70. # define UA_FUNC_ATTR_PURE
  71. # define UA_FUNC_ATTR_CONST
  72. # define UA_FUNC_ATTR_WARN_UNUSED_RESULT
  73. #endif
  74. /**
  75. * Integer Endianness
  76. * ------------------ */
  77. #if defined(_WIN32) || (defined(__BYTE_ORDER__) && defined(__ORDER_LITTLE_ENDIAN__) && \
  78. (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__)) /* little endian detected */
  79. # define UA_BINARY_OVERLAYABLE_INTEGER true
  80. #elif defined(__ANDROID__) /* Andoid */
  81. # include <endian.h>
  82. # if __BYTE_ORDER == __LITTLE_ENDIAN
  83. # define UA_BINARY_OVERLAYABLE_INTEGER true
  84. # endif
  85. #elif defined(__linux__) /* Linux */
  86. # include <endian.h>
  87. # if __BYTE_ORDER == __LITTLE_ENDIAN
  88. # define UA_BINARY_OVERLAYABLE_INTEGER true
  89. # endif
  90. # if __FLOAT_BYTE_ORDER == __LITTLE_ENDIAN
  91. # define UA_BINARY_OVERLAYABLE_FLOAT true
  92. # endif
  93. #elif defined(__OpenBSD__) /* OpenBSD */
  94. # include <sys/endian.h>
  95. # if BYTE_ORDER == LITTLE_ENDIAN
  96. # define UA_BINARY_OVERLAYABLE_INTEGER true
  97. # endif
  98. #elif defined(__NetBSD__) || defined(__FreeBSD__) || defined(__DragonFly__) /* Other BSD */
  99. # include <sys/endian.h>
  100. # if _BYTE_ORDER == _LITTLE_ENDIAN
  101. # define UA_BINARY_OVERLAYABLE_INTEGER true
  102. # endif
  103. #elif defined(__APPLE__) /* Apple (MacOS, iOS) */
  104. # include <libkern/OSByteOrder.h>
  105. # if defined(__LITTLE_ENDIAN__)
  106. # define UA_BINARY_OVERLAYABLE_INTEGER true
  107. # endif
  108. #elif defined(__QNX__) || defined(__QNXNTO__) /* QNX */
  109. # include <gulliver.h>
  110. # if defined(__LITTLEENDIAN__)
  111. # define UA_BINARY_OVERLAYABLE_INTEGER true
  112. # endif
  113. #endif
  114. /**
  115. * Float Endianness
  116. * ---------------- */
  117. #if defined(_WIN32)
  118. # define UA_BINARY_OVERLAYABLE_FLOAT true
  119. #elif defined(__FLOAT_WORD_ORDER__) && defined(__ORDER_LITTLE_ENDIAN__) && \
  120. (__FLOAT_WORD_ORDER__ == __ORDER_LITTLE_ENDIAN__) /* Defined only in GCC */
  121. # define UA_BINARY_OVERLAYABLE_FLOAT true
  122. #endif
  123. /**
  124. * Binary Encoding Overlays
  125. * ------------------------
  126. * Some data types have the same layout in memory as on the binary data stream.
  127. * This can be used to speed up the decoding. If we could not detect
  128. * little-endianness of integers and floats, this is not possible for types that
  129. * contain integers or floats respectively. See the definition of the
  130. * overlayable flag defined in `UA_DataType`. */
  131. /* Demote error to a warning on clang. There is no robust way to detect float
  132. * endianness here. On x86/x86-64, floats are always in the right IEEE 754
  133. * format. So floats are overlayable is the architecture is little-endian. */
  134. #if defined(__clang__)
  135. # pragma GCC diagnostic push
  136. # pragma GCC diagnostic warning "-W#warnings"
  137. #endif
  138. #ifndef UA_BINARY_OVERLAYABLE_INTEGER
  139. # define UA_BINARY_OVERLAYABLE_INTEGER false
  140. # warning Slow Integer Encoding
  141. #endif
  142. #ifndef UA_BINARY_OVERLAYABLE_FLOAT
  143. # define UA_BINARY_OVERLAYABLE_FLOAT false
  144. # warning Slow Float Encoding
  145. #endif
  146. #if defined(__clang__)
  147. # pragma GCC diagnostic pop
  148. #endif
  149. /**
  150. * Embed unavailable libc functions
  151. * -------------------------------- */
  152. #include <stddef.h>
  153. #ifdef UA_ENABLE_EMBEDDED_LIBC
  154. void *memcpy(void *UA_RESTRICT dest, const void *UA_RESTRICT src, size_t n);
  155. void *memset(void *dest, int c, size_t n);
  156. size_t strlen(const char *s);
  157. int memcmp(const void *vl, const void *vr, size_t n);
  158. #else
  159. # include <string.h>
  160. #endif
  161. #endif /* UA_CONFIG_H_ */