ua_config.h.in 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. /*
  2. * Copyright (C) 2013-2015 the contributors as stated in the AUTHORS file
  3. *
  4. * This file is part of open62541. open62541 is free software: you can
  5. * redistribute it and/or modify it under the terms of the GNU Lesser General
  6. * Public License, version 3 (as published by the Free Software Foundation) with
  7. * a static linking exception as stated in the LICENSE file provided with
  8. * open62541.
  9. *
  10. * open62541 is distributed in the hope that it will be useful, but WITHOUT ANY
  11. * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  12. * A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
  13. * details.
  14. */
  15. #ifndef UA_CONFIG_H_
  16. #define UA_CONFIG_H_
  17. #ifdef __cplusplus
  18. extern "C" {
  19. #endif
  20. #ifndef _XOPEN_SOURCE
  21. # define _XOPEN_SOURCE 500
  22. #endif
  23. #ifndef _DEFAULT_SOURCE
  24. # define _DEFAULT_SOURCE
  25. #endif
  26. #define UA_LOGLEVEL ${UA_LOGLEVEL}
  27. #cmakedefine UA_ENABLE_MULTITHREADING
  28. #cmakedefine UA_ENABLE_METHODCALLS
  29. #cmakedefine UA_ENABLE_SUBSCRIPTIONS
  30. #cmakedefine UA_ENABLE_TYPENAMES
  31. #cmakedefine UA_ENABLE_EMBEDDED_LIBC
  32. #cmakedefine UA_ENABLE_GENERATE_NAMESPACE0
  33. #cmakedefine UA_ENABLE_EXTERNAL_NAMESPACES
  34. #cmakedefine UA_ENABLE_NODEMANAGEMENT
  35. #cmakedefine UA_ENABLE_NONSTANDARD_UDP
  36. #cmakedefine UA_ENABLE_NONSTANDARD_STATELESS
  37. /**
  38. * Function Export
  39. * --------------- */
  40. #ifdef _WIN32
  41. # ifdef UA_DYNAMIC_LINKING
  42. # ifdef __GNUC__
  43. # define UA_EXPORT __attribute__ ((dllexport))
  44. # else
  45. # define UA_EXPORT __declspec(dllexport)
  46. # endif
  47. # else
  48. # ifdef __GNUC__
  49. # define UA_EXPORT __attribute__ ((dllexport))
  50. # else
  51. # define UA_EXPORT __declspec(dllimport)
  52. # endif
  53. # endif
  54. #else
  55. # if __GNUC__ || __clang__
  56. # define UA_EXPORT __attribute__ ((visibility ("default")))
  57. # else
  58. # define UA_EXPORT
  59. # endif
  60. #endif
  61. /**
  62. * Inline Functions
  63. * ---------------- */
  64. #ifdef _MSC_VER
  65. # define UA_INLINE __inline
  66. #else
  67. # define UA_INLINE inline
  68. #endif
  69. /**
  70. * Non-aliasing pointers
  71. * -------------------- */
  72. #ifdef _MSC_VER
  73. # define UA_RESTRICT __restrict
  74. #elif defined(__GNUC__)
  75. # define UA_RESTRICT __restrict__
  76. #else
  77. # define UA_RESTRICT restrict
  78. #endif
  79. /**
  80. * Function attributes
  81. * ------------------- */
  82. #ifdef __GNUC__
  83. # define UA_FUNC_ATTR_MALLOC __attribute__((malloc))
  84. # define UA_FUNC_ATTR_PURE __attribute__ ((pure))
  85. # define UA_FUNC_ATTR_CONST __attribute__((const))
  86. # define UA_FUNC_ATTR_WARN_UNUSED_RESULT __attribute__((warn_unused_result))
  87. #else
  88. # define UA_FUNC_ATTR_MALLOC
  89. # define UA_FUNC_ATTR_PURE
  90. # define UA_FUNC_ATTR_CONST
  91. # define UA_FUNC_ATTR_WARN_UNUSED_RESULT
  92. #endif
  93. /**
  94. * Integer Endianness
  95. * ------------------ */
  96. #if defined(_WIN32) || (defined(__BYTE_ORDER__) && defined(__ORDER_LITTLE_ENDIAN__) && \
  97. (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__)) /* little endian detected */
  98. # define UA_BINARY_OVERLAYABLE_INTEGER true
  99. #elif defined(__ANDROID__) /* Andoid */
  100. # include <endian.h>
  101. # if __BYTE_ORDER == __LITTLE_ENDIAN
  102. # define UA_BINARY_OVERLAYABLE_INTEGER true
  103. # endif
  104. #elif defined(__linux__) /* Linux */
  105. # include <endian.h>
  106. # if __BYTE_ORDER == __LITTLE_ENDIAN
  107. # define UA_BINARY_OVERLAYABLE_INTEGER true
  108. # endif
  109. # if __FLOAT_BYTE_ORDER == __LITTLE_ENDIAN
  110. # define UA_BINARY_OVERLAYABLE_FLOAT true
  111. # endif
  112. #elif defined(__OpenBSD__) /* OpenBSD */
  113. # include <sys/endian.h>
  114. # if BYTE_ORDER == LITTLE_ENDIAN
  115. # define UA_BINARY_OVERLAYABLE_INTEGER true
  116. # endif
  117. #elif defined(__NetBSD__) || defined(__FreeBSD__) || defined(__DragonFly__) /* Other BSD */
  118. # include <sys/endian.h>
  119. # if _BYTE_ORDER == _LITTLE_ENDIAN
  120. # define UA_BINARY_OVERLAYABLE_INTEGER true
  121. # endif
  122. #elif defined(__APPLE__) /* Apple (MacOS, iOS) */
  123. # include <libkern/OSByteOrder.h>
  124. # if defined(__LITTLE_ENDIAN__)
  125. # define UA_BINARY_OVERLAYABLE_INTEGER true
  126. # endif
  127. #elif defined(__QNX__) || defined(__QNXNTO__) /* QNX */
  128. # include <gulliver.h>
  129. # if defined(__LITTLEENDIAN__)
  130. # define UA_BINARY_OVERLAYABLE_INTEGER true
  131. # endif
  132. #endif
  133. /**
  134. * Float Endianness
  135. * ---------------- */
  136. #if defined(_WIN32)
  137. # define UA_BINARY_OVERLAYABLE_FLOAT true
  138. #elif defined(__FLOAT_WORD_ORDER__) && defined(__ORDER_LITTLE_ENDIAN__) && \
  139. (__FLOAT_WORD_ORDER__ == __ORDER_LITTLE_ENDIAN__) /* Defined only in GCC */
  140. # define UA_BINARY_OVERLAYABLE_FLOAT true
  141. #endif
  142. /**
  143. * Binary Encoding Overlays
  144. * ------------------------
  145. * Some data types have the same layout in memory as on the binary data stream.
  146. * This can be used to speed up the decoding. If we could not detect
  147. * little-endianness of integers and floats, this is not possible for types that
  148. * contain integers or floats respectively. See the definition of the
  149. * overlayable flag defined in `UA_DataType`. */
  150. /* Demote error to a warning on clang. There is no robust way to detect float
  151. * endianness here. On x86/x86-64, floats are always in the right IEEE 754
  152. * format. So floats are overlayable is the architecture is little-endian. */
  153. #if defined(__clang__)
  154. # pragma GCC diagnostic push
  155. # pragma GCC diagnostic warning "-W#warnings"
  156. #endif
  157. #ifndef UA_BINARY_OVERLAYABLE_INTEGER
  158. # define UA_BINARY_OVERLAYABLE_INTEGER false
  159. # warning Slow Integer Encoding
  160. #endif
  161. #ifndef UA_BINARY_OVERLAYABLE_FLOAT
  162. # define UA_BINARY_OVERLAYABLE_FLOAT false
  163. # warning Slow Float Encoding
  164. #endif
  165. #if defined(__clang__)
  166. # pragma GCC diagnostic pop
  167. #endif
  168. /**
  169. * Embed unavailable libc functions
  170. * -------------------------------- */
  171. #include <stddef.h>
  172. #ifdef UA_ENABLE_EMBEDDED_LIBC
  173. void *memcpy(void *UA_RESTRICT dest, const void *UA_RESTRICT src, size_t n);
  174. void *memset(void *dest, int c, size_t n);
  175. size_t strlen(const char *s);
  176. int memcmp(const void *vl, const void *vr, size_t n);
  177. #else
  178. # include <string.h>
  179. #endif
  180. #ifdef __cplusplus
  181. } // extern "C"
  182. #endif
  183. #endif /* UA_CONFIG_H_ */