Stroika Library 3.0d25
 
Loading...
Searching...
No Matches
Foundation/Common/Platform/Common.h
1/*
2 * Copyright(c) Sophist Solutions, Inc. 1990-2026. 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_Platform_Windows
10 * o qStroika_Platform_Win32 (implies qStroika_Platform_Windows)
11 * o qStroika_Platform_Win64 (implies qStroika_Platform_Windows)
12 * o qStroika_Platform_POSIX
13 * o qStroika_Platform_Linux (implies qStroika_Platform_POSIX)
14 * o qStroika_Platform_MacOS (implies qStroika_Platform_POSIX)
15 *
16 * Short on purpose (see Design-Overview.md "Macro names"): they are tested everywhere, and rc.exe - which keeps only 31
17 * characters of an identifier - can test them too.
18 */
19
20/**
21 * \brief qStroika_Platform_Windows true iff compiling targeting the Windows platform (Win32 or Win64)
22 */
23#ifndef qStroika_Platform_Windows
24#if defined(_WINDOWS) || defined(_WIN64) || defined(_WIN32)
25#define qStroika_Platform_Windows 1
26#else
27#define qStroika_Platform_Windows 0
28#endif
29#endif
30
31/**
32 * \brief qStroika_Platform_Win32
33 */
34#if defined(_WIN32) && !defined(_WIN64)
35#define qStroika_Platform_Win32 1
36#else
37#define qStroika_Platform_Win32 0
38#endif
39
40/**
41 * \brief qStroika_Platform_Win64
42 */
43#if defined(_WIN64)
44#define qStroika_Platform_Win64 1
45#else
46#define qStroika_Platform_Win64 0
47#endif
48
49/**
50 * \brief qStroika_Platform_POSIX
51 */
52#ifndef qStroika_Platform_POSIX
53// Not really sure which defines to look for --LGP 2011-09-13
54#if defined(_POSIX_SOURCE) || defined(__unix__) || (defined(__APPLE__) && defined(__MACH__)) || defined(__linux)
55#define qStroika_Platform_POSIX 1
56#else
57#define qStroika_Platform_POSIX 0
58#endif
59#endif
60
61/**
62 * \brief qStroika_Platform_Linux
63 */
64#ifndef qStroika_Platform_Linux
65#if defined(__linux)
66#define qStroika_Platform_Linux 1
67#else
68#define qStroika_Platform_Linux 0
69#endif
70#endif
71
72/**
73 * \brief qStroika_Platform_MacOS - MacOS X
74 */ \
75#ifndef qStroika_Platform_MacOS
76#if defined(__APPLE__) && defined(__MACH__)
77#define qStroika_Platform_MacOS 1
78#else
79#define qStroika_Platform_MacOS 0
80#endif
81#endif
82
83/*
84 * Sanity/consistency check for platform defines
85 */
86#ifndef RC_INVOKED
87#if qStroika_Platform_Windows != (qStroika_Platform_Win32 || qStroika_Platform_Win64)
88#warning "INCONSISTENT DEFINES"
89#endif
90#if qStroika_Platform_Windows && qStroika_Platform_POSIX
91#warning "Shouldn't have both Windows and POSIX platform flags set"
92#endif
93#if qStroika_Platform_Windows && qStroika_Platform_MacOS
94#warning "Shouldn't have both Windows and MacOS platform flags set"
95#endif
96#endif
97
98/*
99 * Defines to tune other #includes - based on platform
100 */
101#ifndef RC_INVOKED
102#if qStroika_Platform_Windows
103
104// not important, but a good default
105#if !defined(STRICT)
106#define STRICT
107#endif
108
109// Avoid MSFT Win32 macro which interferes with several 'standard c++' things - not just the min/max templates, but
110// the numeric_limits<>::max() stuff as well!
111#define NOMINMAX
112
113// Too many different components have quirky dependencies about what to include in what order.
114// This define helps mitigate that problem.
115// (especially see MFC vs winsock, and Stroika's use of winsock2, windows.h including winsock.h etc)
116#define WIN32_LEAN_AND_MEAN 1
117
118#endif
119#endif
120
121/**
122 * \brief qStroika_FeatureSupported_ProcFilesystem - the platform has a /proc filesystem (as Linux does)
123 */
124#ifndef qStroika_FeatureSupported_ProcFilesystem
125#if defined(qSupport_Proc_Filesystem)
126#define qStroika_FeatureSupported_ProcFilesystem qSupport_Proc_Filesystem
127#elif defined(__linux__)
128#define qStroika_FeatureSupported_ProcFilesystem 1
129#else
130#define qStroika_FeatureSupported_ProcFilesystem 0
131#endif
132#endif
133
134// DEPRECATED NAMES - since 3.0d25 (to be removed in v3.0a1). Not for rc.exe, which truncates identifiers to 31
135// characters - so these long names would all become one macro there
136#ifndef RC_INVOKED
137#define qStroika_Foundation_Common_Platform_Windows qStroika_Platform_Windows
138#define qStroika_Foundation_Common_Platform_Win32 qStroika_Platform_Win32
139#define qStroika_Foundation_Common_Platform_Win64 qStroika_Platform_Win64
140#define qStroika_Foundation_Common_Platform_POSIX qStroika_Platform_POSIX
141#define qStroika_Foundation_Common_Platform_Linux qStroika_Platform_Linux
142#define qStroika_Foundation_Common_Platform_MacOS qStroika_Platform_MacOS
143#endif
144#ifndef qSupport_Proc_Filesystem
145#define qSupport_Proc_Filesystem qStroika_FeatureSupported_ProcFilesystem
146#endif
147#ifndef qHas_pid_t
148#define qHas_pid_t qStroika_Platform_POSIX // (until 3.0d25 it was always 0: it named a macro that did not exist)
149#endif
150#define qRCBWA_Platform_Windows qStroika_Platform_Windows
151
152// DEPRECATED NAMES - since 3.0d11
153#ifndef RC_INVOKED
154#define qPlatform_Windows qStroika_Platform_Windows
155#define qPlatform_Win32 qStroika_Platform_Win32
156#define qPlatform_Win64 qStroika_Platform_Win64
157#define qPlatform_POSIX qStroika_Platform_POSIX
158#define qPlatform_Linux qStroika_Platform_Linux
159#define qPlatform_MacOS qStroika_Platform_MacOS
160#endif
161
162#endif /*_Stroika_Foundation_Common_Platform_Common_h_*/