| 1 | #ifndef CPP_UTILITIES_APPLICATION_UTILITIES_GLOBAL_H |
| 2 | #define CPP_UTILITIES_APPLICATION_UTILITIES_GLOBAL_H |
| 3 | |
| 4 | #if defined(_WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(__NT__) |
| 5 | #ifndef PLATFORM_WINDOWS |
| 6 | /// \brief Defined when compiling for Windows. |
| 7 | #define PLATFORM_WINDOWS |
| 8 | #endif |
| 9 | #endif |
| 10 | #if defined(__CYGWIN__) |
| 11 | #ifndef PLATFORM_CYGWIN |
| 12 | /// \brief Defined when compiling for Cygwin. |
| 13 | #define PLATFORM_CYGWIN |
| 14 | #endif |
| 15 | #endif |
| 16 | #if defined(__MINGW32__) || defined(__MINGW64__) |
| 17 | #ifndef PLATFORM_MINGW |
| 18 | /// \brief Defined when compiling with mingw(-w64). |
| 19 | #define PLATFORM_MINGW |
| 20 | #endif |
| 21 | #endif |
| 22 | #if defined(__linux__) || defined(__linux) || defined(__gnu_linux__) |
| 23 | #ifndef PLATFORM_LINUX |
| 24 | /// \brief Defined when compiling for Linux. |
| 25 | #define PLATFORM_LINUX |
| 26 | #endif |
| 27 | #if defined(__ANDROID__) || defined(ANDROID) |
| 28 | #ifndef PLATFORM_ANDROID |
| 29 | /// \brief Defined when compiling for Android. |
| 30 | #define PLATFORM_ANDROID |
| 31 | #endif |
| 32 | #endif |
| 33 | #endif |
| 34 | #if defined(__APPLE__) |
| 35 | #include <TargetConditionals.h> |
| 36 | #if defined(TARGET_OS_MAC) && TARGET_OS_MAC |
| 37 | #ifndef PLATFORM_MAC |
| 38 | /// \brief Defined when compiling for Mac/Darwin. |
| 39 | #define PLATFORM_MAC |
| 40 | #endif |
| 41 | #ifndef PLATFORM_BSD4 |
| 42 | /// \brief Defined when compiling for BSD 4. |
| 43 | #define PLATFORM_BSD4 |
| 44 | #endif |
| 45 | #endif |
| 46 | #endif |
| 47 | #if defined(__FreeBSD__) || defined(__DragonFly__) || defined(__FreeBSD_kernel__) |
| 48 | #ifndef PLATFORM_FREE_BSD |
| 49 | /// \brief Defined when compiling for FreeBSD |
| 50 | #define PLATFORM_FREE_BSD |
| 51 | #endif |
| 52 | #endif |
| 53 | #if defined(__unix__) || defined(PLATFORM_LINUX) || defined(PLATFORM_FREE_BSD) || defined(PLATFORM_MAC) |
| 54 | #ifndef PLATFORM_UNIX |
| 55 | /// \brief Defined when compiling for any UNIX (like) system. |
| 56 | #define PLATFORM_UNIX |
| 57 | #endif |
| 58 | #endif |
| 59 | |
| 60 | /*! |
| 61 | * \def CPP_UTILITIES_GENERIC_LIB_EXPORT |
| 62 | * \brief Marks a symbol for shared library export. |
| 63 | */ |
| 64 | |
| 65 | /*! |
| 66 | * \def CPP_UTILITIES_GENERIC_LIB_IMPORT |
| 67 | * \brief Declares a symbol to be an import from a shared library. |
| 68 | */ |
| 69 | |
| 70 | /*! |
| 71 | * \def CPP_UTILITIES_GENERIC_LIB_HIDDEN |
| 72 | * \brief Hidden visibility indicates that the symbol will not be placed into |
| 73 | * the dynamic symbol table, so no other module (executable or shared library) |
| 74 | * can reference it directly. |
| 75 | */ |
| 76 | |
| 77 | #ifdef PLATFORM_WINDOWS |
| 78 | #define CPP_UTILITIES_GENERIC_LIB_EXPORT __declspec(dllexport) |
| 79 | #define CPP_UTILITIES_GENERIC_LIB_IMPORT __declspec(dllimport) |
| 80 | #define CPP_UTILITIES_GENERIC_LIB_HIDDEN |
| 81 | #else |
| 82 | #define CPP_UTILITIES_GENERIC_LIB_EXPORT __attribute__((visibility("default"))) |
| 83 | #define CPP_UTILITIES_GENERIC_LIB_IMPORT __attribute__((visibility("default"))) |
| 84 | #define CPP_UTILITIES_GENERIC_LIB_HIDDEN __attribute__((visibility("hidden"))) |
| 85 | #endif |
| 86 | |
| 87 | /*! |
| 88 | * \def CPP_UTILITIES_MAIN_EXPORT |
| 89 | * \brief Exports the main() functions on platforms where this is needed. |
| 90 | * \remarks Needed on Android with Qt where applications are shared libraries. |
| 91 | * Otherwise loading the app will fail with the error "dlsym failed: undefined |
| 92 | * symbol: main". |
| 93 | * \sa See qtbase commit 29b17fa335388c9b93f70c29b2398cf2fee65785 (where this is solved |
| 94 | with the sledgehammer method of setting the default visibility). |
| 95 | */ |
| 96 | |
| 97 | #ifdef PLATFORM_ANDROID |
| 98 | #define CPP_UTILITIES_MAIN_EXPORT CPP_UTILITIES_GENERIC_LIB_EXPORT |
| 99 | #else |
| 100 | #define CPP_UTILITIES_MAIN_EXPORT |
| 101 | #endif |
| 102 | |
| 103 | /*! |
| 104 | * \def CPP_UTILITIES_UNUSED |
| 105 | * \brief Prevents warnings about unused variables. |
| 106 | */ |
| 107 | |
| 108 | #define CPP_UTILITIES_UNUSED(x) (void)x; |
| 109 | |
| 110 | /*! |
| 111 | * \def CPP_UTILITIES_IF_DEBUG_BUILD |
| 112 | * \brief Wraps debug-only lines conveniently. |
| 113 | */ |
| 114 | |
| 115 | #ifdef CPP_UTILITIES_DEBUG_BUILD |
| 116 | #define CPP_UTILITIES_IF_DEBUG_BUILD(x) x |
| 117 | #else |
| 118 | #define CPP_UTILITIES_IF_DEBUG_BUILD(x) |
| 119 | #endif |
| 120 | |
| 121 | #endif // CPP_UTILITIES_APPLICATION_UTILITIES_GLOBAL_H |