FifeGUI 0.2.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#if !defined(FIFECHAN_STATIC)
41 #if defined(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#if defined(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_BUILD) || defined(fifechan_EXPORTS)
104 // Building the library
105 #define FIFEGUI_API __declspec(dllexport)
106 #elif defined(FIFECHAN_EXTENSION_BUILD)
107 // Building an extension to the library
108 #define FIFEGUI_API __declspec(dllimport)
109 #define FIFEGUI_EXT_API __declspec(dllexport)
110 #else
111 // Using the library
112 #define FIFEGUI_API __declspec(dllimport)
113 #define FIFEGUI_EXT_API __declspec(dllimport)
114 #endif
115 #elif defined(FIFEGUI_COMPILER_CLANG)
116 #if defined(FIFECHAN_BUILD) || defined(fifechan_EXPORTS)
117 // Building the library
118 #define FIFEGUI_API __declspec(dllexport) __attribute__ ((visibility("default")))
119 #elif defined(FIFECHAN_EXTENSION_BUILD)
120 // Building an extension to the library
121 #define FIFEGUI_API __declspec(dllimport) __attribute__ ((visibility("default")))
122 #define FIFEGUI_EXT_API __declspec(dllexport) __attribute__ ((visibility("default")))
123 #else
124 // Using the library
125 #define FIFEGUI_API __declspec(dllimport) __attribute__ ((visibility("default")))
126 #define FIFEGUI_EXT_API __declspec(dllimport) __attribute__ ((visibility("default")))
127 #endif
128 #endif
129#else
130 // whatever
131#endif
132
133// For other compilers/platforms, default visibility is assumed.
134#ifndef FIFEGUI_API
135#define FIFEGUI_API __attribute__ ((visibility("default")))
136#endif
137
138#ifndef FIFEGUI_EXT_API
139#define FIFEGUI_EXT_API __attribute__ ((visibility("default")))
140#endif
141
142// clang-format on
143
144// NOLINTEND(cppcoreguidelines-macro-usage)
145
146#endif // INCLUDE_FIFECHAN_PLATFORM_HPP_