summaryrefslogtreecommitdiff
path: root/docs/handbook/meshmc/platform-support.md
blob: 496fe07e32c48032123e8ccf2c4afe792d8f540d (plain)
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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
# Platform Support

## Overview

MeshMC targets Linux, macOS, and Windows with platform-specific build configurations, packaging, and runtime behavior. The CMake build system uses presets and conditional compilation to handle platform differences.

## Build Presets

| Preset | Platform | Compiler | Generator |
|---|---|---|---|
| `linux` | Linux (x86_64, aarch64) | GCC / Clang | Ninja Multi-Config |
| `macos` | macOS (x86_64, arm64) | AppleClang | Ninja Multi-Config |
| `windows_msvc` | Windows | MSVC | Ninja Multi-Config |
| `windows_mingw` | Windows | MinGW-w64 | Ninja Multi-Config |

Each preset is defined in `CMakePresets.json` and configures:
- Compiler toolchain
- vcpkg integration
- Platform-specific CMake variables
- Build/install directories

## Linux

### Build Requirements

- CMake 3.28+
- GCC 14+ or Clang 18+ (C++23 support)
- Qt6 (Core, Widgets, Concurrent, Network, NetworkAuth, Test, Xml)
- Extra CMake Modules (ECM) from KDE
- libarchive, zlib, cmark, tomlplusplus

### Nix Build

MeshMC provides a `flake.nix` for reproducible builds:

```bash
nix build .#meshmc        # Build release
nix develop .#meshmc      # Enter dev shell with all dependencies
```

### Desktop Integration

CMake installs standard freedesktop files:

```cmake
# Application desktop entry
install(FILES launcher/package/linux/org.projecttick.MeshMC.desktop
    DESTINATION ${KDE_INSTALL_APPDIR})

# AppStream metainfo
install(FILES launcher/package/linux/org.projecttick.MeshMC.metainfo.xml
    DESTINATION ${KDE_INSTALL_METAINFODIR})

# MIME type for .meshmc files
install(FILES launcher/package/linux/org.projecttick.MeshMC.mime.xml
    DESTINATION ${KDE_INSTALL_MIMEDIR})

# Application icons (various sizes)
ecm_install_icons(ICONS
    launcher/package/linux/16-apps-org.projecttick.MeshMC.png
    launcher/package/linux/24-apps-org.projecttick.MeshMC.png
    launcher/package/linux/32-apps-org.projecttick.MeshMC.png
    launcher/package/linux/48-apps-org.projecttick.MeshMC.png
    launcher/package/linux/64-apps-org.projecttick.MeshMC.png
    launcher/package/linux/128-apps-org.projecttick.MeshMC.png
    launcher/package/linux/256-apps-org.projecttick.MeshMC.png
    launcher/package/linux/scalable-apps-org.projecttick.MeshMC.svg
    DESTINATION ${KDE_INSTALL_ICONDIR}
)
```

### Runtime Paths

```cpp
// KDE install directories used via ECM
KDE_INSTALL_BINDIR      → /usr/bin
KDE_INSTALL_DATADIR     → /usr/share
KDE_INSTALL_APPDIR      → /usr/share/applications
KDE_INSTALL_ICONDIR     → /usr/share/icons
KDE_INSTALL_METAINFODIR → /usr/share/metainfo
KDE_INSTALL_MIMEDIR     → /usr/share/mime/packages
```

### RPATH

```cmake
# Set RPATH for installed binary
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
```

Ensures bundled libraries are found at runtime without LD_LIBRARY_PATH.

### Wayland/X11

Qt6 handles Wayland and X11 transparently. MeshMC does not have platform-specific display code.

## macOS

### Build Requirements

- CMake 3.28+
- Xcode / AppleClang (C++23 support)
- Qt6 via Homebrew or vcpkg
- Same library dependencies as Linux

### App Bundle

CMake creates a standard macOS `.app` bundle:

```cmake
set_target_properties(meshmc PROPERTIES
    MACOSX_BUNDLE TRUE
    MACOSX_BUNDLE_INFO_PLIST "${CMAKE_SOURCE_DIR}/launcher/package/macos/Info.plist.in"
    MACOSX_BUNDLE_BUNDLE_NAME "MeshMC"
    MACOSX_BUNDLE_BUNDLE_VERSION "${MeshMC_VERSION_NAME}"
    MACOSX_BUNDLE_GUI_IDENTIFIER "org.projecttick.MeshMC"
    MACOSX_BUNDLE_ICON_FILE "meshmc.icns"
    MACOSX_BUNDLE_SHORT_VERSION_STRING "${MeshMC_VERSION_NAME}"
)
```

### Application Icon

```cmake
# Convert SVG to icns
set(MACOSX_ICON "${CMAKE_SOURCE_DIR}/launcher/package/macos/meshmc.icns")
set_source_files_properties(${MACOSX_ICON} PROPERTIES MACOSX_PACKAGE_LOCATION "Resources")
```

### Sparkle Updates

macOS uses the Sparkle framework for auto-updates:

```cmake
if(APPLE)
    find_library(SPARKLE_FRAMEWORK Sparkle)
    if(SPARKLE_FRAMEWORK)
        target_link_libraries(meshmc PRIVATE ${SPARKLE_FRAMEWORK})
    endif()
endif()
```

Sparkle provides:
- Built-in update notification UI
- Differential (delta) updates
- Code signing verification
- Automatic background checks

### Universal Binary

The build supports creating Universal binaries (x86_64 + arm64):

