Stroika Library 3.0d16
 
Loading...
Searching...
No Matches
Foundation/Common/Platform/Common.h
1/*
2 * Copyright(c) Sophist Solutions, Inc. 1990-2025. All rights reserved
3 */
4#ifndef _Stroika_Foundation_Common_Platform_Common_h_
5#define _Stroika_Foundation_Common_Platform_Common_h_ 1
6
7/**
8 * Platforms (not always mutually exclusive)
9 * o qStroika_Foundation_Common_Platform_Windows
10 * o qStroika_Foundation_Common_Platform_Win32 (implies qStroika_Foundation_Common_Platform_Windows)
11 * o qStroika_Foundation_Common_Platform_Win64 (implies qStroika_Foundation_Common_Platform_Windows)
12 * o qStroika_Foundation_Common_Platform_POSIX
13 * o qStroika_Foundation_Common_Platform_Linux (implies qStroika_Foundation_Common_Platform_POSIX)
14 * o qStroika_Foundation_Common_Platform_MacOS (implies qStroika_Foundation_Common_Platform_POSIX)
15 */
16
17/**
18 * \brief qStroika_Foundation_Common_Platform_Windows true iff compiling targeting the Windows platform (Win32 or Win64)
19 */
20#ifndef qStroika_Foundation_Common_Platform_Windows
21#if defined(_WINDOWS) || defined(_WIN64) || defined(_WIN32)
22#define qStroika_Foundation_Common_Platform_Windows 1
23#else
24#define qStroika_Foundation_Common_Platform_Windows 0
25#endif
26#endif
27
28/**
29 * \brief qStroika_Foundation_Common_Platform_Win32
30 */
31#if defined(_WIN32) && !defined(_WIN64)
32#define qStroika_Foundation_Common_Platform_Win32 1
33#else
34#define qStroika_Foundation_Common_Platform_Win32 0
35#endif
36
37/**
38 * \brief qStroika_Foundation_Common_Platform_Win64
39 */
40#if defined(_WIN64)
41#define qStroika_Foundation_Common_Platform_Win64 1
42#else
43#define qStroika_Foundation_Common_Platform_Win64 0
44#endif
45
46/**
47 * \brief qStroika_Foundation_Common_Platform_POSIX
48 */
49#ifndef qStroika_Foundation_Common_Platform_POSIX
50// Not really sure which defines to look for --LGP 2011-09-13
51#if defined(_POSIX_SOURCE) || defined(__unix__) || (defined(__APPLE__) && defined(__MACH__)) || defined(__linux)
52#define qStroika_Foundation_Common_Platform_POSIX 1
53#else
54#define qStroika_Foundation_Common_Platform_POSIX 0
55#endif
56#endif
57
58/**
59 * \brief qStroika_Foundation_Common_Platform_Linux
60 */
61#ifndef qStroika_Foundation_Common_Platform_Linux
62#if defined(__linux)
63#define qStroika_Foundation_Common_Platform_Linux 1
64#else
65#define qStroika_Foundation_Common_Platform_Linux 0
66#endif
67#endif
68
69/**
70 * \brief qStroika_Foundation_Common_Platform_MacOS - MacOS X
71 */ \
72#ifndef qStroika_Foundation_Common_Platform_MacOS
73#if defined(__APPLE__) && defined(__MACH__)
74#define qStroika_Foundation_Common_Platform_MacOS 1
75#else
76#define qStroika_Foundation_Common_Platform_MacOS 0
77#endif
78#endif
79
80/*
81 * Sanity/consistency check for platform defines
82 */
83#ifndef RC_INVOKED
84#if qStroika_Foundation_Common_Platform_Windows != (qStroika_Foundation_Common_Platform_Win32 || qStroika_Foundation_Common_Platform_Win64)
85#warning "INCONSISTENT DEFINES"
86#endif
87#if qStroika_Foundation_Common_Platform_Windows && qStroika_Foundation_Common_Platform_POSIX
88#warning "Shouldn't have both Windows and POSIX platform flags set"
89#endif
90#if qStroika_Foundation_Common_Platform_Windows && qStroika_Foundation_Common_Platform_MacOS
91#warning "Shouldn't have both Windows and MacOS platform flags set"
92#endif
93#endif
94
95/*
96 * Defines to tune other #includes - based on platform
97 */
98#ifndef RC_INVOKED
99#if qStroika_Foundation_Common_Platform_Windows
100
101// not important, but a good default
102#if !defined(STRICT)
103#define STRICT
104#endif
105
106// Avoid MSFT Win32 macro which interferes with several 'standard c++' things - not just the min/max templates, but
107// the numeric_limits<>::max() stuff as well!
108#define NOMINMAX
109
110// Too many different components have quirky dependencies about what to include in what order.
111// This define helps mitigate that problem.
112// (especially see MFC vs winsock, and Stroika's use of winsock2, windows.h including winsock.h etc)
113#define WIN32_LEAN_AND_MEAN 1
114
115#endif
116#endif
117
118//? DERIVITIVE DEFINES
119// @todo reconsider this define
120#ifndef qHas_pid_t
121#define qHas_pid_t Stroika_Foundation_Common_Platform_POSIX
122#endif
123#ifndef qSupport_Proc_Filesystem
124#if defined(__linux__)
125#define qSupport_Proc_Filesystem 1
126#else
127#define qSupport_Proc_Filesystem 0
128#endif
129#endif
130
131// #DEPRECATED DEFINES - DEPRECATED since 3.0d11
132#ifndef RC_INVOKED
133#define qPlatform_Windows qStroika_Foundation_Common_Platform_Windows
134#define qPlatform_Win32 qStroika_Foundation_Common_Platform_Win32
135#define qPlatform_Win64 qStroika_Foundation_Common_Platform_Win64
136#define qPlatform_POSIX qStroika_Foundation_Common_Platform_POSIX
137#define qPlatform_Linux qStroika_Foundation_Common_Platform_Linux
138#define qPlatform_MacOS qStroika_Foundation_Common_Platform_MacOS
139#endif
140
141// FOR RC_INVOKED, but defined always so can be used in mixed use code as well
142#if defined(_WINDOWS) || defined(_WIN64) || defined(_WIN32)
143#define qRCBWA_Platform_Windows 1
144#else
145#define qRCBWA_Platform_Windows 0
146#endif
147
148#endif /*_Stroika_Foundation_Common_Platform_Common_h_*/