ua_config.h.in 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  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) || (__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(__linux__)
  53. # include <endian.h>
  54. # elif defined(__OpenBSD__)
  55. # include <sys/endian.h>
  56. # elif defined(__NetBSD__) || defined(__FreeBSD__) || defined(__DragonFly__)
  57. # include <sys/endian.h>
  58. # define le16toh(x) letoh16(x)
  59. # define le32toh(x) letoh32(x)
  60. # define le64toh(x) letoh64(x)
  61. # elif defined(__APPLE__)
  62. # include <libkern/OSByteOrder.h>
  63. # define htole16(x) OSSwapHostToLittleInt16(x)
  64. # define htole32(x) OSSwapHostToLittleInt32(x)
  65. # define htole64(x) OSSwapHostToLittleInt64(x)
  66. # define le16toh(x) OSSwapLittleToHostInt16(x)
  67. # define le32toh(x) OSSwapLittleToHostInt32(x)
  68. # define le64toh(x) OSSwapLittleToHostInt64(x)
  69. # define __BYTE_ORDER BYTE_ORDER
  70. # elif defined(__QNX__) || defined(__QNXNTO__)
  71. # include <gulliver.h>
  72. # if defined(__LITTLEENDIAN__)
  73. # define __BYTE_ORDER __LITTLE_ENDIAN
  74. # endif
  75. # define htole16(x) ENDIAN_LE16(x)
  76. # define htole32(x) ENDIAN_LE32(x)
  77. # define htole64(x) ENDIAN_LE64(x)
  78. # define le16toh(x) ENDIAN_LE16(x)
  79. # define le32toh(x) ENDIAN_LE32(x)
  80. # define le64toh(x) ENDIAN_LE64(x)
  81. # endif
  82. # if ( __BYTE_ORDER != __LITTLE_ENDIAN )
  83. # define UA_NON_LITTLEENDIAN_ARCHITECTURE
  84. # endif
  85. #endif
  86. /* Manually override */
  87. // If required, define UA_NON_LITTLEENDIAN_ARCHITECTURE, UA_MIXED_ENDIAN, and
  88. // the htole / letoh functions here. Even better, post an issue on github or the
  89. // mailing list, so we can include the architecture in the standard release.
  90. #define swap16(u16) ((u16 >> 8) | (u16 << 8))
  91. #define swap32(u32) ((u32 >> 24) | ((u32 << 8) & 0x00FF0000) | ((u32 >> 8) & 0x0000FF00) | (u32 << 24))
  92. #define swap64(u64) ((u64 >> 56) | ((u64 << 40) & 0x00FF000000000000) | ((u64 << 24) & 0x0000FF0000000000) | \
  93. ((u64 << 8) & 0x000000FF00000000) | ((u64 >> 8) & 0x00000000FF000000) | \
  94. ((u64 >> 24) & 0x0000000000FF0000) | ((u64 >> 40) & 0x000000000000FF00) | (u64 << 56))
  95. #ifdef __ARM_ARCH_4T__
  96. # define UA_MIXED_ENDIAN
  97. # define UA_NON_LITTLEENDIAN_ARCHITECTURE
  98. # define htole16(x) swap16(x)
  99. # define htole32(x) swap32(x)
  100. # define htole64(x) swap64(x)
  101. # define le16toh(x) swap16(x)
  102. # define le32toh(x) swap32(x)
  103. # define le64toh(x) swap64(x)
  104. #endif
  105. #ifndef htole16
  106. # error The endianness of the architecture not known
  107. #endif
  108. /* Inline Functions */
  109. #ifdef _MSC_VER
  110. # define UA_INLINE __inline
  111. #else
  112. # define UA_INLINE inline
  113. #endif
  114. /* Define non-aliasing pointers */
  115. #ifdef _MSC_VER
  116. # define UA_RESTRICT __restrict
  117. #elif defined(__GNUC__)
  118. # define UA_RESTRICT __restrict__
  119. #else
  120. # define UA_RESTRICT restrict
  121. #endif
  122. /* Function attributes */
  123. #ifdef __GNUC__
  124. # define UA_FUNC_ATTR_MALLOC __attribute__((malloc))
  125. # define UA_FUNC_ATTR_PURE __attribute__ ((pure))
  126. # define UA_FUNC_ATTR_CONST __attribute__((const))
  127. # define UA_FUNC_ATTR_WARN_UNUSED_RESULT __attribute__((warn_unused_result))
  128. #else
  129. # define UA_FUNC_ATTR_MALLOC
  130. # define UA_FUNC_ATTR_PURE
  131. # define UA_FUNC_ATTR_CONST
  132. # define UA_FUNC_ATTR_WARN_UNUSED_RESULT
  133. #endif
  134. #include <stddef.h>
  135. #ifdef UA_ENABLE_EMBEDDED_LIBC
  136. void *memcpy(void *UA_RESTRICT dest, const void *UA_RESTRICT src, size_t n);
  137. void *memset(void *dest, int c, size_t n);
  138. size_t strlen(const char *s);
  139. int memcmp(const void *vl, const void *vr, size_t n);
  140. #else
  141. # include <string.h>
  142. #endif
  143. #endif /* UA_CONFIG_H_ */