ua_config.h.in 4.2 KB

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