-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathWukConfig.hh
executable file
·133 lines (117 loc) · 4.5 KB
/
WukConfig.hh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
#pragma once
#include <cstdlib> // 标准库
#include <cstdarg> // 标准参数库
#include <cstring> // 标准字符串库
#include <cstdint> // 标准数字类型库
#include <cinttypes> // 用于在跨平台打印同样的数据类型
#include <string>
/**
* 在Visual Studio中,C++已经集成了bool类型,不需要使用此头文件了。
* https://learn.microsoft.com/zh-cn/cpp/cpp/bool-cpp?view=msvc-170
*/
#ifndef _MSC_VER
# include <cstdbool> // 标准布尔值库
#endif
// 判断编译时是否使用C++20标准
#if __cplusplus >= 202002
# ifndef WUK_STD_CPP_20
# define WUK_STD_CPP_20
# endif
#endif
/**
* 平台判断,后续可能继续改进。
*
* Microsoft官方只定义了这两个宏用于区分当前是否为Windows平台,不要添加其他宏来判断,因为那是无意义的。
* https://learn.microsoft.com/en-us/cpp/preprocessor/predefined-macros?view=msvc-170
*
* 关于其他平台(信息未证实,请谨慎采信,信息真实度未知)
* https://www.cnblogs.com/foohack/p/5013272.html
*
* 关于Linux平台(主要为GNU环境,可能不包括Clang)
* https://gcc.gnu.org/onlinedocs/cpp/Common-Predefined-Macros.html
*/
#if defined(_WIN32) || defined(_WIN64) // Microsoft Windows
# define WUK_PLATFORM_WINOS
# define WUK_SUPPORT true
#elif defined(__linux) || defined(__gnu_linux__) || defined(__linux__) // Linux
# define WUK_PLATFORM_LINUX
# if defined(__ANDROID__) // Android,此处主要用于支持安卓终端模拟(如Termux)用户。
# define WUK_PLATFORM_ANDROID
# endif
# define WUK_SUPPORT true
#elif defined(macintosh) || defined(Macintosh) || defined(__APPLE__) || \
defined(__MACH__) // Mac OS
# define WUK_PLATFORM_MACOS
# define WUK_SUPPORT false
#endif
/**
* https://blog.kowalczyk.info/article/j/guide-to-predefined-macros-in-c-compilers-gcc-clang-msvc-etc..html
* https://dev.to/tenry/predefined-c-c-macros-43id
* Visual Studio _MSC_VER
* gcc __GNUC__
* clang __clang__
* llvm __llvm__
* MinGW 32 __MINGW32__
* MinGW-w64 32bit __MINGW32__
* MinGW-w64 64bit __MINGW64__
*
* 对于Clang
* https://releases.llvm.org/11.0.0/tools/clang/docs/UsersManual.html
* https://clang.llvm.org/docs/ClangCommandLineReference.html
* https://www.bookstack.cn/read/clang-llvm/get_started.md
*/
#if defined(_MSC_VER) || defined(__MINGW32__) || defined(__MINGW64__)
#elif defined(__GNUC__)
#else
# ifndef WUK_NO_COMPILER_WARNING
# warning "This library is not using this compiler for testing, please be careful."
# endif
#endif
// 检查是否被支持
#if WUK_SUPPORT == false
# warning "This library may not support the computer you are using."
#endif
// 检查是否存在导出宏
#ifndef LIBWUK_API
# ifdef WUK_EXPORTS
# ifdef WUK_PLATFORM_WINOS
# define LIBWUK_API __declspec(dllexport)
# elif defined(__ELF__) || defined(WUK_PLATFORM_LINUX)
# define LIBWUK_API __attribute__((visibility("protected")))
# else
# define LIBWUK_API __attribute__((visibility("default")))
# endif
# else
# ifdef WUK_PLATFORM_WINOS
# define LIBWUK_API __declspec(dllimport)
# else
# define LIBWUK_API __attribute__((visibility("default")))
# endif
# endif
#endif
// WUK库类型定义
#ifndef WUK_TYPE_DEFINED
#define WUK_TYPE_DEFINED
typedef uint8_t wByte, w_byte; // 字节类型
typedef int16_t wS16, w_s16; // 16位带符号整数
typedef int16_t wI16, w_i16; // 16位带符号整数
typedef uint16_t wU16, w_u16; // 16位无符号整数
typedef int32_t wS32, w_s32; // 32位带符号整数
typedef int32_t wI32, w_i32; // 32位带符号整数
typedef uint32_t wU32, w_u32; // 32位无符号整数
typedef int64_t wI64, w_i64; // 64位带符号整数
typedef int64_t wS64, w_s64; // 64位带符号整数
typedef uint64_t wU64, w_u64; // 64位无符号整数
#ifdef _MSC_VER
typedef int64_t ssize_t;
#endif
typedef ssize_t wSSize, w_long, wLong, w_ssize; // 带符号长整数
typedef size_t wSize, w_ulong, wULong, w_size; // 无符号长整数
#endif /* WUK_TYPE_DEFINED */
// 定义宏函数
#ifndef WUK_MACRO_DEFINED
#define WUK_MACRO_DEFINED
#define wuk_toString(x) #x /* 将x转为字符串 */
#define wuk_min(x, y) (((x) < (y)) ? (x) : (y))
#define wuk_max(x, y) (((x) > (y)) ? (x) : (y))
#endif /* WUK_MACRO_DEFINED */