ua_config.h.in 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  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. * Library 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. * Options
  19. * ------- */
  20. #define UA_LOGLEVEL ${UA_LOGLEVEL}
  21. #cmakedefine UA_ENABLE_METHODCALLS
  22. #cmakedefine UA_ENABLE_NODEMANAGEMENT
  23. #cmakedefine UA_ENABLE_SUBSCRIPTIONS
  24. #cmakedefine UA_ENABLE_MULTITHREADING
  25. /**
  26. * Advanced Options
  27. * ---------------- */
  28. #cmakedefine UA_ENABLE_STATUSCODE_DESCRIPTIONS
  29. #cmakedefine UA_ENABLE_TYPENAMES
  30. #cmakedefine UA_ENABLE_EMBEDDED_LIBC
  31. #cmakedefine UA_ENABLE_DETERMINISTIC_RNG
  32. #cmakedefine UA_ENABLE_GENERATE_NAMESPACE0
  33. #cmakedefine UA_ENABLE_NONSTANDARD_STATELESS
  34. #cmakedefine UA_ENABLE_NONSTANDARD_UDP
  35. #cmakedefine UA_ENABLE_DISCOVERY
  36. #cmakedefine UA_ENABLE_DISCOVERY_MULTICAST
  37. #cmakedefine UA_ENABLE_DISCOVERY_SEMAPHORE
  38. /**
  39. * Standard Includes
  40. * ----------------- */
  41. #ifndef _XOPEN_SOURCE
  42. #if defined(__QNX__) || defined(__QNXNTO__)
  43. # define _XOPEN_SOURCE 600
  44. #else
  45. # define _XOPEN_SOURCE 500
  46. #endif
  47. #endif
  48. #ifndef _DEFAULT_SOURCE
  49. # define _DEFAULT_SOURCE
  50. #endif
  51. // On older systems we need to define _BSD_SOURCE
  52. // _DEFAULT_SOURCE is an alias for that
  53. #ifndef _BSD_SOURCE
  54. # define _BSD_SOURCE
  55. #endif
  56. // Disable deprecation warnings for sprintf, strncpy, strerror
  57. #ifdef _MSC_VER
  58. # define _CRT_SECURE_NO_WARNINGS
  59. #endif
  60. #include <stddef.h>
  61. /* Include stdint.h or workaround for older Visual Studios */
  62. #if !defined(_MSC_VER) || _MSC_VER >= 1600
  63. # include <stdint.h>
  64. #else
  65. # include "ms_stdint.h"
  66. #endif
  67. #ifndef __cplusplus
  68. # include <stdbool.h> /* C99 Boolean */
  69. /* Manual Boolean:
  70. typedef uint8_t bool;
  71. #define true 1
  72. #define false 0 */
  73. #endif
  74. #include <stdlib.h>
  75. /**
  76. * Memory Management
  77. * ---------------
  78. * The default malloc implementation from ``stdlib.h`` is used internally.
  79. * Override if required. */
  80. #if defined(_WIN32) && !defined(__clang__)
  81. # include <malloc.h>
  82. #endif
  83. #define UA_free(ptr) free(ptr)
  84. #define UA_malloc(size) malloc(size)
  85. #define UA_calloc(num, size) calloc(num, size)
  86. #define UA_realloc(ptr, size) realloc(ptr, size)
  87. #if defined(__GNUC__) || defined(__clang__)
  88. # define UA_alloca(size) __builtin_alloca (size)
  89. #elif defined(_WIN32)
  90. # define UA_alloca(SIZE) _alloca(SIZE)
  91. #else
  92. # include <alloca.h>
  93. # define UA_alloca(SIZE) alloca(SIZE)
  94. #endif
  95. /**
  96. * Function Export
  97. * ---------------
  98. * On Win32: Define ``UA_DYNAMIC_LINKING`` and ``UA_DYNAMIC_LINKING_EXPORT`` in
  99. * order to export symbols for a DLL. Define ``UA_DYNAMIC_LINKING`` only to
  100. * import symbols from a DLL.*/
  101. #cmakedefine UA_DYNAMIC_LINKING
  102. #if defined(_WIN32) && defined(UA_DYNAMIC_LINKING)
  103. # ifdef UA_DYNAMIC_LINKING_EXPORT /* export dll */
  104. # ifdef __GNUC__
  105. # define UA_EXPORT __attribute__ ((dllexport))
  106. # else
  107. # define UA_EXPORT __declspec(dllexport)
  108. # endif
  109. # else /* import dll */
  110. # ifdef __GNUC__
  111. # define UA_EXPORT __attribute__ ((dllimport))
  112. # else
  113. # define UA_EXPORT __declspec(dllimport)
  114. # endif
  115. # endif
  116. #else /* non win32 */
  117. # if __GNUC__ || __clang__
  118. # define UA_EXPORT __attribute__ ((visibility ("default")))
  119. # endif
  120. #endif
  121. #ifndef UA_EXPORT
  122. # define UA_EXPORT /* fallback to default */
  123. #endif
  124. /**
  125. * Inline Functions
  126. * ---------------- */
  127. #ifdef _MSC_VER
  128. # define UA_INLINE __inline
  129. #else
  130. # define UA_INLINE inline
  131. #endif
  132. /**
  133. * Non-aliasing pointers
  134. * -------------------- */
  135. #ifdef _MSC_VER
  136. # define UA_RESTRICT __restrict
  137. #elif defined(__GNUC__)
  138. # define UA_RESTRICT __restrict__
  139. #else
  140. # define UA_RESTRICT restrict
  141. #endif
  142. /**
  143. * Function attributes
  144. * ------------------- */
  145. #ifdef __GNUC__
  146. # define UA_FUNC_ATTR_MALLOC __attribute__((malloc))
  147. # define UA_FUNC_ATTR_PURE __attribute__ ((pure))
  148. # define UA_FUNC_ATTR_CONST __attribute__((const))
  149. # define UA_FUNC_ATTR_WARN_UNUSED_RESULT __attribute__((warn_unused_result))
  150. #else
  151. # define UA_FUNC_ATTR_MALLOC
  152. # define UA_FUNC_ATTR_PURE
  153. # define UA_FUNC_ATTR_CONST
  154. # define UA_FUNC_ATTR_WARN_UNUSED_RESULT
  155. #endif
  156. /**
  157. * String Manipulation
  158. * -------------------
  159. * The header ``string.h`` is defined in the C-standard. If no libc is provided
  160. * (e.g. on some embedded target), use the following definitions and the
  161. * implementation in ``/deps/libc_string.c`` */
  162. #ifndef UA_ENABLE_EMBEDDED_LIBC
  163. # include <string.h>
  164. #else
  165. void *memcpy(void *UA_RESTRICT dest, const void *UA_RESTRICT src, size_t n);
  166. void *memset(void *dest, int c, size_t n);
  167. size_t strlen(const char *s);
  168. int memcmp(const void *vl, const void *vr, size_t n);
  169. #endif
  170. /**
  171. * Binary Encoding Overlays
  172. * ------------------------
  173. * Integers and floating point numbers are transmitted in little-endian (IEEE 754
  174. * for floating point) encoding. If the target architecture uses the same
  175. * format, numeral datatypes can be memcpy'd (overlayed) on the binary stream.
  176. * This speeds up encoding.
  177. *
  178. * Integer Endianness
  179. * ^^^^^^^^^^^^^^^^^^
  180. * The definition ``UA_BINARY_OVERLAYABLE_INTEGER`` is true when the integer
  181. * representation of the target architecture is little-endian. */
  182. #if defined(_WIN32) || (defined(__BYTE_ORDER__) && defined(__ORDER_LITTLE_ENDIAN__) && \
  183. (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__))
  184. # define UA_BINARY_OVERLAYABLE_INTEGER 1
  185. #elif defined(__ANDROID__) /* Andoid */
  186. # include <endian.h>
  187. # if __BYTE_ORDER == __LITTLE_ENDIAN
  188. # define UA_BINARY_OVERLAYABLE_INTEGER 1
  189. # endif
  190. #elif defined(__linux__) /* Linux */
  191. # include <endian.h>
  192. # if __BYTE_ORDER == __LITTLE_ENDIAN
  193. # define UA_BINARY_OVERLAYABLE_INTEGER 1
  194. # endif
  195. # if __FLOAT_BYTE_ORDER == __LITTLE_ENDIAN
  196. # define UA_BINARY_OVERLAYABLE_FLOAT 1
  197. # endif
  198. #elif defined(__OpenBSD__) /* OpenBSD */
  199. # include <sys/endian.h>
  200. # if BYTE_ORDER == LITTLE_ENDIAN
  201. # define UA_BINARY_OVERLAYABLE_INTEGER 1
  202. # endif
  203. #elif defined(__NetBSD__) || defined(__FreeBSD__) || defined(__DragonFly__) /* Other BSD */
  204. # include <sys/endian.h>
  205. # if _BYTE_ORDER == _LITTLE_ENDIAN
  206. # define UA_BINARY_OVERLAYABLE_INTEGER 1
  207. # endif
  208. #elif defined(__APPLE__) /* Apple (MacOS, iOS) */
  209. # include <libkern/OSByteOrder.h>
  210. # if defined(__LITTLE_ENDIAN__)
  211. # define UA_BINARY_OVERLAYABLE_INTEGER 1
  212. # endif
  213. #elif defined(__QNX__) || defined(__QNXNTO__) /* QNX */
  214. # include <gulliver.h>
  215. # if defined(__LITTLEENDIAN__)
  216. # define UA_BINARY_OVERLAYABLE_INTEGER 1
  217. # endif
  218. #endif
  219. #ifndef UA_BINARY_OVERLAYABLE_INTEGER
  220. # define UA_BINARY_OVERLAYABLE_INTEGER 0
  221. #endif
  222. /**
  223. * Float Endianness
  224. * ^^^^^^^^^^^^^^^^
  225. * The definition ``UA_BINARY_OVERLAYABLE_FLOAT`` is true when the floating
  226. * point number representation of the target architecture is IEEE 754. Note that
  227. * this cannot be reliable detected with macros for the clang compiler
  228. * (beginning of 2017). Just override if necessary. */
  229. #if defined(_WIN32)
  230. # define UA_BINARY_OVERLAYABLE_FLOAT 1
  231. #elif defined(__FLOAT_WORD_ORDER__) && defined(__ORDER_LITTLE_ENDIAN__) && \
  232. (__FLOAT_WORD_ORDER__ == __ORDER_LITTLE_ENDIAN__) /* Defined only in GCC */
  233. # define UA_BINARY_OVERLAYABLE_FLOAT 1
  234. #elif defined(__FLOAT_WORD_ORDER) && defined(__LITTLE_ENDIAN) && \
  235. (__FLOAT_WORD_ORDER == __LITTLE_ENDIAN) /* Defined only in GCC */
  236. # define UA_BINARY_OVERLAYABLE_FLOAT 1
  237. #endif
  238. #ifndef UA_BINARY_OVERLAYABLE_FLOAT
  239. # define UA_BINARY_OVERLAYABLE_FLOAT 0
  240. #endif
  241. #ifdef __cplusplus
  242. } // extern "C"
  243. #endif
  244. #endif /* UA_CONFIG_H_ */