ua_config.h.in 6.1 KB

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