ua_config.h.in 6.4 KB

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