```cmake
# Set via CMake variable
set(CMAKE_OSX_ARCHITECTURES "x86_64;arm64")
```

### macOS-Specific Code

```cpp
#ifdef Q_OS_MACOS
    // Set application properties for macOS integration
    QApplication::setAttribute(Qt::AA_DontShowIconsInMenus);

    // Handle macOS dock icon click
    // Handle macOS file open events
#endif
```

## Windows

### Build Requirements

#### MSVC
- Visual Studio 2022 17.10+ (MSVC v143, C++23)
- CMake 3.28+
- Qt6 via vcpkg or installer
- vcpkg for other dependencies

#### MinGW
- MinGW-w64 13+ (GCC 14+ for C++23)
- CMake 3.28+
- Qt6 built for MinGW

### Windows Resource File

```cmake
if(WIN32)
    # Application icon and version info
    configure_file(
        "${CMAKE_SOURCE_DIR}/launcher/package/windows/meshmc.rc.in"
        "${CMAKE_BINARY_DIR}/meshmc.rc"
    )
    target_sources(meshmc PRIVATE "${CMAKE_BINARY_DIR}/meshmc.rc")
endif()
```

The `.rc` file provides:
- Application icon (embedded in `.exe`)
- Version information (shown in file properties)
- Product name and company

### Application Manifest

```cmake
if(WIN32)
    target_sources(meshmc PRIVATE
        "${CMAKE_SOURCE_DIR}/launcher/package/windows/meshmc.manifest"
    )
endif()
```

The manifest declares:
- DPI awareness (per-monitor DPI aware)
- Requested execution level (asInvoker)
- Common controls v6 (modern UI)
- UTF-8 code page

### NSIS Installer

For creating Windows installers:

```cmake
if(WIN32)
    # CPack NSIS configuration
    set(CPACK_GENERATOR "NSIS")
    set(CPACK_NSIS_DISPLAY_NAME "MeshMC")
    set(CPACK_NSIS_PACKAGE_NAME "MeshMC")
    set(CPACK_NSIS_MUI_ICON "${CMAKE_SOURCE_DIR}/launcher/package/windows/meshmc.ico")
    set(CPACK_NSIS_INSTALLED_ICON_NAME "meshmc.exe")
    set(CPACK_NSIS_CREATE_ICONS_EXTRA
        "CreateShortCut '$SMPROGRAMS\\\\$STARTMENU_FOLDER\\\\MeshMC.lnk' '$INSTDIR\\\\meshmc.exe'"
    )
endif()
```

### Windows Registry

The installer registers:
- File associations (`.meshmc` import files)
- Start menu shortcuts
- Uninstall information in Add/Remove Programs

### WSL Rejection

MeshMC detects and rejects running under WSL:

```cpp
#ifdef Q_OS_LINUX
    // Check for WSL
    QFile wslInterop("/proc/sys/fs/binfmt_misc/WSLInterop");
    if (wslInterop.exists()) {
        QMessageBox::critical(nullptr, "Unsupported Platform",
            "MeshMC does not support running under WSL. "
            "Please use the native Windows version.");
        return 1;
    }
#endif
```

WSL cannot run Java GUI applications reliably, so MeshMC refuses to start.

## Portable Mode

All platforms support portable mode:

```cpp
// Check for portable marker file
QFileInfo portableMarker(
    QCoreApplication::applicationDirPath() + "/meshmc_portable.txt"
);

if (portableMarker.exists()) {
    // Use application directory for all data
    m_dataPath = QCoreApplication::applicationDirPath();
} else {
    // Use standard platform data directory
    m_dataPath = QStandardPaths::writableLocation(
        QStandardPaths::GenericDataLocation
    ) + "/MeshMC";
}
```

Create `meshmc_portable.txt` next to the binary to enable portable mode. All data (instances, settings, cache) will be stored alongside the executable.

## OpSys Class

Platform detection utility:

```cpp
class OpSys
{
public:
    enum OS {
        Os_Windows,
        Os_Linux,
        Os_OSX,
        Os_Other
    };

    static OS currentSystem();
    static QString currentSystemString();
    static bool isLinux();
    static bool isMacOS();
    static bool isWindows();
};
```

Used throughout the codebase for platform-conditional logic:
- Library path resolution
- Native path separators
- Platform-specific launch arguments
- Natives extraction (LWJGL)

## Platform-Specific Native Libraries

Minecraft requires platform-specific native libraries (LWJGL, OpenAL, etc.):

```cpp
// From Library class
bool Library::isApplicable() const
{
    // Check OS rules
    for (auto& rule : m_rules) {
        if (rule.os.name == "linux" && OpSys::isLinux()) return rule.action == "allow";
        if (rule.os.name == "osx" && OpSys::isMacOS()) return rule.action == "allow";
        if (rule.os.name == "windows" && OpSys::isWindows()) return rule.action == "allow";
    }
    return true;  // No rules = always applicable
}
```

### Natives Classifiers

```json
{
    "name": "org.lwjgl:lwjgl:3.3.3",
    "natives": {
        "linux": "natives-linux",
        "osx": "natives-macos",
        "windows": "natives-windows"
    }
}
```

## Data Directory Locations

| Platform | Default Data Directory |
|---|---|
| Linux | `~/.local/share/MeshMC` |
| macOS | `~/Library/Application Support/MeshMC` |
| Windows | `%APPDATA%/MeshMC` |
| Portable | `<binary_dir>/` |