ua_config.h.in 6.0 KB

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