ua_config.h.in 9.2 KB

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