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