SDL_platform_defines.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476
  1. /*
  2. Simple DirectMedia Layer
  3. Copyright (C) 1997-2025 Sam Lantinga <slouken@libsdl.org>
  4. This software is provided 'as-is', without any express or implied
  5. warranty. In no event will the authors be held liable for any damages
  6. arising from the use of this software.
  7. Permission is granted to anyone to use this software for any purpose,
  8. including commercial applications, and to alter it and redistribute it
  9. freely, subject to the following restrictions:
  10. 1. The origin of this software must not be misrepresented; you must not
  11. claim that you wrote the original software. If you use this software
  12. in a product, an acknowledgment in the product documentation would be
  13. appreciated but is not required.
  14. 2. Altered source versions must be plainly marked as such, and must not be
  15. misrepresented as being the original software.
  16. 3. This notice may not be removed or altered from any source distribution.
  17. */
  18. /* WIKI CATEGORY: Platform */
  19. /*
  20. * SDL_platform_defines.h tries to get a standard set of platform defines.
  21. */
  22. #ifndef SDL_platform_defines_h_
  23. #define SDL_platform_defines_h_
  24. #ifdef _AIX
  25. /**
  26. * A preprocessor macro that is only defined if compiling for AIX.
  27. *
  28. * \since This macro is available since SDL 3.2.0.
  29. */
  30. #define SDL_PLATFORM_AIX 1
  31. #endif
  32. #ifdef __HAIKU__
  33. /**
  34. * A preprocessor macro that is only defined if compiling for Haiku OS.
  35. *
  36. * \since This macro is available since SDL 3.2.0.
  37. */
  38. #define SDL_PLATFORM_HAIKU 1
  39. #endif
  40. #if defined(bsdi) || defined(__bsdi) || defined(__bsdi__)
  41. /**
  42. * A preprocessor macro that is only defined if compiling for BSDi
  43. *
  44. * \since This macro is available since SDL 3.2.0.
  45. */
  46. #define SDL_PLATFORM_BSDI 1
  47. #endif
  48. #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__)
  49. /**
  50. * A preprocessor macro that is only defined if compiling for FreeBSD.
  51. *
  52. * \since This macro is available since SDL 3.2.0.
  53. */
  54. #define SDL_PLATFORM_FREEBSD 1
  55. #endif
  56. #if defined(hpux) || defined(__hpux) || defined(__hpux__)
  57. /**
  58. * A preprocessor macro that is only defined if compiling for HP-UX.
  59. *
  60. * \since This macro is available since SDL 3.2.0.
  61. */
  62. #define SDL_PLATFORM_HPUX 1
  63. #endif
  64. #if defined(sgi) || defined(__sgi) || defined(__sgi__) || defined(_SGI_SOURCE)
  65. /**
  66. * A preprocessor macro that is only defined if compiling for IRIX.
  67. *
  68. * \since This macro is available since SDL 3.2.0.
  69. */
  70. #define SDL_PLATFORM_IRIX 1
  71. #endif
  72. #if (defined(linux) || defined(__linux) || defined(__linux__))
  73. /**
  74. * A preprocessor macro that is only defined if compiling for Linux.
  75. *
  76. * Note that Android, although ostensibly a Linux-based system, will not
  77. * define this. It defines SDL_PLATFORM_ANDROID instead.
  78. *
  79. * \since This macro is available since SDL 3.2.0.
  80. */
  81. #define SDL_PLATFORM_LINUX 1
  82. #endif
  83. #if defined(ANDROID) || defined(__ANDROID__)
  84. /**
  85. * A preprocessor macro that is only defined if compiling for Android.
  86. *
  87. * \since This macro is available since SDL 3.2.0.
  88. */
  89. #define SDL_PLATFORM_ANDROID 1
  90. #undef SDL_PLATFORM_LINUX
  91. #endif
  92. #if defined(__unix__) || defined(__unix) || defined(unix)
  93. /**
  94. * A preprocessor macro that is only defined if compiling for a Unix-like
  95. * system.
  96. *
  97. * Other platforms, like Linux, might define this in addition to their primary
  98. * define.
  99. *
  100. * \since This macro is available since SDL 3.2.0.
  101. */
  102. #define SDL_PLATFORM_UNIX 1
  103. #endif
  104. #ifdef __APPLE__
  105. /**
  106. * A preprocessor macro that is only defined if compiling for Apple platforms.
  107. *
  108. * iOS, macOS, etc will additionally define a more specific platform macro.
  109. *
  110. * \since This macro is available since SDL 3.2.0.
  111. *
  112. * \sa SDL_PLATFORM_MACOS
  113. * \sa SDL_PLATFORM_IOS
  114. * \sa SDL_PLATFORM_TVOS
  115. * \sa SDL_PLATFORM_VISIONOS
  116. */
  117. #define SDL_PLATFORM_APPLE 1
  118. /* lets us know what version of macOS we're compiling on */
  119. #include <AvailabilityMacros.h>
  120. #ifndef __has_extension /* Older compilers don't support this */
  121. #define __has_extension(x) 0
  122. #include <TargetConditionals.h>
  123. #undef __has_extension
  124. #else
  125. #include <TargetConditionals.h>
  126. #endif
  127. /* Fix building with older SDKs that don't define these
  128. See this for more information:
  129. https://stackoverflow.com/questions/12132933/preprocessor-macro-for-os-x-targets
  130. */
  131. #ifndef TARGET_OS_MACCATALYST
  132. #define TARGET_OS_MACCATALYST 0
  133. #endif
  134. #ifndef TARGET_OS_IOS
  135. #define TARGET_OS_IOS 0
  136. #endif
  137. #ifndef TARGET_OS_IPHONE
  138. #define TARGET_OS_IPHONE 0
  139. #endif
  140. #ifndef TARGET_OS_TV
  141. #define TARGET_OS_TV 0
  142. #endif
  143. #ifndef TARGET_OS_SIMULATOR
  144. #define TARGET_OS_SIMULATOR 0
  145. #endif
  146. #ifndef TARGET_OS_VISION
  147. #define TARGET_OS_VISION 0
  148. #endif
  149. #if TARGET_OS_TV
  150. /**
  151. * A preprocessor macro that is only defined if compiling for tvOS.
  152. *
  153. * \since This macro is available since SDL 3.2.0.
  154. *
  155. * \sa SDL_PLATFORM_APPLE
  156. */
  157. #define SDL_PLATFORM_TVOS 1
  158. #endif
  159. #if TARGET_OS_VISION
  160. /**
  161. * A preprocessor macro that is only defined if compiling for VisionOS.
  162. *
  163. * \since This macro is available since SDL 3.2.0.
  164. *
  165. * \sa SDL_PLATFORM_APPLE
  166. */
  167. #define SDL_PLATFORM_VISIONOS 1
  168. #endif
  169. #if TARGET_OS_IPHONE
  170. /**
  171. * A preprocessor macro that is only defined if compiling for iOS.
  172. *
  173. * \since This macro is available since SDL 3.2.0.
  174. *
  175. * \sa SDL_PLATFORM_APPLE
  176. */
  177. #define SDL_PLATFORM_IOS 1
  178. #else
  179. /**
  180. * A preprocessor macro that is only defined if compiling for macOS.
  181. *
  182. * \since This macro is available since SDL 3.2.0.
  183. *
  184. * \sa SDL_PLATFORM_APPLE
  185. */
  186. #define SDL_PLATFORM_MACOS 1
  187. #if MAC_OS_X_VERSION_MIN_REQUIRED < 1070
  188. #error SDL for macOS only supports deploying on 10.7 and above.
  189. #endif /* MAC_OS_X_VERSION_MIN_REQUIRED < 1070 */
  190. #endif /* TARGET_OS_IPHONE */
  191. #endif /* defined(__APPLE__) */
  192. #ifdef __EMSCRIPTEN__
  193. /**
  194. * A preprocessor macro that is only defined if compiling for Emscripten.
  195. *
  196. * \since This macro is available since SDL 3.2.0.
  197. */
  198. #define SDL_PLATFORM_EMSCRIPTEN 1
  199. #endif
  200. #ifdef __NetBSD__
  201. /**
  202. * A preprocessor macro that is only defined if compiling for NetBSD.
  203. *
  204. * \since This macro is available since SDL 3.2.0.
  205. */
  206. #define SDL_PLATFORM_NETBSD 1
  207. #endif
  208. #ifdef __OpenBSD__
  209. /**
  210. * A preprocessor macro that is only defined if compiling for OpenBSD.
  211. *
  212. * \since This macro is available since SDL 3.2.0.
  213. */
  214. #define SDL_PLATFORM_OPENBSD 1
  215. #endif
  216. #if defined(__OS2__) || defined(__EMX__)
  217. /**
  218. * A preprocessor macro that is only defined if compiling for OS/2.
  219. *
  220. * \since This macro is available since SDL 3.2.0.
  221. */
  222. #define SDL_PLATFORM_OS2 1
  223. #endif
  224. #if defined(osf) || defined(__osf) || defined(__osf__) || defined(_OSF_SOURCE)
  225. /**
  226. * A preprocessor macro that is only defined if compiling for Tru64 (OSF/1).
  227. *
  228. * \since This macro is available since SDL 3.2.0.
  229. */
  230. #define SDL_PLATFORM_OSF 1
  231. #endif
  232. #ifdef __QNXNTO__
  233. /**
  234. * A preprocessor macro that is only defined if compiling for QNX Neutrino.
  235. *
  236. * \since This macro is available since SDL 3.2.0.
  237. */
  238. #define SDL_PLATFORM_QNXNTO 1
  239. #endif
  240. #if defined(riscos) || defined(__riscos) || defined(__riscos__)
  241. /**
  242. * A preprocessor macro that is only defined if compiling for RISC OS.
  243. *
  244. * \since This macro is available since SDL 3.2.0.
  245. */
  246. #define SDL_PLATFORM_RISCOS 1
  247. #endif
  248. #if defined(__sun) && defined(__SVR4)
  249. /**
  250. * A preprocessor macro that is only defined if compiling for SunOS/Solaris.
  251. *
  252. * \since This macro is available since SDL 3.2.0.
  253. */
  254. #define SDL_PLATFORM_SOLARIS 1
  255. #endif
  256. #if defined(__CYGWIN__)
  257. /**
  258. * A preprocessor macro that is only defined if compiling for Cygwin.
  259. *
  260. * \since This macro is available since SDL 3.2.0.
  261. */
  262. #define SDL_PLATFORM_CYGWIN 1
  263. #endif
  264. #if defined(_WIN32) || defined(SDL_PLATFORM_CYGWIN)
  265. /**
  266. * A preprocessor macro that is only defined if compiling for Windows.
  267. *
  268. * This also covers several other platforms, like Microsoft GDK, Xbox, WinRT,
  269. * etc. Each will have their own more-specific platform macros, too.
  270. *
  271. * \since This macro is available since SDL 3.2.0.
  272. *
  273. * \sa SDL_PLATFORM_WIN32
  274. * \sa SDL_PLATFORM_XBOXONE
  275. * \sa SDL_PLATFORM_XBOXSERIES
  276. * \sa SDL_PLATFORM_WINGDK
  277. * \sa SDL_PLATFORM_GDK
  278. */
  279. #define SDL_PLATFORM_WINDOWS 1
  280. /* Try to find out if we're compiling for WinRT, GDK or non-WinRT/GDK */
  281. #if defined(_MSC_VER) && defined(__has_include)
  282. #if __has_include(<winapifamily.h>)
  283. #define HAVE_WINAPIFAMILY_H 1
  284. #else
  285. #define HAVE_WINAPIFAMILY_H 0
  286. #endif
  287. /* If _USING_V110_SDK71_ is defined it means we are using the Windows XP toolset. */
  288. #elif defined(_MSC_VER) && (_MSC_VER >= 1700 && !_USING_V110_SDK71_) /* _MSC_VER == 1700 for Visual Studio 2012 */
  289. #define HAVE_WINAPIFAMILY_H 1
  290. #else
  291. #define HAVE_WINAPIFAMILY_H 0
  292. #endif
  293. #if HAVE_WINAPIFAMILY_H
  294. #include <winapifamily.h>
  295. #define WINAPI_FAMILY_WINRT (!WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) && WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_APP))
  296. #else
  297. #define WINAPI_FAMILY_WINRT 0
  298. #endif /* HAVE_WINAPIFAMILY_H */
  299. #ifdef SDL_WIKI_DOCUMENTATION_SECTION
  300. /**
  301. * A preprocessor macro that defined to 1 if compiling for Windows Phone.
  302. *
  303. * \since This macro is available since SDL 3.2.0.
  304. */
  305. #define SDL_WINAPI_FAMILY_PHONE (WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP)
  306. #elif defined(HAVE_WINAPIFAMILY_H) && HAVE_WINAPIFAMILY_H
  307. #define SDL_WINAPI_FAMILY_PHONE (WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP)
  308. #else
  309. #define SDL_WINAPI_FAMILY_PHONE 0
  310. #endif
  311. #if WINAPI_FAMILY_WINRT
  312. #error Windows RT/UWP is no longer supported in SDL
  313. #elif defined(_GAMING_DESKTOP) /* GDK project configuration always defines _GAMING_XXX */
  314. /**
  315. * A preprocessor macro that is only defined if compiling for Microsoft GDK
  316. * for Windows.
  317. *
  318. * \since This macro is available since SDL 3.2.0.
  319. */
  320. #define SDL_PLATFORM_WINGDK 1
  321. #elif defined(_GAMING_XBOX_XBOXONE)
  322. /**
  323. * A preprocessor macro that is only defined if compiling for Xbox One.
  324. *
  325. * \since This macro is available since SDL 3.2.0.
  326. */
  327. #define SDL_PLATFORM_XBOXONE 1
  328. #elif defined(_GAMING_XBOX_SCARLETT)
  329. /**
  330. * A preprocessor macro that is only defined if compiling for Xbox Series.
  331. *
  332. * \since This macro is available since SDL 3.2.0.
  333. */
  334. #define SDL_PLATFORM_XBOXSERIES 1
  335. #else
  336. /**
  337. * A preprocessor macro that is only defined if compiling for desktop Windows.
  338. *
  339. * Despite the "32", this also covers 64-bit Windows; as an informal
  340. * convention, its system layer tends to still be referred to as "the Win32
  341. * API."
  342. *
  343. * \since This macro is available since SDL 3.2.0.
  344. */
  345. #define SDL_PLATFORM_WIN32 1
  346. #endif
  347. #endif /* defined(_WIN32) || defined(SDL_PLATFORM_CYGWIN) */
  348. /* This is to support generic "any GDK" separate from a platform-specific GDK */
  349. #if defined(SDL_PLATFORM_WINGDK) || defined(SDL_PLATFORM_XBOXONE) || defined(SDL_PLATFORM_XBOXSERIES)
  350. /**
  351. * A preprocessor macro that is only defined if compiling for Microsoft GDK on
  352. * any platform.
  353. *
  354. * \since This macro is available since SDL 3.2.0.
  355. */
  356. #define SDL_PLATFORM_GDK 1
  357. #endif
  358. #if defined(__PSP__) || defined(__psp__)
  359. /**
  360. * A preprocessor macro that is only defined if compiling for Sony PSP.
  361. *
  362. * \since This macro is available since SDL 3.2.0.
  363. */
  364. #define SDL_PLATFORM_PSP 1
  365. #endif
  366. #if defined(__PS2__) || defined(PS2)
  367. /**
  368. * A preprocessor macro that is only defined if compiling for Sony PlayStation
  369. * 2.
  370. *
  371. * \since This macro is available since SDL 3.2.0.
  372. */
  373. #define SDL_PLATFORM_PS2 1
  374. #endif
  375. #if defined(__vita__) || defined(__psp2__)
  376. /**
  377. * A preprocessor macro that is only defined if compiling for Sony Vita.
  378. *
  379. * \since This macro is available since SDL 3.2.0.
  380. */
  381. #define SDL_PLATFORM_VITA 1
  382. #endif
  383. #ifdef __3DS__
  384. /**
  385. * A preprocessor macro that is only defined if compiling for Nintendo 3DS.
  386. *
  387. * \since This macro is available since SDL 3.2.0.
  388. */
  389. #define SDL_PLATFORM_3DS 1
  390. #endif
  391. #endif /* SDL_platform_defines_h_ */