ua_config.h.in 10.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324
  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_PUBSUB
  26. #cmakedefine UA_ENABLE_PUBSUB_INFORMATIONMODEL
  27. #cmakedefine UA_ENABLE_ENCRYPTION
  28. #cmakedefine UA_ENABLE_SUBSCRIPTIONS_EVENTS
  29. /* Multithreading */
  30. #cmakedefine UA_ENABLE_MULTITHREADING
  31. #cmakedefine UA_ENABLE_IMMUTABLE_NODES
  32. #if defined(UA_ENABLE_MULTITHREADING) && !defined(UA_ENABLE_IMMUTABLE_NODES)
  33. #error "The multithreading feature requires nodes to be immutable"
  34. #endif
  35. /* Advanced Options */
  36. #cmakedefine UA_ENABLE_STATUSCODE_DESCRIPTIONS
  37. #cmakedefine UA_ENABLE_TYPENAMES
  38. #cmakedefine UA_ENABLE_DETERMINISTIC_RNG
  39. #cmakedefine UA_ENABLE_GENERATE_NAMESPACE0
  40. #cmakedefine UA_ENABLE_NONSTANDARD_UDP
  41. #cmakedefine UA_ENABLE_DISCOVERY
  42. #cmakedefine UA_ENABLE_DISCOVERY_MULTICAST
  43. #cmakedefine UA_ENABLE_DISCOVERY_SEMAPHORE
  44. #cmakedefine UA_ENABLE_UNIT_TEST_FAILURE_HOOKS
  45. #cmakedefine UA_ENABLE_VALGRIND_INTERACTIVE
  46. #define UA_VALGRIND_INTERACTIVE_INTERVAL ${UA_VALGRIND_INTERACTIVE_INTERVAL}
  47. /* Options for Debugging */
  48. #cmakedefine UA_DEBUG
  49. #cmakedefine UA_DEBUG_DUMP_PKGS
  50. /**
  51. * C99 Definitions
  52. * --------------- */
  53. #include <string.h>
  54. #include <stddef.h>
  55. /* Include stdint.h and stdbool.h or workaround for older Visual Studios */
  56. #if !defined(_MSC_VER) || _MSC_VER >= 1600
  57. # include <stdint.h>
  58. # include <stdbool.h> /* C99 Boolean */
  59. # if defined(_WRS_KERNEL)
  60. # define UINT32_C(x) ((x) + (UINT32_MAX - UINT32_MAX))
  61. # endif
  62. #else
  63. # include "ms_stdint.h"
  64. # if !defined(__bool_true_false_are_defined)
  65. # define bool short
  66. # define true 1
  67. # define false 0
  68. # define __bool_true_false_are_defined
  69. # endif
  70. #endif
  71. /**
  72. * Assertions
  73. * ----------
  74. * The assert macro is disabled by defining NDEBUG. It is often forgotten to
  75. * include -DNDEBUG in the compiler flags when using the single-file release. So
  76. * we make assertions dependent on the UA_DEBUG definition handled by CMake. */
  77. #ifdef UA_DEBUG
  78. # include <assert.h>
  79. # define UA_assert(ignore) assert(ignore)
  80. #else
  81. # define UA_assert(ignore)
  82. #endif
  83. /* Outputs an error message at compile time if the assert fails.
  84. * Example usage:
  85. * UA_STATIC_ASSERT(sizeof(long)==7, use_another_compiler_luke)
  86. * See: https://stackoverflow.com/a/4815532/869402 */
  87. #if defined(__cplusplus) && __cplusplus >= 201103L /* C++11 or above */
  88. # define UA_STATIC_ASSERT(cond,msg) static_assert(cond, #msg)
  89. #elif defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L /* C11 or above */
  90. # define UA_STATIC_ASSERT(cond,msg) _Static_assert(cond, #msg)
  91. #elif defined(__GNUC__) || defined(__clang__) || defined(_MSC_VER) /* GCC, Clang, MSC */
  92. # define UA_CTASTR2(pre,post) pre ## post
  93. # define UA_CTASTR(pre,post) UA_CTASTR2(pre,post)
  94. # ifndef __COUNTER__ /* PPC GCC fix */
  95. # define __COUNTER__ __LINE__
  96. # endif
  97. # define UA_STATIC_ASSERT(cond,msg) \
  98. typedef struct { \
  99. int UA_CTASTR(static_assertion_failed_,msg) : !!(cond); \
  100. } UA_CTASTR(static_assertion_failed_,__COUNTER__)
  101. #else /* Everybody else */
  102. # define UA_STATIC_ASSERT(cond,msg) typedef char static_assertion_##msg[(cond)?1:-1]
  103. #endif
  104. /**
  105. * Memory Management
  106. * -----------------
  107. * The default is to use the malloc implementation from ``stdlib.h``. Override
  108. * if required. Changing the settings has no effect on a pre-compiled
  109. * library. */
  110. #include <stdlib.h>
  111. #if defined(_WIN32) && !defined(__clang__)
  112. # include <malloc.h>
  113. #endif
  114. #if !defined(UA_FREERTOS)
  115. # define UA_free(ptr) free(ptr)
  116. # define UA_malloc(size) malloc(size)
  117. # define UA_calloc(num, size) calloc(num, size)
  118. # define UA_realloc(ptr, size) realloc(ptr, size)
  119. #else
  120. # include <FreeRTOS.h>
  121. # define UA_free(ptr) vPortFree(ptr)
  122. # define UA_malloc(size) pvPortMalloc(size)
  123. # define UA_calloc(num, size) pvPortCalloc(num, size)
  124. # define UA_realloc(ptr, size) pvPortRealloc(ptr, size)
  125. #endif
  126. /* Stack-allocation of memory. Use C99 variable-length arrays if possible.
  127. * Otherwise revert to alloca. Note that alloca is not supported on some
  128. * plattforms. */
  129. #if defined(__GNUC__) || defined(__clang__)
  130. # define UA_STACKARRAY(TYPE, NAME, SIZE) TYPE NAME[SIZE]
  131. #elif defined(_WIN32)
  132. # define UA_STACKARRAY(TYPE, NAME, SIZE) \
  133. TYPE *NAME = (TYPE*)_alloca(sizeof(TYPE) * SIZE)
  134. #else
  135. # include <alloca.h>
  136. # define UA_STACKARRAY(TYPE, NAME, SIZE) \
  137. TYPE *NAME = (TYPE*)alloca(sizeof(TYPE) * SIZE)
  138. #endif
  139. /**
  140. * Function Export
  141. * ---------------
  142. * On Win32: Define ``UA_DYNAMIC_LINKING`` and ``UA_DYNAMIC_LINKING_EXPORT`` in
  143. * order to export symbols for a DLL. Define ``UA_DYNAMIC_LINKING`` only to
  144. * import symbols from a DLL.*/
  145. #cmakedefine UA_DYNAMIC_LINKING
  146. #if defined(_WIN32) && defined(UA_DYNAMIC_LINKING)
  147. # ifdef UA_DYNAMIC_LINKING_EXPORT /* export dll */
  148. # ifdef __GNUC__
  149. # define UA_EXPORT __attribute__ ((dllexport))
  150. # else
  151. # define UA_EXPORT __declspec(dllexport)
  152. # endif
  153. # else /* import dll */
  154. # ifdef __GNUC__
  155. # define UA_EXPORT __attribute__ ((dllimport))
  156. # else
  157. # define UA_EXPORT __declspec(dllimport)
  158. # endif
  159. # endif
  160. #else /* non win32 */
  161. # if __GNUC__ || __clang__
  162. # define UA_EXPORT __attribute__ ((visibility ("default")))
  163. # endif
  164. #endif
  165. #ifndef UA_EXPORT
  166. # define UA_EXPORT /* fallback to default */
  167. #endif
  168. /**
  169. * Inline Functions
  170. * ---------------- */
  171. #ifdef _MSC_VER
  172. # define UA_INLINE __inline
  173. #else
  174. # define UA_INLINE inline
  175. #endif
  176. /**
  177. * Non-aliasing pointers
  178. * -------------------- */
  179. #ifdef _MSC_VER
  180. # define UA_RESTRICT __restrict
  181. #elif defined(__GNUC__)
  182. # define UA_RESTRICT __restrict__
  183. #else
  184. # define UA_RESTRICT restrict
  185. #endif
  186. /**
  187. * Function attributes
  188. * ------------------- */
  189. #if defined(__GNUC__) || defined(__clang__)
  190. # define UA_FUNC_ATTR_MALLOC __attribute__((malloc))
  191. # define UA_FUNC_ATTR_PURE __attribute__ ((pure))
  192. # define UA_FUNC_ATTR_CONST __attribute__((const))
  193. # define UA_FUNC_ATTR_WARN_UNUSED_RESULT __attribute__((warn_unused_result))
  194. # define UA_FORMAT(X,Y) __attribute__ ((format (printf, X, Y)))
  195. #else
  196. # define UA_FUNC_ATTR_MALLOC
  197. # define UA_FUNC_ATTR_PURE
  198. # define UA_FUNC_ATTR_CONST
  199. # define UA_FUNC_ATTR_WARN_UNUSED_RESULT
  200. # define UA_FORMAT(X,Y)
  201. #endif
  202. #if defined(__GNUC__) || defined(__clang__)
  203. # define UA_DEPRECATED __attribute__((deprecated))
  204. #elif defined(_MSC_VER)
  205. # define UA_DEPRECATED __declspec(deprecated)
  206. #else
  207. # define UA_DEPRECATED
  208. #endif
  209. /**
  210. * Detect Binary Overlaying for Encoding
  211. * -------------------------------------
  212. * Integers and floating point numbers are transmitted in little-endian (IEEE 754
  213. * for floating point) encoding. If the target architecture uses the same
  214. * format, numeral datatypes can be memcpy'd (overlayed) on the binary stream.
  215. * This speeds up encoding.
  216. *
  217. * Integer Endianness
  218. * ^^^^^^^^^^^^^^^^^^
  219. * The definition ``UA_BINARY_OVERLAYABLE_INTEGER`` is true when the integer
  220. * representation of the target architecture is little-endian. */
  221. #if defined(_WIN32)
  222. # define UA_BINARY_OVERLAYABLE_INTEGER 1
  223. #elif (defined(__BYTE_ORDER__) && defined(__ORDER_LITTLE_ENDIAN__) && \
  224. (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__))
  225. # define UA_BINARY_OVERLAYABLE_INTEGER 1
  226. #elif defined(__linux__) /* Linux (including Android) */
  227. # include <endian.h>
  228. # if __BYTE_ORDER == __LITTLE_ENDIAN
  229. # define UA_BINARY_OVERLAYABLE_INTEGER 1
  230. # endif
  231. #elif defined(__OpenBSD__) /* OpenBSD */
  232. # include <sys/endian.h>
  233. # if BYTE_ORDER == LITTLE_ENDIAN
  234. # define UA_BINARY_OVERLAYABLE_INTEGER 1
  235. # endif
  236. #elif defined(__NetBSD__) || defined(__FreeBSD__) || defined(__DragonFly__) /* Other BSD */
  237. # include <sys/endian.h>
  238. # if _BYTE_ORDER == _LITTLE_ENDIAN
  239. # define UA_BINARY_OVERLAYABLE_INTEGER 1
  240. # endif
  241. #elif defined(__APPLE__) /* Apple (MacOS, iOS) */
  242. # include <libkern/OSByteOrder.h>
  243. # if defined(__LITTLE_ENDIAN__)
  244. # define UA_BINARY_OVERLAYABLE_INTEGER 1
  245. # endif
  246. #elif defined(__QNX__) || defined(__QNXNTO__) /* QNX */
  247. # include <gulliver.h>
  248. # if defined(__LITTLEENDIAN__)
  249. # define UA_BINARY_OVERLAYABLE_INTEGER 1
  250. # endif
  251. #endif
  252. #ifndef UA_BINARY_OVERLAYABLE_INTEGER
  253. # define UA_BINARY_OVERLAYABLE_INTEGER 0
  254. #endif
  255. /**
  256. * Float Endianness
  257. * ^^^^^^^^^^^^^^^^
  258. * The definition ``UA_BINARY_OVERLAYABLE_FLOAT`` is true when the floating
  259. * point number representation of the target architecture is IEEE 754. Note that
  260. * this cannot be reliable detected with macros for the clang compiler
  261. * (beginning of 2017). ``UA_BINARY_OVERLAYABLE_FLOAT`` can be manually set if
  262. * the target is known to be little endian with floats in the IEEE 754
  263. * format. */
  264. #if defined(_WIN32)
  265. # define UA_BINARY_OVERLAYABLE_FLOAT 1
  266. #elif defined(__FLOAT_WORD_ORDER__) && defined(__ORDER_LITTLE_ENDIAN__) && \
  267. (__FLOAT_WORD_ORDER__ == __ORDER_LITTLE_ENDIAN__) /* Defined only in GCC */
  268. # define UA_BINARY_OVERLAYABLE_FLOAT 1
  269. #elif defined(__FLOAT_WORD_ORDER) && defined(__LITTLE_ENDIAN) && \
  270. (__FLOAT_WORD_ORDER == __LITTLE_ENDIAN) /* Defined only in GCC */
  271. # define UA_BINARY_OVERLAYABLE_FLOAT 1
  272. #elif defined(__linux__) /* Linux (including Android) */
  273. # include <endian.h>
  274. # if defined(__ANDROID__)
  275. # if __BYTE_ORDER == __LITTLE_ENDIAN
  276. # define UA_BINARY_OVERLAYABLE_INTEGER 1
  277. # endif
  278. # elif __FLOAT_WORD_ORDER == __LITTLE_ENDIAN
  279. # define UA_BINARY_OVERLAYABLE_FLOAT 1
  280. # endif
  281. #elif defined(_WRS_KERNEL)
  282. # define UA_BINARY_OVERLAYABLE_FLOAT 1
  283. #endif
  284. #ifndef UA_BINARY_OVERLAYABLE_FLOAT
  285. # define UA_BINARY_OVERLAYABLE_FLOAT 0
  286. #endif
  287. #ifdef __cplusplus
  288. } // extern "C"
  289. #endif
  290. #endif /* UA_CONFIG_H_ */