ua_config.h.in 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312
  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. * Library 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. * Options
  19. * ------- */
  20. #define UA_LOGLEVEL ${UA_LOGLEVEL}
  21. #cmakedefine UA_ENABLE_METHODCALLS
  22. #cmakedefine UA_ENABLE_NODEMANAGEMENT
  23. #cmakedefine UA_ENABLE_SUBSCRIPTIONS
  24. #cmakedefine UA_ENABLE_MULTITHREADING
  25. /**
  26. * Advanced Options
  27. * ---------------- */
  28. #cmakedefine UA_ENABLE_STATUSCODE_DESCRIPTIONS
  29. #cmakedefine UA_ENABLE_TYPENAMES
  30. #cmakedefine UA_ENABLE_EMBEDDED_LIBC
  31. #cmakedefine UA_ENABLE_DETERMINISTIC_RNG
  32. #cmakedefine UA_ENABLE_GENERATE_NAMESPACE0
  33. #cmakedefine UA_ENABLE_NONSTANDARD_UDP
  34. #cmakedefine UA_ENABLE_DISCOVERY
  35. #cmakedefine UA_ENABLE_DISCOVERY_MULTICAST
  36. #cmakedefine UA_ENABLE_DISCOVERY_SEMAPHORE
  37. #cmakedefine UA_DEBUG_DUMP_PKGS
  38. /**
  39. * Standard Includes
  40. * ----------------- */
  41. #ifndef _XOPEN_SOURCE
  42. # define _XOPEN_SOURCE 600
  43. #endif
  44. #ifndef _DEFAULT_SOURCE
  45. # define _DEFAULT_SOURCE
  46. #endif
  47. // On older systems we need to define _BSD_SOURCE
  48. // _DEFAULT_SOURCE is an alias for that
  49. #ifndef _BSD_SOURCE
  50. # define _BSD_SOURCE
  51. #endif
  52. // Disable deprecation warnings for sprintf, strncpy, strerror
  53. #if defined(_MSC_VER) && !defined(_CRT_SECURE_NO_WARNINGS)
  54. # define _CRT_SECURE_NO_WARNINGS
  55. #endif
  56. #include <stddef.h>
  57. /* Include stdint.h and stdbool.h or workaround for older Visual Studios */
  58. #if !defined(_MSC_VER) || _MSC_VER >= 1600
  59. # include <stdint.h>
  60. # include <stdbool.h> /* C99 Boolean */
  61. #else
  62. # include "ms_stdint.h"
  63. #if !(defined(__bool_true_false_are_defined))
  64. #define bool short
  65. #define true 1
  66. #define false 0
  67. #define __bool_true_false_are_defined
  68. #endif
  69. #endif
  70. /**
  71. * Standard Macros
  72. * --------------- */
  73. /* Assert */
  74. #include <assert.h>
  75. #define UA_assert(ignore) assert(ignore)
  76. /**
  77. * Memory Management
  78. * ---------------
  79. * The default malloc implementation from ``stdlib.h`` is used internally.
  80. * Override if required. */
  81. #include <stdlib.h>
  82. #if defined(_WIN32) && !defined(__clang__)
  83. # include <malloc.h>
  84. #endif
  85. #define UA_free(ptr) free(ptr)
  86. #define UA_malloc(size) malloc(size)
  87. #define UA_calloc(num, size) calloc(num, size)
  88. #define UA_realloc(ptr, size) realloc(ptr, size)
  89. #if defined(__GNUC__) || defined(__clang__)
  90. # define UA_alloca(size) __builtin_alloca (size)
  91. #elif defined(_WIN32)
  92. # define UA_alloca(SIZE) _alloca(SIZE)
  93. #else
  94. # include <alloca.h>
  95. # define UA_alloca(SIZE) alloca(SIZE)
  96. #endif
  97. /**
  98. * Function Export
  99. * ---------------
  100. * On Win32: Define ``UA_DYNAMIC_LINKING`` and ``UA_DYNAMIC_LINKING_EXPORT`` in
  101. * order to export symbols for a DLL. Define ``UA_DYNAMIC_LINKING`` only to
  102. * import symbols from a DLL.*/
  103. #cmakedefine UA_DYNAMIC_LINKING
  104. #if defined(_WIN32) && defined(UA_DYNAMIC_LINKING)
  105. # ifdef UA_DYNAMIC_LINKING_EXPORT /* export dll */
  106. # ifdef __GNUC__
  107. # define UA_EXPORT __attribute__ ((dllexport))
  108. # else
  109. # define UA_EXPORT __declspec(dllexport)
  110. # endif
  111. # else /* import dll */
  112. # ifdef __GNUC__
  113. # define UA_EXPORT __attribute__ ((dllimport))
  114. # else
  115. # define UA_EXPORT __declspec(dllimport)
  116. # endif
  117. # endif
  118. #else /* non win32 */
  119. # if __GNUC__ || __clang__
  120. # define UA_EXPORT __attribute__ ((visibility ("default")))
  121. # endif
  122. #endif
  123. #ifndef UA_EXPORT
  124. # define UA_EXPORT /* fallback to default */
  125. #endif
  126. /**
  127. * Inline Functions
  128. * ---------------- */
  129. #ifdef _MSC_VER
  130. # define UA_INLINE __inline
  131. #else
  132. # define UA_INLINE inline
  133. #endif
  134. /**
  135. * Non-aliasing pointers
  136. * -------------------- */
  137. #ifdef _MSC_VER
  138. # define UA_RESTRICT __restrict
  139. #elif defined(__GNUC__)
  140. # define UA_RESTRICT __restrict__
  141. #else
  142. # define UA_RESTRICT restrict
  143. #endif
  144. /**
  145. * Function attributes
  146. * ------------------- */
  147. #ifdef __GNUC__
  148. # define UA_FUNC_ATTR_MALLOC __attribute__((malloc))
  149. # define UA_FUNC_ATTR_PURE __attribute__ ((pure))
  150. # define UA_FUNC_ATTR_CONST __attribute__((const))
  151. # define UA_FUNC_ATTR_WARN_UNUSED_RESULT __attribute__((warn_unused_result))
  152. # define UA_FORMAT(X,Y) __attribute__ ((format (printf, X, Y)))
  153. #else
  154. # define UA_FUNC_ATTR_MALLOC
  155. # define UA_FUNC_ATTR_PURE
  156. # define UA_FUNC_ATTR_CONST
  157. # define UA_FUNC_ATTR_WARN_UNUSED_RESULT
  158. # define UA_FORMAT(X,Y)
  159. #endif
  160. #ifdef __GNUC__
  161. # define UA_DEPRECATED __attribute__((deprecated))
  162. #elif defined(_MSC_VER)
  163. # define UA_DEPRECATED __declspec(deprecated)
  164. #else
  165. # define UA_DEPRECATED
  166. #endif
  167. /**
  168. * String Manipulation
  169. * -------------------
  170. * The header ``string.h`` is defined in the C-standard. If no libc is provided
  171. * (e.g. on some embedded target), use the following definitions and the
  172. * implementation in ``/deps/libc_string.c`` */
  173. #ifndef UA_ENABLE_EMBEDDED_LIBC
  174. # include <string.h>
  175. #else
  176. void *memcpy(void *UA_RESTRICT dest, const void *UA_RESTRICT src, size_t n);
  177. void *memset(void *dest, int c, size_t n);
  178. size_t strlen(const char *s);
  179. int memcmp(const void *vl, const void *vr, size_t n);
  180. #endif
  181. /**
  182. * Binary Encoding Overlays
  183. * ------------------------
  184. * Integers and floating point numbers are transmitted in little-endian (IEEE 754
  185. * for floating point) encoding. If the target architecture uses the same
  186. * format, numeral datatypes can be memcpy'd (overlayed) on the binary stream.
  187. * This speeds up encoding.
  188. *
  189. * Integer Endianness
  190. * ^^^^^^^^^^^^^^^^^^
  191. * The definition ``UA_BINARY_OVERLAYABLE_INTEGER`` is true when the integer
  192. * representation of the target architecture is little-endian. */
  193. #if defined(_WIN32) || (defined(__BYTE_ORDER__) && defined(__ORDER_LITTLE_ENDIAN__) && \
  194. (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__))
  195. # define UA_BINARY_OVERLAYABLE_INTEGER 1
  196. #elif defined(__ANDROID__) /* Andoid */
  197. # include <endian.h>
  198. # if __BYTE_ORDER == __LITTLE_ENDIAN
  199. # define UA_BINARY_OVERLAYABLE_INTEGER 1
  200. # endif
  201. #elif defined(__linux__) /* Linux */
  202. # include <endian.h>
  203. # if __BYTE_ORDER == __LITTLE_ENDIAN
  204. # define UA_BINARY_OVERLAYABLE_INTEGER 1
  205. # endif
  206. # if __FLOAT_BYTE_ORDER == __LITTLE_ENDIAN
  207. # define UA_BINARY_OVERLAYABLE_FLOAT 1
  208. # endif
  209. #elif defined(__OpenBSD__) /* OpenBSD */
  210. # include <sys/endian.h>
  211. # if BYTE_ORDER == LITTLE_ENDIAN
  212. # define UA_BINARY_OVERLAYABLE_INTEGER 1
  213. # endif
  214. #elif defined(__NetBSD__) || defined(__FreeBSD__) || defined(__DragonFly__) /* Other BSD */
  215. # include <sys/endian.h>
  216. # if _BYTE_ORDER == _LITTLE_ENDIAN
  217. # define UA_BINARY_OVERLAYABLE_INTEGER 1
  218. # endif
  219. #elif defined(__APPLE__) /* Apple (MacOS, iOS) */
  220. # include <libkern/OSByteOrder.h>
  221. # if defined(__LITTLE_ENDIAN__)
  222. # define UA_BINARY_OVERLAYABLE_INTEGER 1
  223. # endif
  224. #elif defined(__QNX__) || defined(__QNXNTO__) /* QNX */
  225. # include <gulliver.h>
  226. # if defined(__LITTLEENDIAN__)
  227. # define UA_BINARY_OVERLAYABLE_INTEGER 1
  228. # endif
  229. #endif
  230. #ifndef UA_BINARY_OVERLAYABLE_INTEGER
  231. # define UA_BINARY_OVERLAYABLE_INTEGER 0
  232. #endif
  233. /**
  234. * Float Endianness
  235. * ^^^^^^^^^^^^^^^^
  236. * The definition ``UA_BINARY_OVERLAYABLE_FLOAT`` is true when the floating
  237. * point number representation of the target architecture is IEEE 754. Note that
  238. * this cannot be reliable detected with macros for the clang compiler
  239. * (beginning of 2017). Just override if necessary. */
  240. #if defined(_WIN32)
  241. # define UA_BINARY_OVERLAYABLE_FLOAT 1
  242. #elif defined(__FLOAT_WORD_ORDER__) && defined(__ORDER_LITTLE_ENDIAN__) && \
  243. (__FLOAT_WORD_ORDER__ == __ORDER_LITTLE_ENDIAN__) /* Defined only in GCC */
  244. # define UA_BINARY_OVERLAYABLE_FLOAT 1
  245. #elif defined(__FLOAT_WORD_ORDER) && defined(__LITTLE_ENDIAN) && \
  246. (__FLOAT_WORD_ORDER == __LITTLE_ENDIAN) /* Defined only in GCC */
  247. # define UA_BINARY_OVERLAYABLE_FLOAT 1
  248. #endif
  249. #ifndef UA_BINARY_OVERLAYABLE_FLOAT
  250. # define UA_BINARY_OVERLAYABLE_FLOAT 0
  251. #endif
  252. /**
  253. * Utility Definitions
  254. * ^^^^^^^^^^^^^^^^^^^ */
  255. /* Outputs an error message at compile time if the assert fails.
  256. * Example usage:
  257. * UA_STATIC_ASSERT(sizeof(long)==7, use_another_compiler_luke)
  258. * See: https://stackoverflow.com/a/4815532/869402 */
  259. #if defined(__cplusplus) && __cplusplus >= 201103L /* C++11 or above */
  260. # define UA_STATIC_ASSERT(cond,msg) static_assert(cond, #msg)
  261. #elif defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L /* C11 or above */
  262. # define UA_STATIC_ASSERT(cond,msg) _Static_assert(cond, #msg)
  263. #elif defined(__GNUC__) || defined(__clang__) || defined(_MSC_VER) /* GCC, Clang, MSC */
  264. # define UA_CTASTR2(pre,post) pre ## post
  265. # define UA_CTASTR(pre,post) UA_CTASTR2(pre,post)
  266. # define UA_STATIC_ASSERT(cond,msg) \
  267. typedef struct { \
  268. int UA_CTASTR(static_assertion_failed_,msg) : !!(cond); \
  269. } UA_CTASTR(static_assertion_failed_,__COUNTER__)
  270. #else /* Everybody else */
  271. # define UA_STATIC_ASSERT(cond,msg) typedef char static_assertion_##msg[(cond)?1:-1]
  272. #endif
  273. /* To generate smaller binaries, descriptive strings can be excluded from the
  274. * datatype description */
  275. #ifdef UA_ENABLE_TYPENAMES
  276. # define UA_TYPENAME(name) name,
  277. #else
  278. # define UA_TYPENAME(name)
  279. #endif
  280. #ifdef __cplusplus
  281. } // extern "C"
  282. #endif
  283. #endif /* UA_CONFIG_H_ */