ua_config.h.in 8.6 KB

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