ua_config.h.in 10 KB

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