SDL 3.0
SDL_platform_defines.h
Go to the documentation of this file.
1/*
2 Simple DirectMedia Layer
3 Copyright (C) 1997-2024 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.1.3.
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.1.3.
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.1.3.
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.1.3.
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.1.3.
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.1.3.
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.1.3.
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.1.3.
110 */
111#define SDL_PLATFORM_ANDROID 1
112#undef SDL_PLATFORM_LINUX
113#endif
114
115#ifdef __NGAGE__
116
117/**
118 * A preprocessor macro that is only defined if compiling for Nokia N-Gage.
119 *
120 * \since This macro is available since SDL 3.1.3.
121 */
122#define SDL_PLATFORM_NGAGE 1
123#endif
124
125#if defined(__unix__) || defined(__unix) || defined(unix)
126
127/**
128 * A preprocessor macro that is only defined if compiling for a Unix-like
129 * system.
130 *
131 * Other platforms, like Linux, might define this in addition to their primary
132 * define.
133 *
134 * \since This macro is available since SDL 3.1.3.
135 */
136#define SDL_PLATFORM_UNIX 1
137#endif
138
139#ifdef __APPLE__
140
141/**
142 * A preprocessor macro that is only defined if compiling for Apple platforms.
143 *
144 * iOS, macOS, etc will additionally define a more specific platform macro.
145 *
146 * \since This macro is available since SDL 3.1.3.
147 *
148 * \sa SDL_PLATFORM_MACOS
149 * \sa SDL_PLATFORM_IOS
150 * \sa SDL_PLATFORM_TVOS
151 * \sa SDL_PLATFORM_VISIONOS
152 */
153#define SDL_PLATFORM_APPLE 1
154
155/* lets us know what version of macOS we're compiling on */
156#include <AvailabilityMacros.h>
157#ifndef __has_extension /* Older compilers don't support this */
158 #define __has_extension(x) 0
159 #include <TargetConditionals.h>
160 #undef __has_extension
161#else
162 #include <TargetConditionals.h>
163#endif
164
165/* Fix building with older SDKs that don't define these
166 See this for more information:
167 https://stackoverflow.com/questions/12132933/preprocessor-macro-for-os-x-targets
168*/
169#ifndef TARGET_OS_MACCATALYST
170 #define TARGET_OS_MACCATALYST 0
171#endif
172#ifndef TARGET_OS_IOS
173 #define TARGET_OS_IOS 0
174#endif
175#ifndef TARGET_OS_IPHONE
176 #define TARGET_OS_IPHONE 0
177#endif
178#ifndef TARGET_OS_TV
179 #define TARGET_OS_TV 0
180#endif
181#ifndef TARGET_OS_SIMULATOR
182 #define TARGET_OS_SIMULATOR 0
183#endif
184#ifndef TARGET_OS_VISION
185 #define TARGET_OS_VISION 0
186#endif
187
188#if TARGET_OS_TV
189
190/**
191 * A preprocessor macro that is only defined if compiling for tvOS.
192 *
193 * \since This macro is available since SDL 3.1.3.
194 *
195 * \sa SDL_PLATFORM_APPLE
196 */
197#define SDL_PLATFORM_TVOS 1
198#endif
199
200#if TARGET_OS_VISION
201
202/**
203 * A preprocessor macro that is only defined if compiling for VisionOS.
204 *
205 * \since This macro is available since SDL 3.1.3.
206 *
207 * \sa SDL_PLATFORM_APPLE
208 */
209#define SDL_PLATFORM_VISIONOS 1
210#endif
211
212#if TARGET_OS_IPHONE
213
214/**
215 * A preprocessor macro that is only defined if compiling for iOS.
216 *
217 * \since This macro is available since SDL 3.1.3.
218 *
219 * \sa SDL_PLATFORM_APPLE
220 */
221#define SDL_PLATFORM_IOS 1
222
223#else
224
225/**
226 * A preprocessor macro that is only defined if compiling for macOS.
227 *
228 * \since This macro is available since SDL 3.1.3.
229 *
230 * \sa SDL_PLATFORM_APPLE
231 */
232#define SDL_PLATFORM_MACOS 1
233
234#if MAC_OS_X_VERSION_MIN_REQUIRED < 1070
235 #error SDL for macOS only supports deploying on 10.7 and above.
236#endif /* MAC_OS_X_VERSION_MIN_REQUIRED < 1070 */
237#endif /* TARGET_OS_IPHONE */
238#endif /* defined(__APPLE__) */
239
240#ifdef __EMSCRIPTEN__
241
242/**
243 * A preprocessor macro that is only defined if compiling for Emscripten.
244 *
245 * \since This macro is available since SDL 3.1.3.
246 */
247#define SDL_PLATFORM_EMSCRIPTEN 1
248#endif
249
250#ifdef __NetBSD__
251
252/**
253 * A preprocessor macro that is only defined if compiling for NetBSD.
254 *
255 * \since This macro is available since SDL 3.1.3.
256 */
257#define SDL_PLATFORM_NETBSD 1
258#endif
259
260#ifdef __OpenBSD__
261
262/**
263 * A preprocessor macro that is only defined if compiling for OpenBSD.
264 *
265 * \since This macro is available since SDL 3.1.3.
266 */
267#define SDL_PLATFORM_OPENBSD 1
268#endif
269
270#if defined(__OS2__) || defined(__EMX__)
271
272/**
273 * A preprocessor macro that is only defined if compiling for OS/2.
274 *
275 * \since This macro is available since SDL 3.1.3.
276 */
277#define SDL_PLATFORM_OS2 1
278#endif
279
280#if defined(osf) || defined(__osf) || defined(__osf__) || defined(_OSF_SOURCE)
281
282/**
283 * A preprocessor macro that is only defined if compiling for Tru64 (OSF/1).
284 *
285 * \since This macro is available since SDL 3.1.3.
286 */
287#define SDL_PLATFORM_OSF 1
288#endif
289
290#ifdef __QNXNTO__
291
292/**
293 * A preprocessor macro that is only defined if compiling for QNX Neutrino.
294 *
295 * \since This macro is available since SDL 3.1.3.
296 */
297#define SDL_PLATFORM_QNXNTO 1
298#endif
299
300#if defined(riscos) || defined(__riscos) || defined(__riscos__)
301
302/**
303 * A preprocessor macro that is only defined if compiling for RISC OS.
304 *
305 * \since This macro is available since SDL 3.1.3.
306 */
307#define SDL_PLATFORM_RISCOS 1
308#endif
309
310#if defined(__sun) && defined(__SVR4)
311
312/**
313 * A preprocessor macro that is only defined if compiling for SunOS/Solaris.
314 *
315 * \since This macro is available since SDL 3.1.3.
316 */
317#define SDL_PLATFORM_SOLARIS 1
318#endif
319
320#if defined(__CYGWIN__)
321
322/**
323 * A preprocessor macro that is only defined if compiling for Cygwin.
324 *
325 * \since This macro is available since SDL 3.1.3.
326 */
327#define SDL_PLATFORM_CYGWIN 1
328#endif
329
330#if defined(_WIN32) || defined(SDL_PLATFORM_CYGWIN)
331
332/**
333 * A preprocessor macro that is only defined if compiling for Windows.
334 *
335 * This also covers several other platforms, like Microsoft GDK, Xbox, WinRT,
336 * etc. Each will have their own more-specific platform macros, too.
337 *
338 * \since This macro is available since SDL 3.1.3.
339 *
340 * \sa SDL_PLATFORM_WIN32
341 * \sa SDL_PLATFORM_XBOXONE
342 * \sa SDL_PLATFORM_XBOXSERIES
343 * \sa SDL_PLATFORM_WINGDK
344 * \sa SDL_PLATFORM_GDK
345 */
346#define SDL_PLATFORM_WINDOWS 1
347
348/* Try to find out if we're compiling for WinRT, GDK or non-WinRT/GDK */
349#if defined(_MSC_VER) && defined(__has_include)
350 #if __has_include(<winapifamily.h>)
351 #define HAVE_WINAPIFAMILY_H 1
352 #else
353 #define HAVE_WINAPIFAMILY_H 0
354 #endif
355
356 /* If _USING_V110_SDK71_ is defined it means we are using the Windows XP toolset. */
357#elif defined(_MSC_VER) && (_MSC_VER >= 1700 && !_USING_V110_SDK71_) /* _MSC_VER == 1700 for Visual Studio 2012 */
358 #define HAVE_WINAPIFAMILY_H 1
359#else
360 #define HAVE_WINAPIFAMILY_H 0
361#endif
362
363#if HAVE_WINAPIFAMILY_H
364 #include <winapifamily.h>
365 #define WINAPI_FAMILY_WINRT (!WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) && WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_APP))
366#else
367 #define WINAPI_FAMILY_WINRT 0
368#endif /* HAVE_WINAPIFAMILY_H */
369
370#if HAVE_WINAPIFAMILY_H && HAVE_WINAPIFAMILY_H
371 #define SDL_WINAPI_FAMILY_PHONE (WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP)
372#else
373 #define SDL_WINAPI_FAMILY_PHONE 0
374#endif
375
376#if WINAPI_FAMILY_WINRT
377#error Windows RT/UWP is no longer supported in SDL
378
379#elif defined(_GAMING_DESKTOP) /* GDK project configuration always defines _GAMING_XXX */
380
381/**
382 * A preprocessor macro that is only defined if compiling for Microsoft GDK
383 * for Windows.
384 *
385 * \since This macro is available since SDL 3.1.3.
386 */
387#define SDL_PLATFORM_WINGDK 1
388
389#elif defined(_GAMING_XBOX_XBOXONE)
390
391/**
392 * A preprocessor macro that is only defined if compiling for Xbox One.
393 *
394 * \since This macro is available since SDL 3.1.3.
395 */
396#define SDL_PLATFORM_XBOXONE 1
397
398#elif defined(_GAMING_XBOX_SCARLETT)
399
400/**
401 * A preprocessor macro that is only defined if compiling for Xbox Series.
402 *
403 * \since This macro is available since SDL 3.1.3.
404 */
405#define SDL_PLATFORM_XBOXSERIES 1
406
407#else
408
409/**
410 * A preprocessor macro that is only defined if compiling for desktop Windows.
411 *
412 * Despite the "32", this also covers 64-bit Windows; as an informal
413 * convention, its system layer tends to still be referred to as "the Win32
414 * API."
415 *
416 * \since This macro is available since SDL 3.1.3.
417 */
418#define SDL_PLATFORM_WIN32 1
419
420#endif
421#endif /* defined(_WIN32) || defined(SDL_PLATFORM_CYGWIN) */
422
423
424/* This is to support generic "any GDK" separate from a platform-specific GDK */
425#if defined(SDL_PLATFORM_WINGDK) || defined(SDL_PLATFORM_XBOXONE) || defined(SDL_PLATFORM_XBOXSERIES)
426
427/**
428 * A preprocessor macro that is only defined if compiling for Microsoft GDK on
429 * any platform.
430 *
431 * \since This macro is available since SDL 3.1.3.
432 */
433#define SDL_PLATFORM_GDK 1
434#endif
435
436#if defined(__PSP__) || defined(__psp__)
437
438/**
439 * A preprocessor macro that is only defined if compiling for Sony PSP.
440 *
441 * \since This macro is available since SDL 3.1.3.
442 */
443#define SDL_PLATFORM_PSP 1
444#endif
445
446#if defined(__PS2__) || defined(PS2)
447
448/**
449 * A preprocessor macro that is only defined if compiling for Sony PlayStation
450 * 2.
451 *
452 * \since This macro is available since SDL 3.1.3.
453 */
454#define SDL_PLATFORM_PS2 1
455#endif
456
457#if defined(__vita__) || defined(__psp2__)
458
459/**
460 * A preprocessor macro that is only defined if compiling for Sony Vita.
461 *
462 * \since This macro is available since SDL 3.1.3.
463 */
464#define SDL_PLATFORM_VITA 1
465#endif
466
467#ifdef __3DS__
468
469/**
470 * A preprocessor macro that is only defined if compiling for Nintendo 3DS.
471 *
472 * \since This macro is available since SDL 3.1.3.
473 */
474#define SDL_PLATFORM_3DS 1
475
476#undef __3DS__
477#endif
478
479#endif /* SDL_platform_defines_h_ */