ua_config.h.in 6.4 KB

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