ua_config.h.in 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  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_PUBSUB
  27. #cmakedefine UA_ENABLE_ENCRYPTION
  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. #cmakedefine UA_ENABLE_VALGRIND_INTERACTIVE
  39. #define UA_VALGRIND_INTERACTIVE_INTERVAL ${UA_VALGRIND_INTERACTIVE_INTERVAL}
  40. /* Options for Debugging */
  41. #cmakedefine UA_DEBUG
  42. #cmakedefine UA_DEBUG_DUMP_PKGS
  43. #include "ua_architecture.h"
  44. /**
  45. * C99 Definitions
  46. * --------------- */
  47. #include <string.h>
  48. #include <stddef.h>
  49. /* Include stdint.h and stdbool.h or workaround for older Visual Studios */
  50. #if !defined(_MSC_VER) || _MSC_VER >= 1600
  51. # include <stdint.h>
  52. # include <stdbool.h> /* C99 Boolean */
  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. # ifndef __COUNTER__ /* PPC GCC fix */
  86. # define __COUNTER__ __LINE__
  87. # endif
  88. # define UA_STATIC_ASSERT(cond,msg) \
  89. typedef struct { \
  90. int UA_CTASTR(static_assertion_failed_,msg) : !!(cond); \
  91. } UA_CTASTR(static_assertion_failed_,__COUNTER__)
  92. #else /* Everybody else */
  93. # define UA_STATIC_ASSERT(cond,msg) typedef char static_assertion_##msg[(cond)?1:-1]
  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. #if defined(__GNUC__) || defined(__clang__)
  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. # define UA_FORMAT(X,Y) __attribute__ ((format (printf, X, Y)))
  151. #else
  152. # define UA_FUNC_ATTR_MALLOC
  153. # define UA_FUNC_ATTR_PURE
  154. # define UA_FUNC_ATTR_CONST
  155. # define UA_FUNC_ATTR_WARN_UNUSED_RESULT
  156. # define UA_FORMAT(X,Y)
  157. #endif
  158. #if defined(__GNUC__) || defined(__clang__)
  159. # define UA_DEPRECATED __attribute__((deprecated))
  160. #elif defined(_MSC_VER)
  161. # define UA_DEPRECATED __declspec(deprecated)
  162. #else
  163. # define UA_DEPRECATED
  164. #endif
  165. /**
  166. * Detect Binary Overlaying for Encoding
  167. * -------------------------------------
  168. * Integers and floating point numbers are transmitted in little-endian (IEEE 754
  169. * for floating point) encoding. If the target architecture uses the same
  170. * format, numeral datatypes can be memcpy'd (overlayed) on the binary stream.
  171. * This speeds up encoding.
  172. *
  173. * Integer Endianness
  174. * ^^^^^^^^^^^^^^^^^^
  175. * The definition ``UA_BINARY_OVERLAYABLE_INTEGER`` is true when the integer
  176. * representation of the target architecture is little-endian. */
  177. #if defined(_WIN32)
  178. # define UA_BINARY_OVERLAYABLE_INTEGER 1
  179. #elif (defined(__BYTE_ORDER__) && defined(__ORDER_LITTLE_ENDIAN__) && \
  180. (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__))
  181. # define UA_BINARY_OVERLAYABLE_INTEGER 1
  182. #elif defined(__linux__) /* Linux (including Android) */
  183. # include <endian.h>
  184. # if __BYTE_ORDER == __LITTLE_ENDIAN
  185. # define UA_BINARY_OVERLAYABLE_INTEGER 1
  186. # endif
  187. #elif defined(__OpenBSD__) /* OpenBSD */
  188. # include <sys/endian.h>
  189. # if BYTE_ORDER == LITTLE_ENDIAN
  190. # define UA_BINARY_OVERLAYABLE_INTEGER 1
  191. # endif
  192. #elif defined(__NetBSD__) || defined(__FreeBSD__) || defined(__DragonFly__) /* Other BSD */
  193. # include <sys/endian.h>
  194. # if _BYTE_ORDER == _LITTLE_ENDIAN
  195. # define UA_BINARY_OVERLAYABLE_INTEGER 1
  196. # endif
  197. #elif defined(__APPLE__) /* Apple (MacOS, iOS) */
  198. # include <libkern/OSByteOrder.h>
  199. # if defined(__LITTLE_ENDIAN__)
  200. # define UA_BINARY_OVERLAYABLE_INTEGER 1
  201. # endif
  202. #elif defined(__QNX__) || defined(__QNXNTO__) /* QNX */
  203. # include <gulliver.h>
  204. # if defined(__LITTLEENDIAN__)
  205. # define UA_BINARY_OVERLAYABLE_INTEGER 1
  206. # endif
  207. #endif
  208. #ifndef UA_BINARY_OVERLAYABLE_INTEGER
  209. # define UA_BINARY_OVERLAYABLE_INTEGER 0
  210. #endif
  211. /**
  212. * Float Endianness
  213. * ^^^^^^^^^^^^^^^^
  214. * The definition ``UA_BINARY_OVERLAYABLE_FLOAT`` is true when the floating
  215. * point number representation of the target architecture is IEEE 754. Note that
  216. * this cannot be reliable detected with macros for the clang compiler
  217. * (beginning of 2017). ``UA_BINARY_OVERLAYABLE_FLOAT`` can be manually set if
  218. * the target is known to be little endian with floats in the IEEE 754
  219. * format. */
  220. #if defined(_WIN32)
  221. # define UA_BINARY_OVERLAYABLE_FLOAT 1
  222. #elif defined(__FLOAT_WORD_ORDER__) && defined(__ORDER_LITTLE_ENDIAN__) && \
  223. (__FLOAT_WORD_ORDER__ == __ORDER_LITTLE_ENDIAN__) /* Defined only in GCC */
  224. # define UA_BINARY_OVERLAYABLE_FLOAT 1
  225. #elif defined(__FLOAT_WORD_ORDER) && defined(__LITTLE_ENDIAN) && \
  226. (__FLOAT_WORD_ORDER == __LITTLE_ENDIAN) /* Defined only in GCC */
  227. # define UA_BINARY_OVERLAYABLE_FLOAT 1
  228. #elif defined(__linux__) /* Linux (including Android) */
  229. # include <endian.h>
  230. # if defined(__ANDROID__)
  231. # if __BYTE_ORDER == __LITTLE_ENDIAN
  232. # define UA_BINARY_OVERLAYABLE_INTEGER 1
  233. # endif
  234. # elif __FLOAT_WORD_ORDER == __LITTLE_ENDIAN
  235. # define UA_BINARY_OVERLAYABLE_FLOAT 1
  236. # endif
  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_ */