Audio plugin host https://kx.studio/carla
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

215 lines
6.4KB

  1. /*
  2. * Carla common defines
  3. * Copyright (C) 2011-2013 Filipe Coelho <falktx@falktx.com>
  4. *
  5. * This program is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU General Public License as
  7. * published by the Free Software Foundation; either version 2 of
  8. * the License, or any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * For a full copy of the GNU General Public License see the doc/GPL.txt file.
  16. */
  17. #ifndef CARLA_DEFINES_HPP_INCLUDED
  18. #define CARLA_DEFINES_HPP_INCLUDED
  19. // IDE Helper
  20. #ifndef REAL_BUILD
  21. # include "config.h"
  22. #endif
  23. // Check OS
  24. #if defined(WIN64) || defined(_WIN64) || defined(__WIN64__)
  25. # define CARLA_OS_WIN64
  26. #elif defined(WIN32) || defined(_WIN32) || defined(__WIN32__)
  27. # define CARLA_OS_WIN32
  28. #elif defined(__APPLE__)
  29. # define CARLA_OS_MAC
  30. #elif defined(__HAIKU__)
  31. # define CARLA_OS_HAIKU
  32. #elif defined(__linux__) || defined(__linux)
  33. # define CARLA_OS_LINUX
  34. #else
  35. # warning Unsupported platform!
  36. #endif
  37. #if defined(CARLA_OS_WIN32) || defined(CARLA_OS_WIN64)
  38. # define CARLA_OS_WIN
  39. #elif ! defined(CARLA_OS_HAIKU)
  40. # define CARLA_OS_UNIX
  41. #endif
  42. // Check for C++11 support
  43. #if defined(HAVE_CPP11_SUPPORT)
  44. # define CARLA_PROPER_CPP11_SUPPORT
  45. #elif defined(__GNUC__) && (__cplusplus >= 201103L || defined(__GXX_EXPERIMENTAL_CXX0X__))
  46. # if (__GNUC__ * 100 + __GNUC_MINOR__) >= 405
  47. # define CARLA_PROPER_CPP11_SUPPORT
  48. # if (__GNUC__ * 100 + __GNUC_MINOR__) < 407
  49. # define override // gcc4.7+ only
  50. # define final // gcc4.7+ only
  51. # endif
  52. # endif
  53. #endif
  54. #ifndef CARLA_PROPER_CPP11_SUPPORT
  55. # define override
  56. # define final
  57. # define noexcept throw()
  58. # define nullptr (0)
  59. #endif
  60. // Common includes
  61. #ifdef CARLA_OS_WIN
  62. # include <winsock2.h>
  63. # include <windows.h>
  64. #else
  65. # include <unistd.h>
  66. # ifndef __cdecl
  67. # define __cdecl
  68. # endif
  69. #endif
  70. // Define various string format types
  71. #if defined(CARLA_OS_WIN64)
  72. # define P_INT64 "%I64i"
  73. # define P_INTPTR "%I64i"
  74. # define P_UINTPTR "%I64x"
  75. # define P_SIZE "%I64u"
  76. #elif defined(CARLA_OS_WIN32)
  77. # define P_INT64 "%I64i"
  78. # define P_INTPTR "%i"
  79. # define P_UINTPTR "%x"
  80. # define P_SIZE "%u"
  81. #elif __WORDSIZE == 64
  82. # define P_INT64 "%li"
  83. # define P_INTPTR "%li"
  84. # define P_UINTPTR "%lx"
  85. # define P_SIZE "%lu"
  86. #else
  87. # define P_INT64 "%lli"
  88. # define P_INTPTR "%i"
  89. # define P_UINTPTR "%x"
  90. # define P_SIZE "%u"
  91. #endif
  92. // Define BINARY_NATIVE
  93. #if defined(CARLA_OS_HAIKU) || defined(CARLA_OS_UNIX)
  94. # if defined (__LP64__) || defined (_LP64)
  95. # define BINARY_NATIVE BINARY_POSIX64
  96. # else
  97. # define BINARY_NATIVE BINARY_POSIX32
  98. # endif
  99. #elif defined(CARLA_OS_WIN)
  100. # ifdef CARLA_OS_WIN64
  101. # define BINARY_NATIVE BINARY_WIN64
  102. # else
  103. # define BINARY_NATIVE BINARY_WIN32
  104. # endif
  105. #else
  106. # warning Unknown binary native
  107. # define BINARY_NATIVE BINARY_OTHER
  108. #endif
  109. // Define CARLA_ASSERT*
  110. #if defined(CARLA_NO_ASSERTS)
  111. # define CARLA_ASSERT(cond)
  112. # define CARLA_ASSERT_INT(cond, value)
  113. # define CARLA_ASSERT_INT2(cond, v1, v2)
  114. #elif defined(NDEBUG)
  115. # define CARLA_ASSERT CARLA_SAFE_ASSERT
  116. # define CARLA_ASSERT_INT CARLA_SAFE_ASSERT_INT
  117. # define CARLA_ASSERT_INT2 CARLA_SAFE_ASSERT_INT2
  118. #else
  119. # define CARLA_ASSERT(cond) assert(cond)
  120. # define CARLA_ASSERT_INT(cond, value) assert(cond)
  121. # define CARLA_ASSERT_INT2(cond, v1, v2) assert(cond)
  122. #endif
  123. // Define CARLA_SAFE_ASSERT*
  124. #define CARLA_SAFE_ASSERT(cond) if (cond) pass(); else carla_assert (#cond, __FILE__, __LINE__);
  125. #define CARLA_SAFE_ASSERT_INT(cond, value) if (cond) pass(); else carla_assert_int (#cond, __FILE__, __LINE__, value);
  126. #define CARLA_SAFE_ASSERT_INT2(cond, v1, v2) if (cond) pass(); else carla_assert_int2(#cond, __FILE__, __LINE__, v1, v2);
  127. #define CARLA_SAFE_ASSERT_BREAK(cond) if (cond) pass(); else { carla_assert(#cond, __FILE__, __LINE__); break; }
  128. #define CARLA_SAFE_ASSERT_CONTINUE(cond) if (cond) pass(); else { carla_assert(#cond, __FILE__, __LINE__); continue; }
  129. #define CARLA_SAFE_ASSERT_RETURN(cond, ret) if (cond) pass(); else { carla_assert(#cond, __FILE__, __LINE__); return ret; }
  130. // Define CARLA_DECLARE_NON_COPY_CLASS
  131. #ifdef CARLA_PROPER_CPP11_SUPPORT
  132. # define CARLA_DECLARE_NON_COPY_CLASS(ClassName) \
  133. private: \
  134. ClassName(ClassName&) = delete; \
  135. ClassName(const ClassName&) = delete; \
  136. ClassName& operator=(ClassName&) = delete; \
  137. ClassName& operator=(const ClassName&) = delete;
  138. #else
  139. # define CARLA_DECLARE_NON_COPY_CLASS(ClassName) \
  140. private: \
  141. ClassName(ClassName&); \
  142. ClassName(const ClassName&); \
  143. ClassName& operator=(ClassName&); \
  144. ClassName& operator=(const ClassName&);
  145. #endif
  146. // Define CARLA_DECLARE_NON_COPY_STRUCT
  147. #ifdef CARLA_PROPER_CPP11_SUPPORT
  148. # define CARLA_DECLARE_NON_COPY_STRUCT(StructName) \
  149. StructName(StructName&) = delete; \
  150. StructName(const StructName&) = delete; \
  151. StructName& operator=(StructName&) = delete; \
  152. StructName& operator=(const StructName&) = delete;
  153. #else
  154. # define CARLA_DECLARE_NON_COPY_STRUCT(StructName)
  155. #endif
  156. #ifdef CARLA_PROPER_CPP11_SUPPORT
  157. # define CARLA_PREVENT_HEAP_ALLOCATION \
  158. private: \
  159. static void* operator new(size_t) = delete; \
  160. static void operator delete(void*) = delete;
  161. #else
  162. # define CARLA_PREVENT_HEAP_ALLOCATION \
  163. private: \
  164. static void* operator new(size_t); \
  165. static void operator delete(void*);
  166. #endif
  167. // Define CARLA_EXPORT
  168. #ifdef BUILD_BRIDGE
  169. # define CARLA_EXPORT extern "C"
  170. #else
  171. # if defined(CARLA_OS_WIN) && ! defined(__WINE__)
  172. # define CARLA_EXPORT extern "C" __declspec (dllexport)
  173. # else
  174. # define CARLA_EXPORT extern "C" __attribute__ ((visibility("default")))
  175. # endif
  176. #endif
  177. // Define PRE/POST_PACKED_STRUCTURE
  178. #if defined(__GNUC__)
  179. # define PRE_PACKED_STRUCTURE
  180. # define POST_PACKED_STRUCTURE __attribute__((__packed__))
  181. #elif defined(_MSC_VER)
  182. # define PRE_PACKED_STRUCTURE1 __pragma(pack(push,1))
  183. # define PRE_PACKED_STRUCTURE PRE_PACKED_STRUCTURE1
  184. # define POST_PACKED_STRUCTURE ;__pragma(pack(pop))
  185. #else
  186. # define PRE_PACKED_STRUCTURE
  187. # define POST_PACKED_STRUCTURE
  188. #endif
  189. // Define OS_SEP
  190. #ifdef CARLA_OS_WIN
  191. # define OS_SEP '\\'
  192. #else
  193. # define OS_SEP '/'
  194. #endif
  195. #endif // CARLA_DEFINES_HPP_INCLUDED