ua_config.h.in 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313
  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_NODESET_COMPILER_DESCRIPTIONS
  41. #cmakedefine UA_ENABLE_DETERMINISTIC_RNG
  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. #include "ua_architecture.h"
  55. /**
  56. * C99 Definitions
  57. * --------------- */
  58. #include <string.h>
  59. #include <stddef.h>
  60. /* Include stdint.h and stdbool.h or workaround for older Visual Studios */
  61. #if !defined(_MSC_VER) || _MSC_VER >= 1600
  62. # include <stdint.h>
  63. # include <stdbool.h> /* C99 Boolean */
  64. #else
  65. # include "ms_stdint.h"
  66. # if !defined(__bool_true_false_are_defined)
  67. # define bool unsigned char
  68. # define true 1
  69. # define false 0
  70. # define __bool_true_false_are_defined
  71. # endif
  72. #endif
  73. /**
  74. * Assertions
  75. * ----------
  76. * The assert macro is disabled by defining NDEBUG. It is often forgotten to
  77. * include -DNDEBUG in the compiler flags when using the single-file release. So
  78. * we make assertions dependent on the UA_DEBUG definition handled by CMake. */
  79. #ifdef UA_DEBUG
  80. # include <assert.h>
  81. # define UA_assert(ignore) assert(ignore)
  82. #else
  83. # define UA_assert(ignore)
  84. #endif
  85. /* Outputs an error message at compile time if the assert fails.
  86. * Example usage:
  87. * UA_STATIC_ASSERT(sizeof(long)==7, use_another_compiler_luke)
  88. * See: https://stackoverflow.com/a/4815532/869402 */
  89. #if defined(__cplusplus) && __cplusplus >= 201103L /* C++11 or above */
  90. # define UA_STATIC_ASSERT(cond,msg) static_assert(cond, #msg)
  91. #elif defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L /* C11 or above */
  92. # define UA_STATIC_ASSERT(cond,msg) _Static_assert(cond, #msg)
  93. #elif defined(__GNUC__) || defined(__clang__) || defined(_MSC_VER) /* GCC, Clang, MSC */
  94. # define UA_CTASTR2(pre,post) pre ## post
  95. # define UA_CTASTR(pre,post) UA_CTASTR2(pre,post)
  96. # ifndef __COUNTER__ /* PPC GCC fix */
  97. # define __COUNTER__ __LINE__
  98. # endif
  99. # define UA_STATIC_ASSERT(cond,msg) \
  100. typedef struct { \
  101. int UA_CTASTR(static_assertion_failed_,msg) : !!(cond); \
  102. } UA_CTASTR(static_assertion_failed_,__COUNTER__)
  103. #else /* Everybody else */
  104. # define UA_STATIC_ASSERT(cond,msg) typedef char static_assertion_##msg[(cond)?1:-1]
  105. #endif
  106. /**
  107. * Function Export
  108. * ---------------
  109. * On Win32: Define ``UA_DYNAMIC_LINKING`` and ``UA_DYNAMIC_LINKING_EXPORT`` in
  110. * order to export symbols for a DLL. Define ``UA_DYNAMIC_LINKING`` only to
  111. * import symbols from a DLL.*/
  112. #cmakedefine UA_DYNAMIC_LINKING
  113. #if defined(_WIN32) && defined(UA_DYNAMIC_LINKING)
  114. # ifdef UA_DYNAMIC_LINKING_EXPORT /* export dll */
  115. # ifdef __GNUC__
  116. # define UA_EXPORT __attribute__ ((dllexport))
  117. # else
  118. # define UA_EXPORT __declspec(dllexport)
  119. # endif
  120. # else /* import dll */
  121. # ifdef __GNUC__
  122. # define UA_EXPORT __attribute__ ((dllimport))
  123. # else
  124. # define UA_EXPORT __declspec(dllimport)
  125. # endif
  126. # endif
  127. #else /* non win32 */
  128. # if __GNUC__ || __clang__
  129. # define UA_EXPORT __attribute__ ((visibility ("default")))
  130. # endif
  131. #endif
  132. #ifndef UA_EXPORT
  133. # define UA_EXPORT /* fallback to default */
  134. #endif
  135. /**
  136. * Inline Functions
  137. * ---------------- */
  138. #ifdef _MSC_VER
  139. # define UA_INLINE __inline
  140. #else
  141. # define UA_INLINE inline
  142. #endif
  143. /**
  144. * Non-aliasing pointers
  145. * -------------------- */
  146. #ifdef _MSC_VER
  147. # define UA_RESTRICT __restrict
  148. #elif defined(__GNUC__)
  149. # define UA_RESTRICT __restrict__
  150. #else
  151. # define UA_RESTRICT restrict
  152. #endif
  153. /**
  154. * Function attributes
  155. * ------------------- */
  156. #if defined(__GNUC__) || defined(__clang__)
  157. # define UA_FUNC_ATTR_MALLOC __attribute__((malloc))
  158. # define UA_FUNC_ATTR_PURE __attribute__ ((pure))
  159. # define UA_FUNC_ATTR_CONST __attribute__((const))
  160. # define UA_FUNC_ATTR_WARN_UNUSED_RESULT __attribute__((warn_unused_result))
  161. # define UA_FORMAT(X,Y) __attribute__ ((format (printf, X, Y)))
  162. #else
  163. # define UA_FUNC_ATTR_MALLOC
  164. # define UA_FUNC_ATTR_PURE
  165. # define UA_FUNC_ATTR_CONST
  166. # define UA_FUNC_ATTR_WARN_UNUSED_RESULT
  167. # define UA_FORMAT(X,Y)
  168. #endif
  169. #if defined(__GNUC__) || defined(__clang__)
  170. # define UA_DEPRECATED __attribute__((deprecated))
  171. #elif defined(_MSC_VER)
  172. # define UA_DEPRECATED __declspec(deprecated)
  173. #else
  174. # define UA_DEPRECATED
  175. #endif
  176. /**
  177. * Detect Endianness and IEEE 754 floating point
  178. * ---------------------------------------------
  179. * Integers and floating point numbers are transmitted in little-endian (IEEE
  180. * 754 for floating point) encoding. If the target architecture uses the same
  181. * format, numeral datatypes can be memcpy'd (overlayed) on the network buffer.
  182. * Otherwise, a slow default encoding routine is used that works for every
  183. * architecture.
  184. *
  185. * Integer Endianness
  186. * ^^^^^^^^^^^^^^^^^^
  187. * The definition ``UA_LITTLE_ENDIAN`` is true when the integer representation
  188. * of the target architecture is little-endian. */
  189. #if defined(_WIN32)
  190. # define UA_LITTLE_ENDIAN 1
  191. #elif defined(__i386__) || defined(__x86_64__) || defined(__amd64__)
  192. # define UA_LITTLE_ENDIAN 1
  193. #elif (defined(__BYTE_ORDER__) && defined(__ORDER_LITTLE_ENDIAN__) && \
  194. (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__))
  195. # define UA_LITTLE_ENDIAN 1
  196. #elif defined(__linux__) /* Linux (including Android) */
  197. # include <endian.h>
  198. # if __BYTE_ORDER == __LITTLE_ENDIAN
  199. # define UA_LITTLE_ENDIAN 1
  200. # endif
  201. #elif defined(__OpenBSD__) /* OpenBSD */
  202. # include <sys/endian.h>
  203. # if BYTE_ORDER == LITTLE_ENDIAN
  204. # define UA_LITTLE_ENDIAN 1
  205. # endif
  206. #elif defined(__NetBSD__) || defined(__FreeBSD__) || defined(__DragonFly__) /* Other BSD */
  207. # include <sys/endian.h>
  208. # if _BYTE_ORDER == _LITTLE_ENDIAN
  209. # define UA_LITTLE_ENDIAN 1
  210. # endif
  211. #elif defined(__APPLE__) /* Apple (MacOS, iOS) */
  212. # include <libkern/OSByteOrder.h>
  213. # if defined(__LITTLE_ENDIAN__)
  214. # define UA_LITTLE_ENDIAN 1
  215. # endif
  216. #elif defined(__QNX__) || defined(__QNXNTO__) /* QNX */
  217. # include <gulliver.h>
  218. # if defined(__LITTLEENDIAN__)
  219. # define UA_LITTLE_ENDIAN 1
  220. # endif
  221. #elif defined(_OS9000) /* OS-9 */
  222. # if defined(_LIL_END)
  223. # define UA_LITTLE_ENDIAN 1
  224. # endif
  225. #endif
  226. #ifndef UA_LITTLE_ENDIAN
  227. # define UA_LITTLE_ENDIAN 0
  228. #endif
  229. /* Can the integers be memcpy'd onto the network buffer? Add additional checks
  230. * here. Some platforms (e.g. QNX) have sizeof(bool) > 1. Manually disable
  231. * overlayed integer encoding if that is the case. */
  232. #if (UA_LITTLE_ENDIAN == 1)
  233. UA_STATIC_ASSERT(sizeof(bool) == 1, cannot_overlay_integers_with_large_bool);
  234. # define UA_BINARY_OVERLAYABLE_INTEGER 1
  235. #else
  236. # define UA_BINARY_OVERLAYABLE_INTEGER 0
  237. #endif
  238. /**
  239. * Float Endianness
  240. * ^^^^^^^^^^^^^^^^
  241. * The definition ``UA_FLOAT_IEEE754`` is set to true when the floating point
  242. * number representation of the target architecture is IEEE 754. The definition
  243. * ``UA_FLOAT_LITTLE_ENDIAN`` is set to true when the floating point number
  244. * representation is in little-endian encoding. */
  245. #if defined(_WIN32)
  246. # define UA_FLOAT_IEEE754 1
  247. #elif defined(__i386__) || defined(__x86_64__) || defined(__amd64__) || \
  248. defined(__ia64__) || defined(__powerpc__) || defined(__sparc__) || \
  249. defined(__arm__)
  250. # define UA_FLOAT_IEEE754 1
  251. #elif defined(__STDC_IEC_559__)
  252. # define UA_FLOAT_IEEE754 1
  253. #else
  254. # define UA_FLOAT_IEEE754 0
  255. #endif
  256. /* Wikipedia says (https://en.wikipedia.org/wiki/Endianness): Although the
  257. * ubiquitous x86 processors of today use little-endian storage for all types of
  258. * data (integer, floating point, BCD), there are a number of hardware
  259. * architectures where floating-point numbers are represented in big-endian form
  260. * while integers are represented in little-endian form. */
  261. #if defined(_WIN32)
  262. # define UA_FLOAT_LITTLE_ENDIAN 1
  263. #elif defined(__i386__) || defined(__x86_64__) || defined(__amd64__)
  264. # define UA_FLOAT_LITTLE_ENDIAN 1
  265. #elif defined(__FLOAT_WORD_ORDER__) && defined(__ORDER_LITTLE_ENDIAN__) && \
  266. (__FLOAT_WORD_ORDER__ == __ORDER_LITTLE_ENDIAN__) /* Defined only in GCC */
  267. # define UA_FLOAT_LITTLE_ENDIAN 1
  268. #elif defined(__FLOAT_WORD_ORDER) && defined(__LITTLE_ENDIAN) && \
  269. (__FLOAT_WORD_ORDER == __LITTLE_ENDIAN) /* Defined only in GCC */
  270. # define UA_FLOAT_LITTLE_ENDIAN 1
  271. #endif
  272. #ifndef UA_FLOAT_LITTLE_ENDIAN
  273. # define UA_FLOAT_LITTLE_ENDIAN 0
  274. #endif
  275. /* Only if the floating points are litle-endian **and** in IEEE 754 format can
  276. * we memcpy directly onto the network buffer. */
  277. #if (UA_FLOAT_IEEE754 == 1) && (UA_FLOAT_LITTLE_ENDIAN == 1)
  278. # define UA_BINARY_OVERLAYABLE_FLOAT 1
  279. #else
  280. # define UA_BINARY_OVERLAYABLE_FLOAT 0
  281. #endif
  282. #ifdef __cplusplus
  283. } // extern "C"
  284. #endif
  285. #endif /* UA_CONFIG_H_ */