ua_config.h.in 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  1. /* This Source Code Form is subject to the terms of the Mozilla Public
  2. * License, v. 2.0. If a copy of the MPL was not distributed with this
  3. * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  4. #ifndef UA_CONFIG_H_
  5. #define UA_CONFIG_H_
  6. #ifdef __cplusplus
  7. extern "C" {
  8. #endif
  9. /**
  10. * open62541 Version
  11. * ----------------- */
  12. #define UA_OPEN62541_VER_MAJOR ${OPEN62541_VER_MAJOR}
  13. #define UA_OPEN62541_VER_MINOR ${OPEN62541_VER_MINOR}
  14. #define UA_OPEN62541_VER_PATCH ${OPEN62541_VER_PATCH}
  15. #define UA_OPEN62541_VER_LABEL "${OPEN62541_VER_LABEL}" /* Release candidate label, etc. */
  16. #define UA_OPEN62541_VER_COMMIT "${OPEN62541_VER_COMMIT}"
  17. /**
  18. * Feature Options
  19. * ---------------
  20. * Changing the feature options has no effect on a pre-compiled library. */
  21. #define UA_LOGLEVEL ${UA_LOGLEVEL}
  22. #cmakedefine UA_ENABLE_METHODCALLS
  23. #cmakedefine UA_ENABLE_NODEMANAGEMENT
  24. #cmakedefine UA_ENABLE_SUBSCRIPTIONS
  25. #cmakedefine UA_ENABLE_MULTITHREADING
  26. /* Advanced Options */
  27. #cmakedefine UA_ENABLE_STATUSCODE_DESCRIPTIONS
  28. #cmakedefine UA_ENABLE_TYPENAMES
  29. #cmakedefine UA_ENABLE_EMBEDDED_LIBC
  30. #cmakedefine UA_ENABLE_DETERMINISTIC_RNG
  31. #cmakedefine UA_ENABLE_GENERATE_NAMESPACE0
  32. #cmakedefine UA_ENABLE_NONSTANDARD_UDP
  33. #cmakedefine UA_ENABLE_DISCOVERY
  34. #cmakedefine UA_ENABLE_DISCOVERY_MULTICAST
  35. #cmakedefine UA_ENABLE_DISCOVERY_SEMAPHORE
  36. #cmakedefine UA_DEBUG_DUMP_PKGS
  37. /**
  38. * Assertions
  39. * ---------- */
  40. #include <assert.h>
  41. #define UA_assert(ignore) assert(ignore)
  42. /* Outputs an error message at compile time if the assert fails.
  43. * Example usage:
  44. * UA_STATIC_ASSERT(sizeof(long)==7, use_another_compiler_luke)
  45. * See: https://stackoverflow.com/a/4815532/869402 */
  46. #if defined(__cplusplus) && __cplusplus >= 201103L /* C++11 or above */
  47. # define UA_STATIC_ASSERT(cond,msg) static_assert(cond, #msg)
  48. #elif defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L /* C11 or above */
  49. # define UA_STATIC_ASSERT(cond,msg) _Static_assert(cond, #msg)
  50. #elif defined(__GNUC__) || defined(__clang__) || defined(_MSC_VER) /* GCC, Clang, MSC */
  51. # define UA_CTASTR2(pre,post) pre ## post
  52. # define UA_CTASTR(pre,post) UA_CTASTR2(pre,post)
  53. # define UA_STATIC_ASSERT(cond,msg) \
  54. typedef struct { \
  55. int UA_CTASTR(static_assertion_failed_,msg) : !!(cond); \
  56. } UA_CTASTR(static_assertion_failed_,__COUNTER__)
  57. #else /* Everybody else */
  58. # define UA_STATIC_ASSERT(cond,msg) typedef char static_assertion_##msg[(cond)?1:-1]
  59. #endif
  60. /**
  61. * Memory Management
  62. * -----------------
  63. * The default is to use the malloc implementation from ``stdlib.h``. Override
  64. * if required. Changing the settings has no effect on a pre-compiled
  65. * library. */
  66. #include <stdlib.h>
  67. #if defined(_WIN32) && !defined(__clang__)
  68. # include <malloc.h>
  69. #endif
  70. #define UA_free(ptr) free(ptr)
  71. #define UA_malloc(size) malloc(size)
  72. #define UA_calloc(num, size) calloc(num, size)
  73. #define UA_realloc(ptr, size) realloc(ptr, size)
  74. #if defined(__GNUC__) || defined(__clang__)
  75. # define UA_alloca(size) __builtin_alloca (size)
  76. #elif defined(_WIN32)
  77. # define UA_alloca(SIZE) _alloca(SIZE)
  78. #else
  79. # include <alloca.h>
  80. # define UA_alloca(SIZE) alloca(SIZE)
  81. #endif
  82. /**
  83. * Function Export
  84. * ---------------
  85. * On Win32: Define ``UA_DYNAMIC_LINKING`` and ``UA_DYNAMIC_LINKING_EXPORT`` in
  86. * order to export symbols for a DLL. Define ``UA_DYNAMIC_LINKING`` only to
  87. * import symbols from a DLL.*/
  88. #cmakedefine UA_DYNAMIC_LINKING
  89. #if defined(_WIN32) && defined(UA_DYNAMIC_LINKING)
  90. # ifdef UA_DYNAMIC_LINKING_EXPORT /* export dll */
  91. # ifdef __GNUC__
  92. # define UA_EXPORT __attribute__ ((dllexport))
  93. # else
  94. # define UA_EXPORT __declspec(dllexport)
  95. # endif
  96. # else /* import dll */
  97. # ifdef __GNUC__
  98. # define UA_EXPORT __attribute__ ((dllimport))
  99. # else
  100. # define UA_EXPORT __declspec(dllimport)
  101. # endif
  102. # endif
  103. #else /* non win32 */
  104. # if __GNUC__ || __clang__
  105. # define UA_EXPORT __attribute__ ((visibility ("default")))
  106. # endif
  107. #endif
  108. #ifndef UA_EXPORT
  109. # define UA_EXPORT /* fallback to default */
  110. #endif
  111. /**
  112. * Inline Functions
  113. * ---------------- */
  114. #ifdef _MSC_VER
  115. # define UA_INLINE __inline
  116. #else
  117. # define UA_INLINE inline
  118. #endif
  119. /**
  120. * Non-aliasing pointers
  121. * -------------------- */
  122. #ifdef _MSC_VER
  123. # define UA_RESTRICT __restrict
  124. #elif defined(__GNUC__)
  125. # define UA_RESTRICT __restrict__
  126. #else
  127. # define UA_RESTRICT restrict
  128. #endif
  129. /**
  130. * Function attributes
  131. * ------------------- */
  132. #if defined(__GNUC__) || defined(__clang__)
  133. # define UA_FUNC_ATTR_MALLOC __attribute__((malloc))
  134. # define UA_FUNC_ATTR_PURE __attribute__ ((pure))
  135. # define UA_FUNC_ATTR_CONST __attribute__((const))
  136. # define UA_FUNC_ATTR_WARN_UNUSED_RESULT __attribute__((warn_unused_result))
  137. # define UA_FORMAT(X,Y) __attribute__ ((format (printf, X, Y)))
  138. #else
  139. # define UA_FUNC_ATTR_MALLOC
  140. # define UA_FUNC_ATTR_PURE
  141. # define UA_FUNC_ATTR_CONST
  142. # define UA_FUNC_ATTR_WARN_UNUSED_RESULT
  143. # define UA_FORMAT(X,Y)
  144. #endif
  145. #if defined(__GNUC__) || defined(__clang__)
  146. # define UA_DEPRECATED __attribute__((deprecated))
  147. #elif defined(_MSC_VER)
  148. # define UA_DEPRECATED __declspec(deprecated)
  149. #else
  150. # define UA_DEPRECATED
  151. #endif
  152. /**
  153. * Basic Libc Definitions
  154. * ------------------------
  155. * The header ``string.h`` is defined in the C-standard. If no libc is provided
  156. * (e.g. on some embedded target), use the following definitions and the
  157. * implementation in ``/deps/libc_string.c`` */
  158. #ifndef UA_ENABLE_EMBEDDED_LIBC
  159. # include <string.h>
  160. #else
  161. void *memcpy(void *UA_RESTRICT dest, const void *UA_RESTRICT src, size_t n);
  162. void *memset(void *dest, int c, size_t n);
  163. size_t strlen(const char *s);
  164. int memcmp(const void *vl, const void *vr, size_t n);
  165. #endif
  166. /**
  167. * Detect Binary Overlaying for Encoding
  168. * -------------------------------------
  169. * Integers and floating point numbers are transmitted in little-endian (IEEE 754
  170. * for floating point) encoding. If the target architecture uses the same
  171. * format, numeral datatypes can be memcpy'd (overlayed) on the binary stream.
  172. * This speeds up encoding.
  173. *
  174. * Integer Endianness
  175. * ^^^^^^^^^^^^^^^^^^
  176. * The definition ``UA_BINARY_OVERLAYABLE_INTEGER`` is true when the integer
  177. * representation of the target architecture is little-endian. */
  178. #if defined(_WIN32) || (defined(__BYTE_ORDER__) && defined(__ORDER_LITTLE_ENDIAN__) && \
  179. (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__))
  180. # define UA_BINARY_OVERLAYABLE_INTEGER 1
  181. #elif defined(__ANDROID__) /* Andoid */
  182. # include <endian.h>
  183. # if __BYTE_ORDER == __LITTLE_ENDIAN
  184. # define UA_BINARY_OVERLAYABLE_INTEGER 1
  185. # endif
  186. #elif defined(__linux__) /* Linux */
  187. # include <endian.h>
  188. # if __BYTE_ORDER == __LITTLE_ENDIAN
  189. # define UA_BINARY_OVERLAYABLE_INTEGER 1
  190. # endif
  191. # if __FLOAT_BYTE_ORDER == __LITTLE_ENDIAN
  192. # define UA_BINARY_OVERLAYABLE_FLOAT 1
  193. # endif
  194. #elif defined(__OpenBSD__) /* OpenBSD */
  195. # include <sys/endian.h>
  196. # if BYTE_ORDER == LITTLE_ENDIAN
  197. # define UA_BINARY_OVERLAYABLE_INTEGER 1
  198. # endif
  199. #elif defined(__NetBSD__) || defined(__FreeBSD__) || defined(__DragonFly__) /* Other BSD */
  200. # include <sys/endian.h>
  201. # if _BYTE_ORDER == _LITTLE_ENDIAN
  202. # define UA_BINARY_OVERLAYABLE_INTEGER 1
  203. # endif
  204. #elif defined(__APPLE__) /* Apple (MacOS, iOS) */
  205. # include <libkern/OSByteOrder.h>
  206. # if defined(__LITTLE_ENDIAN__)
  207. # define UA_BINARY_OVERLAYABLE_INTEGER 1
  208. # endif
  209. #elif defined(__QNX__) || defined(__QNXNTO__) /* QNX */
  210. # include <gulliver.h>
  211. # if defined(__LITTLEENDIAN__)
  212. # define UA_BINARY_OVERLAYABLE_INTEGER 1
  213. # endif
  214. #endif
  215. #ifndef UA_BINARY_OVERLAYABLE_INTEGER
  216. # define UA_BINARY_OVERLAYABLE_INTEGER 0
  217. #endif
  218. /**
  219. * Float Endianness
  220. * ^^^^^^^^^^^^^^^^
  221. * The definition ``UA_BINARY_OVERLAYABLE_FLOAT`` is true when the floating
  222. * point number representation of the target architecture is IEEE 754. Note that
  223. * this cannot be reliable detected with macros for the clang compiler
  224. * (beginning of 2017). Just override if necessary. */
  225. #if defined(_WIN32)
  226. # define UA_BINARY_OVERLAYABLE_FLOAT 1
  227. #elif defined(__FLOAT_WORD_ORDER__) && defined(__ORDER_LITTLE_ENDIAN__) && \
  228. (__FLOAT_WORD_ORDER__ == __ORDER_LITTLE_ENDIAN__) /* Defined only in GCC */
  229. # define UA_BINARY_OVERLAYABLE_FLOAT 1
  230. #elif defined(__FLOAT_WORD_ORDER) && defined(__LITTLE_ENDIAN) && \
  231. (__FLOAT_WORD_ORDER == __LITTLE_ENDIAN) /* Defined only in GCC */
  232. # define UA_BINARY_OVERLAYABLE_FLOAT 1
  233. #elif defined(_WRS_KERNEL)
  234. # define UA_BINARY_OVERLAYABLE_FLOAT 1
  235. #endif
  236. #ifndef UA_BINARY_OVERLAYABLE_FLOAT
  237. # define UA_BINARY_OVERLAYABLE_FLOAT 0
  238. #endif
  239. #ifdef __cplusplus
  240. } // extern "C"
  241. #endif
  242. #endif /* UA_CONFIG_H_ */