FifeGUI 0.3.0
A C++ GUI library designed for games.
platform.hpp
1// SPDX-License-Identifier: LGPL-2.1-or-later OR BSD-3-Clause
2// SPDX-FileCopyrightText: 2004 - 2008 Olof Naessén and Per Larsson
3// SPDX-FileCopyrightText: 2013 - 2026 Fifengine contributors
4
5#ifndef INCLUDE_FIFECHAN_PLATFORM_HPP_
6#define INCLUDE_FIFECHAN_PLATFORM_HPP_
7
8// NOLINTBEGIN(cppcoreguidelines-macro-usage)
9// The warning suggests to use constexpr instead of macros.
10// This is not always possible, e.g. for platform detection macros.
11
12// clang-format off
13
14// Check and defines for the operating system
15#if !defined(FIFEGUI_OS_WINDOWS) && (defined(_WIN32) || defined(_WIN64))
16 #define FIFEGUI_OS_WINDOWS 1
17#endif
18#if !defined(FIFEGUI_OS_LINUX) && defined(__linux__)
19 #define FIFEGUI_OS_LINUX 1
20#endif
21#if !defined(FIFEGUI_OS_MACOS) && defined(__APPLE__)
22 #define FIFEGUI_OS_MACOS 1
23#endif
24
25// Check and defines for the compiler
26#if !defined(FIFEGUI_COMPILER_MSVC) && defined(_MSC_VER)
27 #define FIFEGUI_COMPILER_MSVC 1
28#endif
29#if !defined(FIFEGUI_COMPILER_GNU) && defined(__GNUC__)
30 #define FIFEGUI_COMPILER_GNU 1
31#endif
32#if !defined(FIFEGUI_COMPILER_CLANG) && defined(__clang__)
33 #define FIFEGUI_COMPILER_CLANG 1
34#endif
35#if !defined(FIFEGUI_COMPILER_MINGW) && defined(__MINGW32__)
36 #define FIFEGUI_COMPILER_MINGW 1
37#endif
38
39// Static builds do not use import/export decorations on Windows.
40#ifndef FIFECHAN_STATIC
41 #ifdef FIFECHAN_STATICLIB
42 #define FIFECHAN_STATIC 1
43 #endif
44#endif
45
77
78// FIFECHAN_BUILD and FIIFECHAN_EXTENSION_BUILD are defined in CMakeLists.txt.
79// FIFECHAN_BUILD is our manual definition for building the core library.
80// FIFECHAN_EXTENSION_BUILD is our manual definition for building an extension to the core library.
81// Additionally CMake automatically defines target_EXPORTS when building a shared library, e.g
82// fifechan_EXPORTS when building the library.
83
84#ifdef FIFEGUI_OS_LINUX
85 // For Linux, we only need to use __attribute__ for visibility.
86 #if defined(FIFECHAN_BUILD) || defined(fifechan_EXPORTS)
87 // Building the library
88 #define FIFEGUI_API __attribute__((visibility("default")))
89 #elif defined(FIFECHAN_EXTENSION_BUILD)
90 // Building an extension to the library
91 #define FIFEGUI_API __attribute__((visibility("default")))
92 #define FIFEGUI_EXT_API __attribute__((visibility("default")))
93 #elif defined(FIFECHAN_DLL_IMPORT)
94 // Importing symbols (not typically used on Linux, but included for completeness)
95 #define FIFEGUI_API __attribute__((visibility("default")))
96 #define FIFEGUI_EXT_API __attribute__((visibility("default")))
97 #endif
98#elif defined(FIFEGUI_OS_WINDOWS)
99 #if defined(FIFECHAN_STATIC)
100 #define FIFEGUI_API
101 #define FIFEGUI_EXT_API
102 #elif defined(FIFEGUI_COMPILER_MSVC) || defined(FIFEGUI_COMPILER_MINGW)
103 #if defined(FIFECHAN_EXTENSION_BUILD)
104 // Building an extension to the library
105 //#pragma message(">>> FIFECHAN_EXTENSION_BUILD: Taking extension branch")
106 #define FIFEGUI_API __declspec(dllimport)
107 #define FIFEGUI_EXT_API __declspec(dllexport)
108 #elif defined(FIFECHAN_BUILD) || defined(fifechan_EXPORTS)
109 //#pragma message(">>> fifechan_EXPORTS: Taking core library branch")
110 // Building the library
111 #define FIFEGUI_API __declspec(dllexport)
112 // Not building extensions
113 #define FIFEGUI_EXT_API
114 #else
115 #pragma message(">>> Default: Taking client application branch")
116 // Using the library
117 #define FIFEGUI_API __declspec(dllimport)
118 #define FIFEGUI_EXT_API __declspec(dllimport)
119 #endif
120 #elif defined(FIFEGUI_COMPILER_CLANG)
121 #if defined(FIFECHAN_BUILD) || defined(fifechan_EXPORTS)
122 // Building the library
123 #define FIFEGUI_API __declspec(dllexport) __attribute__ ((visibility("default")))
124 #define FIFEGUI_EXT_API __declspec(dllexport) __attribute__ ((visibility("default")))
125 #elif defined(FIFECHAN_EXTENSION_BUILD)
126 // Building an extension to the library
127 #define FIFEGUI_API __declspec(dllimport) __attribute__ ((visibility("default")))
128 #define FIFEGUI_EXT_API __declspec(dllexport) __attribute__ ((visibility("default")))
129 #else
130 // Using the library
131 #define FIFEGUI_API __declspec(dllimport) __attribute__ ((visibility("default")))
132 #define FIFEGUI_EXT_API __declspec(dllimport) __attribute__ ((visibility("default")))
133 #endif
134 #endif
135#else
136 // whatever
137#endif
138
139// For other compilers/platforms, default visibility is assumed.
140#ifndef FIFEGUI_API
141#define FIFEGUI_API __attribute__ ((visibility("default")))
142#endif
143
144#ifndef FIFEGUI_EXT_API
145#define FIFEGUI_EXT_API __attribute__ ((visibility("default")))
146#endif
147
148// clang-format on
149
150// NOLINTEND(cppcoreguidelines-macro-usage)
151
152#endif // INCLUDE_FIFECHAN_PLATFORM_HPP_