ua_config.h.in 5.3 KB

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