ua_config.h.in 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  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(__LITTLE_ENDIAN__) || defined(_WIN32)
  78. # define htole16(x) (x)
  79. # define htole32(x) (x)
  80. # define htole64(x) (x)
  81. # define le16toh(x) (x)
  82. # define le32toh(x) (x)
  83. # define le64toh(x) (x)
  84. #else
  85. # if defined(__ANDROID__)
  86. # include <endian.h>
  87. # define le16toh(x) letoh16(x)
  88. # define le32toh(x) letoh32(x)
  89. # define le64toh(x) letoh64(x)
  90. # elif defined(__linux__)
  91. # include <endian.h>
  92. # elif defined(__OpenBSD__)
  93. # include <sys/endian.h>
  94. # elif defined(__NetBSD__) || defined(__FreeBSD__) || defined(__DragonFly__)
  95. # include <sys/endian.h>
  96. # define le16toh(x) letoh16(x)
  97. # define le32toh(x) letoh32(x)
  98. # define le64toh(x) letoh64(x)
  99. # elif defined(__APPLE__)
  100. # include <libkern/OSByteOrder.h>
  101. # define htole16(x) OSSwapHostToLittleInt16(x)
  102. # define htole32(x) OSSwapHostToLittleInt32(x)
  103. # define htole64(x) OSSwapHostToLittleInt64(x)
  104. # define le16toh(x) OSSwapLittleToHostInt16(x)
  105. # define le32toh(x) OSSwapLittleToHostInt32(x)
  106. # define le64toh(x) OSSwapLittleToHostInt64(x)
  107. # elif defined(__QNX__) || defined(__QNXNTO__)
  108. # include <gulliver.h>
  109. # define htole16(x) ENDIAN_LE16(x)
  110. # define htole32(x) ENDIAN_LE32(x)
  111. # define htole64(x) ENDIAN_LE64(x)
  112. # define le16toh(x) ENDIAN_LE16(x)
  113. # define le32toh(x) ENDIAN_LE32(x)
  114. # define le64toh(x) ENDIAN_LE64(x)
  115. # else
  116. # define UA_ENCODING_INTEGER_GENERIC
  117. # warning No native function for endianness conversion available. Use a slow generic conversion.
  118. # endif
  119. #endif
  120. /**
  121. * Float Endianness
  122. * ---------------- */
  123. /* Demote error to a warning on clang. There is no robust way to detect float
  124. * endianness here. On x86/x86-64, floats are always in the right IEEE 754
  125. * format. Then, the "Unknown float representation warning" can be ignored or
  126. * disabled and the UA_ENCODING_FLOAT_GENERIC definition removed to get faster
  127. * speed. */
  128. #if defined(__clang__)
  129. #pragma GCC diagnostic push
  130. #pragma GCC diagnostic warning "-W#warnings"
  131. #endif
  132. #if !defined(_WIN32)
  133. # if !defined(__FLOAT_WORD_ORDER__) || !defined(__BYTE_ORDER__) || \
  134. !defined(__ORDER_LITTLE_ENDIAN__) || !defined(__ORDER_BIG_ENDIAN__)
  135. # define UA_ENCODING_FLOAT_GENERIC
  136. # warning Unknown float representation. Use a slow manual IEEE 754 conversion.
  137. # else
  138. # if !(((__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__) && (__FLOAT_WORD_ORDER__ == __ORDER_LITTLE_ENDIAN__)) || \
  139. ((__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__) && (__FLOAT_WORD_ORDER__ == __ORDER_BIG_ENDIAN__)))
  140. # if ((__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__) && (__FLOAT_WORD_ORDER__ == __ORDER_BIG_ENDIAN__)) || \
  141. ((__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__) && (__FLOAT_WORD_ORDER__ == __ORDER_LITTLE_ENDIAN__))
  142. # define UA_ENCODING_FLOAT_SWAP
  143. # else
  144. # define UA_ENCODING_FLOAT_GENERIC
  145. # warning Unknown float representation. Use a slow manual IEEE 754 conversion.
  146. # endif
  147. # endif
  148. # endif
  149. #endif
  150. #if defined(__clang__)
  151. #pragma GCC diagnostic pop
  152. #endif
  153. /**
  154. * Embed unavailable libc functions
  155. * -------------------------------- */
  156. #include <stddef.h>
  157. #ifdef UA_ENABLE_EMBEDDED_LIBC
  158. void *memcpy(void *UA_RESTRICT dest, const void *UA_RESTRICT src, size_t n);
  159. void *memset(void *dest, int c, size_t n);
  160. size_t strlen(const char *s);
  161. int memcmp(const void *vl, const void *vr, size_t n);
  162. #else
  163. # include <string.h>
  164. #endif
  165. #endif /* UA_CONFIG_H_ */