ua_config.h.in 5.6 KB

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