-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathcommon.cppm
More file actions
96 lines (80 loc) · 3.29 KB
/
common.cppm
File metadata and controls
96 lines (80 loc) · 3.29 KB
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
// mcpp.platform.common — centralized platform-specific constants.
//
// Consumers import this module (via mcpp.platform) instead of scattering
// #if/_WIN32 / __APPLE__ blocks throughout the codebase. All compile-time
// branching for platform constants lives here.
module;
export module mcpp.platform.common;
import std;
export namespace mcpp::platform {
// ── Binary / library name conventions ─────────────────────────────────────
#if defined(_WIN32)
constexpr std::string_view exe_suffix = ".exe";
constexpr std::string_view static_lib_ext = ".lib";
constexpr std::string_view shared_lib_ext = ".dll";
constexpr std::string_view lib_prefix = "";
#elif defined(__APPLE__)
constexpr std::string_view exe_suffix = "";
constexpr std::string_view static_lib_ext = ".a";
constexpr std::string_view shared_lib_ext = ".dylib";
constexpr std::string_view lib_prefix = "lib";
#else
// Linux and other POSIX
constexpr std::string_view exe_suffix = "";
constexpr std::string_view static_lib_ext = ".a";
constexpr std::string_view shared_lib_ext = ".so";
constexpr std::string_view lib_prefix = "lib";
#endif
// ── Shell / process helpers ────────────────────────────────────────────────
#if defined(_WIN32)
constexpr std::string_view null_redirect = "2>nul";
#else
constexpr std::string_view null_redirect = "2>/dev/null";
#endif
// ── Platform identification ────────────────────────────────────────────────
#if defined(_WIN32)
constexpr bool is_windows = true;
constexpr bool is_macos = false;
constexpr bool is_linux = false;
#elif defined(__APPLE__)
constexpr bool is_windows = false;
constexpr bool is_macos = true;
constexpr bool is_linux = false;
#elif defined(__linux__)
constexpr bool is_windows = false;
constexpr bool is_macos = false;
constexpr bool is_linux = true;
#else
constexpr bool is_windows = false;
constexpr bool is_macos = false;
constexpr bool is_linux = false;
#endif
// ── Platform name string ───────────────────────────────────────────────────
constexpr std::string_view name =
#if defined(_WIN32)
"windows";
#elif defined(__APPLE__)
"macos";
#elif defined(__linux__)
"linux";
#else
"unknown";
#endif
// xpkg platform key (used by resolver for xpkg.lua lookups).
// Note: macOS uses "macosx" (not "macos") for xpkg compatibility.
constexpr std::string_view xpkg_platform =
#if defined(_WIN32)
"windows";
#elif defined(__APPLE__)
"macosx";
#elif defined(__linux__)
"linux";
#else
"linux";
#endif
// ── Link strategy capabilities ─────────────────────────────────────────
// Used by build/flags.cppm to avoid #ifdef blocks in linker flag logic.
constexpr bool supports_full_static = is_linux; // macOS/Windows cannot
constexpr bool supports_rpath = !is_windows; // ELF + Mach-O only
constexpr bool needs_explicit_libcxx = is_macos; // macOS: -lc++ required
} // namespace mcpp::platform