ua_config.h.in 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. #ifndef UA_CONFIG_H_
  2. #define UA_CONFIG_H_
  3. #ifndef _XOPEN_SOURCE
  4. # define _XOPEN_SOURCE 500
  5. # define _BSD_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. /* Function Export */
  19. #ifdef _WIN32
  20. # ifdef UA_DYNAMIC_LINKING
  21. # ifdef __GNUC__
  22. # define UA_EXPORT __attribute__ ((dllexport))
  23. # else
  24. # define UA_EXPORT __declspec(dllexport)
  25. # endif
  26. # else
  27. # ifdef __GNUC__
  28. # define UA_EXPORT __attribute__ ((dllexport))
  29. # else
  30. # define UA_EXPORT __declspec(dllimport)
  31. # endif
  32. # endif
  33. #else
  34. # if __GNUC__ || __clang__
  35. # define UA_EXPORT __attribute__ ((visibility ("default")))
  36. # else
  37. # define UA_EXPORT
  38. # endif
  39. #endif
  40. /* Endianness */
  41. // UA_NON_LITTLEENDIAN_ARCHITECTURE disables memcpying integer arrays directly
  42. // onto the message buffer. UA_MIXED_ENDIAN enables special encoding for floats
  43. // and doubles. Otherwise, they are endianness-switched similar to integers.
  44. #if defined(__LITTLE_ENDIAN__) || defined(_WIN32) || (!defined(__ANDROID__) && BYTE_ORDER == ORDER_LITTLE_ENDIAN)
  45. # define htole16(x) (x)
  46. # define htole32(x) (x)
  47. # define htole64(x) (x)
  48. # define le16toh(x) (x)
  49. # define le32toh(x) (x)
  50. # define le64toh(x) (x)
  51. #else
  52. # if defined(__ANDROID__)
  53. # include <endian.h>
  54. # define le16toh(x) letoh16(x)
  55. # define le32toh(x) letoh32(x)
  56. # define le64toh(x) letoh64(x)
  57. # elif defined(__linux__)
  58. # include <endian.h>
  59. # elif defined(__OpenBSD__)
  60. # include <sys/endian.h>
  61. # elif defined(__NetBSD__) || defined(__FreeBSD__) || defined(__DragonFly__)
  62. # include <sys/endian.h>
  63. # define le16toh(x) letoh16(x)
  64. # define le32toh(x) letoh32(x)
  65. # define le64toh(x) letoh64(x)
  66. # elif defined(__APPLE__)
  67. # include <libkern/OSByteOrder.h>
  68. # define htole16(x) OSSwapHostToLittleInt16(x)
  69. # define htole32(x) OSSwapHostToLittleInt32(x)
  70. # define htole64(x) OSSwapHostToLittleInt64(x)
  71. # define le16toh(x) OSSwapLittleToHostInt16(x)
  72. # define le32toh(x) OSSwapLittleToHostInt32(x)
  73. # define le64toh(x) OSSwapLittleToHostInt64(x)
  74. # define __BYTE_ORDER BYTE_ORDER
  75. # elif defined(__QNX__) || defined(__QNXNTO__)
  76. # include <gulliver.h>
  77. # if defined(__LITTLEENDIAN__)
  78. # define __BYTE_ORDER __LITTLE_ENDIAN
  79. # endif
  80. # define htole16(x) ENDIAN_LE16(x)
  81. # define htole32(x) ENDIAN_LE32(x)
  82. # define htole64(x) ENDIAN_LE64(x)
  83. # define le16toh(x) ENDIAN_LE16(x)
  84. # define le32toh(x) ENDIAN_LE32(x)
  85. # define le64toh(x) ENDIAN_LE64(x)
  86. # endif
  87. # if ( __BYTE_ORDER != __LITTLE_ENDIAN ) && (_BYTE_ORDER != _LITTLE_ENDIAN)
  88. # define UA_NON_LITTLEENDIAN_ARCHITECTURE
  89. # endif
  90. #endif
  91. /* Manually override */
  92. // If required, define UA_NON_LITTLEENDIAN_ARCHITECTURE, UA_MIXED_ENDIAN, and
  93. // the htole / letoh functions here. Even better, post an issue on github or the
  94. // mailing list, so we can include the architecture in the standard release.
  95. #define swap16(u16) ((u16 >> 8) | (u16 << 8))
  96. #define swap32(u32) ((u32 >> 24) | ((u32 << 8) & 0x00FF0000) | ((u32 >> 8) & 0x0000FF00) | (u32 << 24))
  97. #define swap64(u64) ((u64 >> 56) | ((u64 << 40) & 0x00FF000000000000) | ((u64 << 24) & 0x0000FF0000000000) | \
  98. ((u64 << 8) & 0x000000FF00000000) | ((u64 >> 8) & 0x00000000FF000000) | \
  99. ((u64 >> 24) & 0x0000000000FF0000) | ((u64 >> 40) & 0x000000000000FF00) | (u64 << 56))
  100. #ifdef __ARM_ARCH_4T__
  101. # define UA_MIXED_ENDIAN
  102. # define UA_NON_LITTLEENDIAN_ARCHITECTURE
  103. # define htole16(x) swap16(x)
  104. # define htole32(x) swap32(x)
  105. # define htole64(x) swap64(x)
  106. # define le16toh(x) swap16(x)
  107. # define le32toh(x) swap32(x)
  108. # define le64toh(x) swap64(x)
  109. #endif
  110. #ifndef htole16
  111. # error The endianness of the architecture not known
  112. #endif
  113. /* Inline Functions */
  114. #ifdef _MSC_VER
  115. # define UA_INLINE __inline
  116. #else
  117. # define UA_INLINE inline
  118. #endif
  119. /* Define non-aliasing pointers */
  120. #ifdef _MSC_VER
  121. # define UA_RESTRICT __restrict
  122. #elif defined(__GNUC__)
  123. # define UA_RESTRICT __restrict__
  124. #else
  125. # define UA_RESTRICT restrict
  126. #endif
  127. /* Function attributes */
  128. #ifdef __GNUC__
  129. # define UA_FUNC_ATTR_MALLOC __attribute__((malloc))
  130. # define UA_FUNC_ATTR_PURE __attribute__ ((pure))
  131. # define UA_FUNC_ATTR_CONST __attribute__((const))
  132. # define UA_FUNC_ATTR_WARN_UNUSED_RESULT __attribute__((warn_unused_result))
  133. #else
  134. # define UA_FUNC_ATTR_MALLOC
  135. # define UA_FUNC_ATTR_PURE
  136. # define UA_FUNC_ATTR_CONST
  137. # define UA_FUNC_ATTR_WARN_UNUSED_RESULT
  138. #endif
  139. #include <stddef.h>
  140. #ifdef UA_ENABLE_EMBEDDED_LIBC
  141. void *memcpy(void *UA_RESTRICT dest, const void *UA_RESTRICT src, size_t n);
  142. void *memset(void *dest, int c, size_t n);
  143. size_t strlen(const char *s);
  144. int memcmp(const void *vl, const void *vr, size_t n);
  145. #else
  146. # include <string.h>
  147. #endif
  148. #endif /* UA_CONFIG_H_ */